Created
September 30, 2011 22:31
-
-
Save jrafanie/1255186 to your computer and use it in GitHub Desktop.
When eager loading a HABTM and also including anything beyond it, everything in that result should have been queried for. Add passing tests that previously failed on Rails 2.3.8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 03c1caefa04d9d22da31c02b6a137e76d43caf76 Mon Sep 17 00:00:00 2001 | |
From: Joe Rafaniello <jrafanie@gmail.com> | |
Date: Fri, 30 Sep 2011 18:27:25 -0400 | |
Subject: [PATCH] When eager loading a HABTM and also including anything | |
beyond it, everything in that result should have been | |
queried for. Add passing tests that previously failed on | |
Rails 2.3.8. | |
See https://rails.lighthouseapp.com/projects/8994/tickets/4831 | |
--- | |
activerecord/test/cases/associations/eager_test.rb | 7 +++++++ | |
1 files changed, 7 insertions(+), 0 deletions(-) | |
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb | |
index c6e451f..d8949aa 100644 | |
--- a/activerecord/test/cases/associations/eager_test.rb | |
+++ b/activerecord/test/cases/associations/eager_test.rb | |
@@ -181,6 +181,13 @@ class EagerAssociationTest < ActiveRecord::TestCase | |
assert_equal categories.map { |category| category.posts.first.special_comments.loaded? }, [true, true] | |
end | |
+ def test_deep_including_through_habtm | |
+ posts = Post.find(:all, :include => {:categories => :categorizations}, :order => "posts.id") | |
+ assert_no_queries { assert_equal 2, posts[0].categories[0].categorizations.length } | |
+ assert_no_queries { assert_equal 1, posts[0].categories[1].categorizations.length } | |
+ assert_no_queries { assert_equal 2, posts[1].categories[0].categorizations.length } | |
+ end | |
+ | |
def test_finding_with_includes_on_has_many_association_with_same_include_includes_only_once | |
author_id = authors(:david).id | |
author = assert_queries(3) { Author.find(author_id, :include => {:posts_with_comments => :comments}) } # find the author, then find the posts, then find the comments | |
-- | |
1.7.6.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment