diff --git a/lib/active_model_serializers/railtie.rb b/lib/active_model_serializers/railtie.rb index 1d95ceac..1c8ff3c9 100644 --- a/lib/active_model_serializers/railtie.rb +++ b/lib/active_model_serializers/railtie.rb @@ -25,8 +25,11 @@ module ActiveModelSerializers # and also before eager_loading (if enabled). initializer 'active_model_serializers.set_configs', :after => 'action_controller.set_configs' do ActiveModelSerializers.logger = Rails.configuration.action_controller.logger - ActiveModelSerializers.config.cache_store = Rails.configuration.action_controller.cache_store ActiveModelSerializers.config.perform_caching = Rails.configuration.action_controller.perform_caching + # We want this hook to run after the config has been set, even if ActionController has already loaded. + ActiveSupport.on_load(:action_controller) do + ActiveModelSerializers.config.cache_store = cache_store + end end generators do |app| diff --git a/test/serializers/caching_configuration_test_isolated.rb b/test/serializers/caching_configuration_test_isolated.rb index 1b6d5541..82e497b2 100644 --- a/test/serializers/caching_configuration_test_isolated.rb +++ b/test/serializers/caching_configuration_test_isolated.rb @@ -37,6 +37,7 @@ class CachingConfigurationTest < ActiveSupport::TestCase app.config.action_controller.perform_caching = true app.config.action_controller.cache_store = ActiveSupport::Cache.lookup_store(:memory_store) end + controller_cache_store # Force ActiveSupport.on_load(:action_controller) to run end test 'it sets perform_caching to true on AMS.config and serializers' do @@ -103,6 +104,7 @@ class CachingConfigurationTest < ActiveSupport::TestCase app.config.action_controller.perform_caching = false app.config.action_controller.cache_store = ActiveSupport::Cache.lookup_store(:memory_store) end + controller_cache_store # Force ActiveSupport.on_load(:action_controller) to run end test 'it sets perform_caching to false on AMS.config and serializers' do diff --git a/test/support/rails_app.rb b/test/support/rails_app.rb index bc2fc8d1..9d44a59a 100644 --- a/test/support/rails_app.rb +++ b/test/support/rails_app.rb @@ -5,7 +5,6 @@ module ActiveModelSerializers config.secret_key_base = 'abc123' config.active_support.test_order = :random config.action_controller.perform_caching = true - ActionController::Base.cache_store = :memory_store end app.routes.default_url_options = { host: 'example.com' }