From 5f4b66201eb9bd01be96a212adfea8fb95334380 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Fri, 10 Feb 2006 05:19:41 +0000 Subject: Allow has_many :through to work with :include [Michael Schoen]. Closes #3611 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3566 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations_go_eager_test.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'activerecord/test/associations_go_eager_test.rb') diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb index a03c201d76..1bc9d9f982 100644 --- a/activerecord/test/associations_go_eager_test.rb +++ b/activerecord/test/associations_go_eager_test.rb @@ -4,10 +4,12 @@ require 'fixtures/comment' require 'fixtures/author' require 'fixtures/category' require 'fixtures/company' +require 'fixtures/person' +require 'fixtures/reader' class EagerAssociationTest < Test::Unit::TestCase fixtures :posts, :comments, :authors, :categories, :categories_posts, - :companies, :accounts + :companies, :accounts, :tags, :people, :readers def test_loading_with_one_association posts = Post.find(:all, :include => :comments) @@ -101,6 +103,15 @@ class EagerAssociationTest < Test::Unit::TestCase assert_equal [], posts end + def test_eager_with_has_many_through + posts_with_comments = people(:michael).posts.find(:all, :include => :comments ) + posts_with_author = people(:michael).posts.find(:all, :include => :author ) + posts_with_comments_and_author = people(:michael).posts.find(:all, :include => [ :comments, :author ]) + assert_equal 2, posts_with_comments.inject(0) { |sum, post| sum += post.comments.size } + assert_equal authors(:david), posts_with_author.first.author + assert_equal authors(:david), posts_with_comments_and_author.first.author + end + def test_eager_with_has_many_and_limit posts = Post.find(:all, :order => 'posts.id asc', :include => [ :author, :comments ], :limit => 2) assert_equal 2, posts.size -- cgit v1.2.3