1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
require 'abstract_unit'
require 'fixtures/post'
require 'fixtures/comment'
require 'fixtures/author'
class EagerAssociationTest < Test::Unit::TestCase
fixtures :posts, :comments, :authors
def test_loading_with_one_association
posts = Post.find(:all, :include => :comments)
assert_equal 2, posts.first.comments.size
assert_equal @greetings.body, posts.first.comments.first.body
post = Post.find(:first, :include => :comments, :conditions => "posts.title = 'Welcome to the weblog'")
assert_equal 2, post.comments.size
assert_equal @greetings.body, post.comments.first.body
end
def test_loading_with_multiple_associations
posts = Post.find(:all, :include => [ :comments, :author ])
assert_equal 2, posts.first.comments.size
assert_equal @greetings.body, posts.first.comments.first.body
end
def test_loading_from_an_association
posts = @david.posts.find(:all, :include => :comments)
assert_equal 2, posts.first.comments.size
end
def test_eager_association_loading_with_belongs_to
comments = Comment.find(:all, :include => :post)
assert_equal @welcome.title, comments.first.post.title
assert_equal @thinking.title, comments.last.post.title
end
end
|