mirror of https://github.com/rails/rails
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
This commit is contained in:
commit
36d3f59a31
|
@ -1114,6 +1114,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def reset_scope # :nodoc:
|
||||
@offsets = {}
|
||||
@scope = nil
|
||||
self
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue