1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #37210 from jonhyman/feature-fix-36956-rebased

Fixes #36956 by dup'ing the value and entry object returned from MemoryStore.
This commit is contained in:
Rafael França 2019-09-16 13:30:01 -04:00 committed by GitHub
commit a1b6c1669f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View file

@ -124,6 +124,8 @@ module ActiveSupport
entry = @data[key]
synchronize do
if entry
entry = entry.dup
entry.dup_value!
@key_access[key] = Time.now.to_f
else
@key_access.delete(key)

View file

@ -107,6 +107,36 @@ class MemoryStorePruningTest < ActiveSupport::TestCase
assert_not @cache.exist?(1)
end
def test_cache_not_mutated
item = { "foo" => "bar" }
key = "test_key"
@cache.write(key, item)
read_item = @cache.read(key)
read_item["foo"] = "xyz"
assert_equal item, @cache.read(key)
end
def test_cache_different_object_ids_hash
item = { "foo" => "bar" }
key = "test_key"
@cache.write(key, item)
read_item = @cache.read(key)
assert_not_equal item.object_id, read_item.object_id
assert_not_equal read_item.object_id, @cache.read(key).object_id
end
def test_cache_different_object_ids_string
item = "my_string"
key = "test_key"
@cache.write(key, item)
read_item = @cache.read(key)
assert_not_equal item.object_id, read_item.object_id
assert_not_equal read_item.object_id, @cache.read(key).object_id
end
def test_write_with_unless_exist
assert_equal true, @cache.write(1, "aaaaaaaaaa")
assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true)