Skip to content

Commit 3a02ef8

Browse files
committed
Add test for custom root and meta using the array serializer
1 parent d8cf11e commit 3a02ef8

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/action_controller/serialization_test.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ def render_using_custom_root_in_adapter_with_a_default
3333
render json: @profile, root: "profile", adapter: :json_api
3434
end
3535

36+
def render_array_using_custom_root_and_meta
37+
array = [
38+
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
39+
Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })
40+
]
41+
render json: array, root: "custom_root", meta: { total: 10 }
42+
end
43+
3644
def render_array_using_implicit_serializer
3745
array = [
3846
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
@@ -209,6 +217,25 @@ def test_render_using_custom_root_in_adapter_with_a_default
209217
assert_equal expected.to_json, @response.body
210218
end
211219

220+
def test_render_array_using_custom_root_and_meta
221+
get :render_array_using_custom_root_and_meta
222+
assert_equal 'application/json', @response.content_type
223+
224+
expected = { custom_root: [
225+
{
226+
name: 'Name 1',
227+
description: 'Description 1',
228+
},
229+
{
230+
name: 'Name 2',
231+
description: 'Description 2',
232+
}],
233+
meta: { total: 10 }
234+
}
235+
236+
assert_equal expected.to_json, @response.body
237+
end
238+
212239
def test_render_array_using_implicit_serializer
213240
get :render_array_using_implicit_serializer
214241
assert_equal 'application/json', @response.content_type

0 commit comments

Comments
 (0)