From 1a6954af01680d18135ce9a50ff273fd81dc6245 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 18 Apr 2005 05:55:20 +0000 Subject: Changed habtm eager loading to also use joins git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1201 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations_go_eager_test.rb | 15 ++++++++------- activerecord/test/fixtures/posts.yml | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'activerecord/test') diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb index 0bd887478d..8de37f3d92 100644 --- a/activerecord/test/associations_go_eager_test.rb +++ b/activerecord/test/associations_go_eager_test.rb @@ -18,10 +18,10 @@ class EagerAssociationTest < Test::Unit::TestCase end def test_loading_with_multiple_associations - posts = Post.find(:all, :include => [ :comments, :author, :categories ]) + posts = Post.find(:all, :include => [ :comments, :author, :categories ], :order => "posts.id") assert_equal 2, posts.first.comments.size assert_equal 2, posts.first.categories.size - assert_equal @greetings.body, posts.first.comments.first.body + assert posts.first.comments.include?(@greetings) end def test_loading_from_an_association @@ -40,11 +40,12 @@ class EagerAssociationTest < Test::Unit::TestCase end def test_eager_association_loading_with_habtm - posts = Post.find(:all, :include => :categories) - assert_equal 2, posts.first.categories.size - assert_equal 1, posts.last.categories.size - assert_equal @technology.name, posts.first.categories.last.name - assert_equal @general.name, posts.last.categories.first.name + posts = Post.find(:all, :include => :categories, :order => "posts.id") + assert_equal 2, posts[0].categories.size + assert_equal 1, posts[1].categories.size + assert_equal 0, posts[2].categories.size + assert posts[0].categories.include?(@technology) + assert posts[1].categories.include?(@general) end def test_eager_with_inheritance diff --git a/activerecord/test/fixtures/posts.yml b/activerecord/test/fixtures/posts.yml index 037f0a2323..decd14b70e 100644 --- a/activerecord/test/fixtures/posts.yml +++ b/activerecord/test/fixtures/posts.yml @@ -14,6 +14,7 @@ thinking: authorless: id: 3 + author_id: 0 title: I don't have any comments body: I just don't want to type: Post -- cgit v1.2.3