Displaying 1 result from an estimated 1 matches for "before_articles".
2006 May 04
2
Testing associations
...class Article
belongs_to :user
end
class User
has_many :articles
end
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
each model.
# user_test.rb
def test_add_post
u = users(:first)
before_articles = u.articles.count
u.articles << Article.new(:title => "Title", :body => "Body")
u.reload
assert_equal before_articles + 1, u.articles.count
end
# article_test.rb
def test_create_with_user
a = Article.new(:title => "Title", :body =&g...