include old implicit serialization custom root tests with failing empty array test

This commit is contained in:
vyrak bunleang 2015-07-16 14:19:47 -06:00
parent e5ccb8e4dd
commit 1d31096600

View File

@ -18,6 +18,26 @@ module ActionController
end
end
def render_array_using_custom_root
with_adapter ActiveModel::Serializer::Adapter::Json do
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
render json: [@profile], root: "custom_root"
end
end
def render_array_that_is_empty_using_custom_root
with_adapter ActiveModel::Serializer::Adapter::Json do
render json: [], root: "custom_root"
end
end
def render_object_using_custom_root
with_adapter ActiveModel::Serializer::Adapter::Json do
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
render json: @profile, root: "custom_root"
end
end
def render_array_using_implicit_serializer
array = [
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
@ -169,6 +189,30 @@ module ActionController
assert_equal expected.to_json, @response.body
end
def test_render_array_using_custom_root
get :render_array_using_custom_root
expected = {custom_roots: [{name: "Name 1", description: "Description 1"}]}
assert_equal 'application/json', @response.content_type
assert_equal expected.to_json, @response.body
end
def test_render_array_that_is_empty_using_custom_root
get :render_array_that_is_empty_using_custom_root
expected = {custom_roots: []}
assert_equal 'application/json', @response.content_type
assert_equal expected.to_json, @response.body
end
def test_render_object_using_custom_root
get :render_object_using_custom_root
expected = {custom_root: {name: "Name 1", description: "Description 1"}}
assert_equal 'application/json', @response.content_type
assert_equal expected.to_json, @response.body
end
def test_render_json_object_without_serializer
get :render_json_object_without_serializer