mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
fix test for custom serializer, add test for :each_serializer
This commit is contained in:
parent
0832e42917
commit
84c7cfa988
@ -136,8 +136,14 @@ class RenderJsonTest < ActionController::TestCase
|
|||||||
render :json => JsonSerializable.new(true)
|
render :json => JsonSerializable.new(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# To specify a custom serializer for an object, use :serializer.
|
||||||
def render_json_with_custom_serializer
|
def render_json_with_custom_serializer
|
||||||
render :json => [], :serializer => CustomSerializer
|
render :json => Object.new, :serializer => CustomSerializer
|
||||||
|
end
|
||||||
|
|
||||||
|
# To specify a custom serializer for each item in the Array, use :each_serializer.
|
||||||
|
def render_json_array_with_custom_serializer
|
||||||
|
render :json => [Object.new], :each_serializer => CustomSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_json_with_links
|
def render_json_with_links
|
||||||
@ -263,6 +269,11 @@ class RenderJsonTest < ActionController::TestCase
|
|||||||
assert_match '{"hello":true}', @response.body
|
assert_match '{"hello":true}', @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_render_json_array_with_custom_serializer
|
||||||
|
get :render_json_array_with_custom_serializer
|
||||||
|
assert_match '{"test":[{"hello":true}]}', @response.body
|
||||||
|
end
|
||||||
|
|
||||||
def test_render_json_with_links
|
def test_render_json_with_links
|
||||||
get :render_json_with_links
|
get :render_json_with_links
|
||||||
assert_match '{"link":"http://www.nextangle.com/hypermedia"}', @response.body
|
assert_match '{"link":"http://www.nextangle.com/hypermedia"}', @response.body
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user