I have a pretty simple model, articles and users.
In my unit tests I want to ensure that the associations work properly.
What’s the best way to do this? The obvious thing to do is a test in
u = users(:first)
before_articles = u.articles.count
u.articles << Article.new(:title => “Title”, :body => “Body”)
assert_equal before_articles + 1, u.articles.count
a = Article.new(:title => “Title”, :body => “Body”, :user =>
assert_equal users(:first), a.user
The thing that bugs me is that in my unit test for article I have to
include the users fixtures. As my domain model gets more complicated,
my tests require more fixtures. It just feels messy to me. This is a
pretty basic question, but it’s something that’s bothered me for a
long time throughout several projects…am I justified in thinking
it’s ugly, or is that the correct approach?