diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-06-26 14:50:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-26 14:50:34 -0400 |
commit | 36d3f59a31c258570fea71902237ecb872ba9408 (patch) | |
tree | 88278cff7a79497713f017aa3d940677960441bf /activerecord/test/cases | |
parent | 229d8b2a7e30761054ca2eb5b359f4db4fadb7e2 (diff) | |
parent | adcd3079970ea7ef715ddfb8d2a386971d73eb52 (diff) | |
download | rails-36d3f59a31c258570fea71902237ecb872ba9408.tar.gz rails-36d3f59a31c258570fea71902237ecb872ba9408.tar.bz2 rails-36d3f59a31c258570fea71902237ecb872ba9408.zip |
Merge pull request #29511 from jhawthorn/clear_offsets_cache_on_collection_proxy
Rails 5.1.2.rc1 regression - Clear offset cache on CollectionProxy reset/reload
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 590d3642bd..169e1a5449 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -741,6 +741,41 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal client2, firm.clients.merge!(where: ["#{QUOTED_TYPE} = :type", { type: "Client" }], order: "id").first end + def test_find_first_after_reset_scope + firm = Firm.all.merge!(order: "id").first + collection = firm.clients + + original_object_id = collection.first.object_id + assert_equal original_object_id, collection.first.object_id, "Expected second call to #first to cache the same object" + + # It should return a different object, since the association has been reloaded + assert_not_equal original_object_id, firm.clients.first.object_id, "Expected #first to return a new object" + end + + def test_find_first_after_reset + firm = Firm.all.merge!(order: "id").first + collection = firm.clients + + original_object_id = collection.first.object_id + assert_equal original_object_id, collection.first.object_id, "Expected second call to #first to cache the same object" + collection.reset + + # It should return a different object, since the association has been reloaded + assert_not_equal original_object_id, collection.first.object_id, "Expected #first after #reload to return a new object" + end + + def test_find_first_after_reload + firm = Firm.all.merge!(order: "id").first + collection = firm.clients + + original_object_id = collection.first.object_id + assert_equal original_object_id, collection.first.object_id, "Expected second call to #first to cache the same object" + collection.reset + + # It should return a different object, since the association has been reloaded + assert_not_equal original_object_id, collection.first.object_id, "Expected #first after #reload to return a new object" + end + def test_find_all_with_include_and_conditions assert_nothing_raised do Developer.all.merge!(joins: :audit_logs, where: { "audit_logs.message" => nil, :name => "Smith" }).to_a |