Ruby on Rails
Sunday, April 1, 2012
I'm glad you found my snippet helpful!
Testing associations is trickier, and I must admit that I don't test associations as thoroughly as I probably should. I usually just test that the record responds to the association (e.g.: record.must_respond_to :association).
I took a look at the "shoulda-matchers" gem's source code. Those association matchers test for a whole bunch of stuff (foreign keys, join tables, correct class names, etc.), some of which are probably re-testing ActiveRecord functionality which we should be able to assume works correctly. A good test for associations should fall somewhere in between these two extremes.
I'd love to hear if anyone else has suggestions.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/TjqbTOsfhGkJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment