mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
include old implicit serialization custom root tests with failing empty array test
This commit is contained in:
parent
e5ccb8e4dd
commit
1d31096600
@ -18,6 +18,26 @@ module ActionController
|
|||||||
end
|
end
|
||||||
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
|
def render_array_using_implicit_serializer
|
||||||
array = [
|
array = [
|
||||||
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
|
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
|
||||||
@ -169,6 +189,30 @@ module ActionController
|
|||||||
assert_equal expected.to_json, @response.body
|
assert_equal expected.to_json, @response.body
|
||||||
end
|
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
|
def test_render_json_object_without_serializer
|
||||||
get :render_json_object_without_serializer
|
get :render_json_object_without_serializer
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user