提交 bdf412b4 编写于 作者: R Rafael França 提交者: Rafael Mendonça França

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
上级 8ee7909f
......@@ -1118,6 +1118,7 @@ def reset
end
def reset_scope # :nodoc:
@offsets = {}
@scope = nil
self
end
......
......@@ -741,6 +741,41 @@ def test_find_first_sanitized
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册