mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Adds jsonapi_namespace_separator configuration Also: * Enable getting type from record class without serializer Needs Followup: - https://github.com/rails-api/active_model_serializers/pull/1874#discussion_r74607042 - https://github.com/rails-api/active_model_serializers/pull/1874#discussion_r74607734
64 lines
1.8 KiB
Ruby
64 lines
1.8 KiB
Ruby
module SerializationTesting
|
|
def config
|
|
ActiveModelSerializers.config
|
|
end
|
|
|
|
private
|
|
|
|
def generate_cached_serializer(obj)
|
|
ActiveModelSerializers::SerializableResource.new(obj).to_json
|
|
end
|
|
|
|
def with_namespace_separator(seperator)
|
|
original_seperator = ActiveModelSerializers.config.jsonapi_namespace_separator
|
|
ActiveModelSerializers.config.jsonapi_namespace_separator = seperator
|
|
yield
|
|
ensure
|
|
ActiveModelSerializers.config.jsonapi_namespace_separator = original_seperator
|
|
end
|
|
|
|
# Aliased as :with_configured_adapter to clarify that
|
|
# this method tests the configured adapter.
|
|
# When not testing configuration, it may be preferable
|
|
# to pass in the +adapter+ option to <tt>ActiveModelSerializers::SerializableResource</tt>.
|
|
# e.g ActiveModelSerializers::SerializableResource.new(resource, adapter: :json_api)
|
|
def with_adapter(adapter)
|
|
old_adapter = ActiveModelSerializers.config.adapter
|
|
ActiveModelSerializers.config.adapter = adapter
|
|
yield
|
|
ensure
|
|
ActiveModelSerializers.config.adapter = old_adapter
|
|
end
|
|
alias with_configured_adapter with_adapter
|
|
|
|
def with_config(hash)
|
|
old_config = config.dup
|
|
ActiveModelSerializers.config.update(hash)
|
|
yield
|
|
ensure
|
|
ActiveModelSerializers.config.replace(old_config)
|
|
end
|
|
|
|
def with_serializer_lookup_disabled
|
|
original_serializer_lookup = ActiveModelSerializers.config.serializer_lookup_enabled
|
|
ActiveModelSerializers.config.serializer_lookup_enabled = false
|
|
yield
|
|
ensure
|
|
ActiveModelSerializers.config.serializer_lookup_enabled = original_serializer_lookup
|
|
end
|
|
|
|
def serializable(resource, options = {})
|
|
ActiveModelSerializers::SerializableResource.new(resource, options)
|
|
end
|
|
end
|
|
|
|
module Minitest
|
|
class Test
|
|
def before_setup
|
|
ActionController::Base.cache_store.clear
|
|
end
|
|
|
|
include SerializationTesting
|
|
end
|
|
end
|