aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_associations_test.rb
diff options
context:
space:
mode:
authorBogdan Gusiev <agresso@gmail.com>2019-02-13 12:25:43 +0200
committerBogdan Gusiev <agresso@gmail.com>2019-02-20 13:48:51 +0200
commitbd4eff2f99ffa5868574c497bc63f320cbda3083 (patch)
treeb21d4bdea255230b35ebc142472aaf3120dfed33 /activerecord/test/cases/associations/has_many_associations_test.rb
parent4cb1438b57067d637c79d49d0662c43b5b4e64c2 (diff)
downloadrails-bd4eff2f99ffa5868574c497bc63f320cbda3083.tar.gz
rails-bd4eff2f99ffa5868574c497bc63f320cbda3083.tar.bz2
rails-bd4eff2f99ffa5868574c497bc63f320cbda3083.zip
Fix reset of the source association when through association is loaded
The special case happens when through association has a custom scope that is applied to the source association when loading. In this case, the soucre association would need to be reset after main association is loaded. See tests. The special case exists when a through association has
Diffstat (limited to 'activerecord/test/cases/associations/has_many_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 5fdc5a92fc..38e25a9100 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -2080,10 +2080,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
end
def test_associations_order_should_be_priority_over_throughs_order
- david = authors(:david)
+ original = authors(:david)
expected = [12, 10, 9, 8, 7, 6, 5, 3, 2, 1]
- assert_equal expected, david.comments_desc.map(&:id)
- assert_equal expected, Author.includes(:comments_desc).find(david.id).comments_desc.map(&:id)
+ assert_equal expected, original.comments_desc.map(&:id)
+ preloaded = Author.includes(:comments_desc).find(original.id)
+ assert_equal expected, preloaded.comments_desc.map(&:id)
+ assert_equal original.posts_sorted_by_id.first.comments.map(&:id), preloaded.posts_sorted_by_id.first.comments.map(&:id)
end
def test_dynamic_find_should_respect_association_order_for_through