Created
May 14, 2011 02:33
-
-
Save AquaGeek/971708 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #5623
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 a01c41d39efae7806f0ad3718e5d46b0c7605ac6 Mon Sep 17 00:00:00 2001 | |
From: Eric Cohen <eric@rento.gr> | |
Date: Mon, 13 Sep 2010 15:01:30 +0300 | |
Subject: [PATCH] Failing tests. | |
--- | |
activerecord/test/cases/associations/eager_test.rb | 35 ++++++++++++++++++++ | |
1 files changed, 35 insertions(+), 0 deletions(-) | |
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb | |
index 1870f97..b9f479e 100644 | |
--- a/activerecord/test/cases/associations/eager_test.rb | |
+++ b/activerecord/test/cases/associations/eager_test.rb | |
@@ -79,6 +79,41 @@ class EagerAssociationTest < ActiveRecord::TestCase | |
assert posts.first.comments.include?(comments(:greetings)) | |
end | |
+ def test_loading_with_includes_on_has_one_association | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}) | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_loading_with_includes_on_has_one_association_and_order | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}, :order => "author_addresses.id") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_loading_with_includes_on_has_one_association_and_order_in_first_associated_table | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}, :order => "authors.id") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_loading_with_includes_on_has_one_association_and_order_in_second_associated_table | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}, :order => "posts.id") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_loading_with_includes_on_has_one_association_and_conditions | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}, :conditions => "author_addresses.id > 0") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_loading_with_includes_on_has_one_association_and_conditions_in_first_associated_table | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}, :conditions => "authors.id > 0") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_loading_with_includes_on_has_one_association_and_conditions_in_second_associated_table | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}, :conditions => "posts.id > 0") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
def test_duplicate_middle_objects | |
comments = Comment.find :all, :conditions => 'post_id = 1', :include => [:post => :author] | |
assert_no_queries do | |
-- | |
1.7.1 | |
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 7589594dc8f659d79a87019ba40176d696f4f860 Mon Sep 17 00:00:00 2001 | |
From: Fotos Georgiadis <fotos@rento.gr> | |
Date: Sat, 22 Jan 2011 00:16:25 +0200 | |
Subject: [PATCH] Fixed bug with nested has_many eager loaded associations. | |
--- | |
activerecord/lib/active_record/associations.rb | 2 +- | |
activerecord/test/cases/associations/eager_test.rb | 35 ++++++++++++++++++++ | |
2 files changed, 36 insertions(+), 1 deletions(-) | |
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb | |
index 3a32581..dced226 100755 | |
--- a/activerecord/lib/active_record/associations.rb | |
+++ b/activerecord/lib/active_record/associations.rb | |
@@ -1967,7 +1967,7 @@ module ActiveRecord | |
collection.__send__(:set_inverse_instance, association, record) | |
when :has_one | |
return if record.id.to_s != join.parent.record_id(row).to_s | |
- return if record.instance_variable_defined?("@#{join.reflection.name}") | |
+ return record.instance_variable_get("@#{join.reflection.name}") if record.instance_variable_defined?("@#{join.reflection.name}") | |
association = join.instantiate(row) unless row[join.aliased_primary_key].nil? | |
set_target_and_inverse(join, association, record) | |
when :belongs_to | |
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb | |
index b711719..ad454a7 100644 | |
--- a/activerecord/test/cases/associations/eager_test.rb | |
+++ b/activerecord/test/cases/associations/eager_test.rb | |
@@ -79,6 +79,41 @@ class EagerAssociationTest < ActiveRecord::TestCase | |
assert posts.first.comments.include?(comments(:greetings)) | |
end | |
+ def test_loading_with_includes_on_has_one_association | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}) | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_loading_with_includes_on_has_one_association_and_order | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}, :order => "author_addresses.id") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_loading_with_includes_on_has_one_association_and_order_in_first_associated_table | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}, :order => "authors.id") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_loading_with_includes_on_has_one_association_and_order_in_second_associated_table | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}, :order => "posts.id") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_loading_with_includes_on_has_one_association_and_conditions | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}, :conditions => "author_addresses.id > 0") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_loading_with_includes_on_has_one_association_and_conditions_in_first_associated_table | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}, :conditions => "authors.id > 0") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_loading_with_includes_on_has_one_association_and_conditions_in_second_associated_table | |
+ aa = AuthorAddress.find(1, :include => {:author => :posts}, :conditions => "posts.id > 0") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
def test_duplicate_middle_objects | |
comments = Comment.find :all, :conditions => 'post_id = 1', :include => [:post => :author] | |
assert_no_queries do | |
-- | |
1.7.3.1 | |
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 25b287dbd98df07fdc746dc287fb72ee0f3b1f40 Mon Sep 17 00:00:00 2001 | |
From: robg <rob.golkosky@gmail.com> | |
Date: Thu, 14 Apr 2011 13:55:38 -0700 | |
Subject: [PATCH] Tests for #5623 | |
--- | |
activerecord/test/cases/associations/eager_test.rb | 35 ++++++++++++++++++++ | |
1 files changed, 35 insertions(+), 0 deletions(-) | |
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb | |
index 40c82f2..65ac657 100644 | |
--- a/activerecord/test/cases/associations/eager_test.rb | |
+++ b/activerecord/test/cases/associations/eager_test.rb | |
@@ -242,6 +242,41 @@ class EagerAssociationTest < ActiveRecord::TestCase | |
end | |
end | |
+ def test_nested_loading_through_has_one_association | |
+ aa = AuthorAddress.find(author_addresses(:david_address).id, :include => {:author => :posts}) | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_nested_loading_through_has_one_association_with_order | |
+ aa = AuthorAddress.find(author_addresses(:david_address).id, :include => {:author => :posts}, :order => 'author_addresses.id') | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_nested_loading_through_has_one_association_with_order_on_association | |
+ aa = AuthorAddress.find(author_addresses(:david_address).id, :include => {:author => :posts}, :order => 'authors.id') | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_nested_loading_through_has_one_association_with_order_on_nested_association | |
+ aa = AuthorAddress.find(author_addresses(:david_address).id, :include => {:author => :posts}, :order => 'posts.id') | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_nested_loading_through_has_one_association_with_conditions | |
+ aa = AuthorAddress.find(author_addresses(:david_address).id, :include => {:author => :posts}, :conditions => "author_addresses.id > 0") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_nested_loading_through_has_one_association_with_conditions_on_association | |
+ aa = AuthorAddress.find(author_addresses(:david_address).id, :include => {:author => :posts}, :conditions => "authors.id > 0") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
+ def test_nested_loading_through_has_one_association_with_conditions_on_nested_association | |
+ aa = AuthorAddress.find(author_addresses(:david_address).id, :include => {:author => :posts}, :conditions => "posts.id > 0") | |
+ assert_equal aa.author.posts.count, aa.author.posts.length | |
+ end | |
+ | |
def test_eager_association_loading_with_belongs_to_and_foreign_keys | |
pets = Pet.find(:all, :include => :owner) | |
assert_equal 3, pets.length | |
-- | |
1.7.0.4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment