aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorJohn Hawthorn <john@stembolt.com>2017-06-20 17:35:13 -0700
committerJohn Hawthorn <john@stembolt.com>2017-06-21 16:53:53 -0700
commitadcd3079970ea7ef715ddfb8d2a386971d73eb52 (patch)
tree0180a48c1a193a5743a043e6ffa88654bf68fde6 /activerecord/test/cases
parentc7f669af6f1d8e9053a586c97584702971e1906c (diff)
downloadrails-adcd3079970ea7ef715ddfb8d2a386971d73eb52.tar.gz
rails-adcd3079970ea7ef715ddfb8d2a386971d73eb52.tar.bz2
rails-adcd3079970ea7ef715ddfb8d2a386971d73eb52.zip
Move clearing of @offsets cache to reset_scope
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb33
1 files changed, 21 insertions, 12 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index ae58dbff21..169e1a5449 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -741,30 +741,39 @@ 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
+ 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
- # Calling first twice should return the same object
- original_object_id = firm.clients.first.object_id
- assert_equal firm.clients.first.object_id, original_object_id, "Expected multiple invocations of #first to return the same object"
+ def test_find_first_after_reset
+ firm = Firm.all.merge!(order: "id").first
+ collection = firm.clients
- firm.clients.reset
+ 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, firm.clients.first.object_id, "Expected #first after #reload to return a new object"
+ 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
- # Calling first twice should return the same object
- original_object_id = firm.clients.first.object_id
- assert_equal firm.clients.first.object_id, original_object_id, "Expected multiple invocations of #first to return the same object"
-
- firm.clients.reload
+ 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, firm.clients.first.object_id, "Expected #first after #reload to return a new object"
+ 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