mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Factor with_adapter + force cache clear before each test.
This commit is contained in:
@@ -32,24 +32,24 @@ module ActiveModel
|
||||
ActiveModel::Serializer.config[:jsonapi_resource_type] = type
|
||||
yield
|
||||
ensure
|
||||
ActiveModel::Serializer.config[:jsonapi_resource_type] = old_type
|
||||
ActiveModel::Serializer.config.jsonapi_resource_type = old_type
|
||||
end
|
||||
|
||||
def test_config_plural
|
||||
with_jsonapi_resource_type :plural do
|
||||
serializer = CommentSerializer.new(@comment)
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
||||
ActionController::Base.cache_store.clear
|
||||
assert_equal('comments', adapter.serializable_hash[:data][:type])
|
||||
with_adapter :json_api do
|
||||
with_jsonapi_resource_type :plural do
|
||||
hash = ActiveModel::SerializableResource.serialize(@comment).serializable_hash
|
||||
assert_equal('comments', hash[:data][:type])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_config_singular
|
||||
with_jsonapi_resource_type :singular do
|
||||
serializer = CommentSerializer.new(@comment)
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
||||
ActionController::Base.cache_store.clear
|
||||
assert_equal('comment', adapter.serializable_hash[:data][:type])
|
||||
with_adapter :json_api do
|
||||
with_jsonapi_resource_type :singular do
|
||||
hash = ActiveModel::SerializableResource.serialize(@comment).serializable_hash
|
||||
assert_equal('comment', hash[:data][:type])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user