From fb62fb39b23501d038fcfd1ab87c368e29067077 Mon Sep 17 00:00:00 2001 From: Yohan Robert Date: Wed, 30 Mar 2016 11:10:36 +0200 Subject: [PATCH] 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. --- lib/active_model_serializers/adapter/attributes.rb | 2 +- test/support/rails_app.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_model_serializers/adapter/attributes.rb b/lib/active_model_serializers/adapter/attributes.rb index c062127c..8281392b 100644 --- a/lib/active_model_serializers/adapter/attributes.rb +++ b/lib/active_model_serializers/adapter/attributes.rb @@ -55,7 +55,7 @@ module ActiveModelSerializers def serializable_hash_for_single_resource(options) resource = resource_object_for(options) relationships = resource_relationships(options) - resource.merge!(relationships) + resource.merge(relationships) end def resource_relationships(options) diff --git a/test/support/rails_app.rb b/test/support/rails_app.rb index 1dc7e506..67b7e607 100644 --- a/test/support/rails_app.rb +++ b/test/support/rails_app.rb @@ -8,7 +8,7 @@ module ActiveModelSerializers # TODO: figure out why turning on the memory cache changes # the result of the CacheTest#test_associations_cache_when_updated # and if it is more correct or less correct. - # config.action_controller.cache_store = :memory + config.action_controller.cache_store = :memory_store end app.routes.default_url_options = { host: 'example.com' }