mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Restrict serializable_hash to accepted options, only for tests
This commit is contained in:
@@ -15,6 +15,22 @@ require 'action_controller'
|
||||
require 'action_controller/test_case'
|
||||
require 'action_controller/railtie'
|
||||
require 'active_model_serializers'
|
||||
# For now, we only restrict the options to serializable_hash/as_json/to_json
|
||||
# in tests, to ensure developers don't add any unsupported options.
|
||||
# There's no known benefit, at this time, to having the filtering run in
|
||||
# production when the excluded options would simply not be used.
|
||||
#
|
||||
# However, for documentation purposes, the constant
|
||||
# ActiveModel::Serializer::SERIALIZABLE_HASH_VALID_KEYS is defined
|
||||
# in the Serializer.
|
||||
ActiveModelSerializers::Adapter::Base.class_eval do
|
||||
alias_method :original_serialization_options, :serialization_options
|
||||
|
||||
def serialization_options(options)
|
||||
original_serialization_options(options)
|
||||
.slice(*ActiveModel::Serializer::SERIALIZABLE_HASH_VALID_KEYS)
|
||||
end
|
||||
end
|
||||
require 'fileutils'
|
||||
FileUtils.mkdir_p(File.expand_path('../../tmp/cache', __FILE__))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user