Allow for the implicit use of ArraySerializer when :each_serializer is specified.

This commit is contained in:
Mike A. Owens
2014-11-07 09:39:36 -05:00
parent c84430cdad
commit 58b6c4a6b7
3 changed files with 38 additions and 6 deletions

View File

@@ -24,6 +24,19 @@ module ActionController
serializer: PaginatedSerializer,
each_serializer: ProfilePreviewSerializer
end
def render_array_using_implicit_serializer
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,
each_serializer: ProfilePreviewSerializer
end
end
tests MyController
@@ -48,6 +61,18 @@ module ActionController
assert_equal expected.to_json, @response.body
end
def test_render_array_using_explicit_serializer
get :render_array_using_implicit_serializer
assert_equal 'application/json', @response.content_type
expected = [
{ 'name' => 'Name 1' },
{ 'name' => 'Name 2' }
]
assert_equal expected.to_json, @response.body
end
end
end
end