Restrict serializable_hash to accepted options, only for tests

This commit is contained in:
Benjamin Fleischer
2016-04-13 00:30:47 -05:00
parent aad7779a3f
commit 929a5d0a51
7 changed files with 57 additions and 3 deletions

View File

@@ -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__))