Skip to content

Commit

Permalink
Add test for custom root and meta using the array serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbranson committed Jun 3, 2015
1 parent d8cf11e commit 3a02ef8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/action_controller/serialization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ def render_using_custom_root_in_adapter_with_a_default
render json: @profile, root: "profile", adapter: :json_api
end

def render_array_using_custom_root_and_meta
array = [
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })
]
render json: array, root: "custom_root", meta: { total: 10 }
end

def render_array_using_implicit_serializer
array = [
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
Expand Down Expand Up @@ -209,6 +217,25 @@ def test_render_using_custom_root_in_adapter_with_a_default
assert_equal expected.to_json, @response.body
end

def test_render_array_using_custom_root_and_meta
get :render_array_using_custom_root_and_meta
assert_equal 'application/json', @response.content_type

expected = { custom_root: [
{
name: 'Name 1',
description: 'Description 1',
},
{
name: 'Name 2',
description: 'Description 2',
}],
meta: { total: 10 }
}

assert_equal expected.to_json, @response.body
end

def test_render_array_using_implicit_serializer
get :render_array_using_implicit_serializer
assert_equal 'application/json', @response.content_type
Expand Down

0 comments on commit 3a02ef8

Please sign in to comment.