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<https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/active_record/association_matcher.rb>.
 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to