Factor with_adapter + force cache clear before each test.

This commit is contained in:
Lucas Hosseini
2015-08-28 17:00:24 +02:00
parent 64168cbecd
commit 4bba16bf4e
4 changed files with 52 additions and 43 deletions

View File

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