mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Move caching initialization to Railtie
Also - Add reference to config from ActiveModelSerializers.config - correctly call super in FragmentCacheTest#setup - rename test rails app from Foo to ActiveModelSerializers::RailsApplication
This commit is contained in:
parent
2bea7f94f3
commit
a9ce4fb766
@ -152,7 +152,7 @@ module ActiveModel
|
||||
# @todo require less code comments. See
|
||||
# https://github.com/rails-api/active_model_serializers/pull/1249#issuecomment-146567837
|
||||
def self.cache(options = {})
|
||||
self._cache = ActionController::Base.cache_store if Rails.configuration.action_controller.perform_caching
|
||||
self._cache = ActiveModelSerializers.config.cache_store if ActiveModelSerializers.config.perform_caching
|
||||
self._cache_key = options.delete(:key)
|
||||
self._cache_only = options.delete(:only)
|
||||
self._cache_except = options.delete(:except)
|
||||
|
||||
@ -8,6 +8,13 @@ module ActiveModel
|
||||
end
|
||||
end
|
||||
|
||||
initializer 'active_model_serializers.caching' do
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
ActiveModelSerializers.config.cache_store = ActionController::Base.cache_store
|
||||
ActiveModelSerializers.config.perform_caching = Rails.configuration.action_controller.perform_caching
|
||||
end
|
||||
end
|
||||
|
||||
initializer 'generators' do |app|
|
||||
app.load_generators
|
||||
require 'generators/serializer/resource_override'
|
||||
|
||||
@ -5,6 +5,10 @@ require 'action_controller/railtie'
|
||||
module ActiveModelSerializers
|
||||
mattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
|
||||
|
||||
def self.config
|
||||
ActiveModel::Serializer.config
|
||||
end
|
||||
|
||||
extend ActiveSupport::Autoload
|
||||
autoload :Model
|
||||
autoload :Callbacks
|
||||
|
||||
@ -4,6 +4,7 @@ module ActiveModel
|
||||
module Adapter
|
||||
class FragmentCacheTest < Minitest::Test
|
||||
def setup
|
||||
super
|
||||
@spam = Spam::UnrelatedLink.new(id: 'spam-id-1')
|
||||
@author = Author.new(name: 'Joao M. D. Moura')
|
||||
@role = Role.new(name: 'Great Author', description: nil)
|
||||
|
||||
@ -1,14 +1,18 @@
|
||||
class Foo < Rails::Application
|
||||
class ActiveModelSerializers::RailsApplication < Rails::Application
|
||||
if Rails::VERSION::MAJOR >= 4
|
||||
config.eager_load = false
|
||||
|
||||
config.secret_key_base = 'abc123'
|
||||
config.action_controller.perform_caching = true
|
||||
|
||||
config.active_support.test_order = :random
|
||||
|
||||
config.logger = Logger.new(nil)
|
||||
|
||||
config.action_controller.perform_caching = true
|
||||
ActionController::Base.cache_store = :memory_store
|
||||
end
|
||||
end
|
||||
Foo.initialize!
|
||||
ActiveModelSerializers::RailsApplication.initialize!
|
||||
|
||||
module TestHelper
|
||||
Routes = ActionDispatch::Routing::RouteSet.new
|
||||
|
||||
Loading…
Reference in New Issue
Block a user