Skip to content

Commit fb62fb3

Browse files
Yohan Robertbf4
authored andcommitted
Fix caching issue happening with memory_store
It seems that fecthing from memory_store returns a reference to the object and not a copy. Since the Attributes adapter applies #merge! on the Hash that is returned from the memory_store, the value in the cache is also modified.
1 parent d50d29b commit fb62fb3

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/active_model_serializers/adapter/attributes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def cached_attributes(cached_serializer)
5555
def serializable_hash_for_single_resource(options)
5656
resource = resource_object_for(options)
5757
relationships = resource_relationships(options)
58-
resource.merge!(relationships)
58+
resource.merge(relationships)
5959
end
6060

6161
def resource_relationships(options)

test/support/rails_app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module ActiveModelSerializers
88
# TODO: figure out why turning on the memory cache changes
99
# the result of the CacheTest#test_associations_cache_when_updated
1010
# and if it is more correct or less correct.
11-
# config.action_controller.cache_store = :memory
11+
config.action_controller.cache_store = :memory_store
1212
end
1313

1414
app.routes.default_url_options = { host: 'example.com' }

0 commit comments

Comments
 (0)