aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/associations_go_eager_test.rb
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2006-02-10 05:19:41 +0000
committerMichael Koziarski <michael@koziarski.com>2006-02-10 05:19:41 +0000
commit5f4b66201eb9bd01be96a212adfea8fb95334380 (patch)
tree619c8ce24e8f143828d5aca229f151c55f459f99 /activerecord/test/associations_go_eager_test.rb
parent7e6d5b51093c6fae345f6460130bbe2c495b95f4 (diff)
downloadrails-5f4b66201eb9bd01be96a212adfea8fb95334380.tar.gz
rails-5f4b66201eb9bd01be96a212adfea8fb95334380.tar.bz2
rails-5f4b66201eb9bd01be96a212adfea8fb95334380.zip
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
Diffstat (limited to 'activerecord/test/associations_go_eager_test.rb')
-rw-r--r--activerecord/test/associations_go_eager_test.rb13
1 files changed, 12 insertions, 1 deletions
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