Fix support for custom root in JSON-API adapter

This commit is contained in:
Guillermo Iguaran
2014-10-22 03:55:17 -03:00
parent 47deb87e81
commit 5f198667be
2 changed files with 18 additions and 1 deletions

View File

@@ -24,6 +24,16 @@ module ActionController
ActiveModel::Serializer.config.adapter = old_adapter
end
def render_using_custom_root_in_adapter_with_a_default
old_adapter = ActiveModel::Serializer.config.adapter
# JSON-API adapter sets root by default
ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::JsonApi
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
render json: @profile, root: "profile"
ensure
ActiveModel::Serializer.config.adapter = old_adapter
end
def render_array_using_implicit_serializer
array = [
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
@@ -57,6 +67,13 @@ module ActionController
assert_equal '{"profiles":{"name":"Name 1","description":"Description 1"}}', @response.body
end
def test_render_using_custom_root_in_adapter_with_a_default
get :render_using_custom_root_in_adapter_with_a_default
assert_equal 'application/json', @response.content_type
assert_equal '{"profile":{"name":"Name 1","description":"Description 1"}}', @response.body
end
def test_render_array_using_implicit_serializer
get :render_array_using_implicit_serializer
assert_equal 'application/json', @response.content_type