Skip to content

Commit 1d31096

Browse files
committed
include old implicit serialization custom root tests with failing empty array test
1 parent e5ccb8e commit 1d31096

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/action_controller/serialization_test.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,26 @@ def render_using_default_adapter_root
1818
end
1919
end
2020

21+
def render_array_using_custom_root
22+
with_adapter ActiveModel::Serializer::Adapter::Json do
23+
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
24+
render json: [@profile], root: "custom_root"
25+
end
26+
end
27+
28+
def render_array_that_is_empty_using_custom_root
29+
with_adapter ActiveModel::Serializer::Adapter::Json do
30+
render json: [], root: "custom_root"
31+
end
32+
end
33+
34+
def render_object_using_custom_root
35+
with_adapter ActiveModel::Serializer::Adapter::Json do
36+
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
37+
render json: @profile, root: "custom_root"
38+
end
39+
end
40+
2141
def render_array_using_implicit_serializer
2242
array = [
2343
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
@@ -169,6 +189,30 @@ def test_render_using_default_root
169189
assert_equal expected.to_json, @response.body
170190
end
171191

192+
def test_render_array_using_custom_root
193+
get :render_array_using_custom_root
194+
195+
expected = {custom_roots: [{name: "Name 1", description: "Description 1"}]}
196+
assert_equal 'application/json', @response.content_type
197+
assert_equal expected.to_json, @response.body
198+
end
199+
200+
def test_render_array_that_is_empty_using_custom_root
201+
get :render_array_that_is_empty_using_custom_root
202+
203+
expected = {custom_roots: []}
204+
assert_equal 'application/json', @response.content_type
205+
assert_equal expected.to_json, @response.body
206+
end
207+
208+
def test_render_object_using_custom_root
209+
get :render_object_using_custom_root
210+
211+
expected = {custom_root: {name: "Name 1", description: "Description 1"}}
212+
assert_equal 'application/json', @response.content_type
213+
assert_equal expected.to_json, @response.body
214+
end
215+
172216
def test_render_json_object_without_serializer
173217
get :render_json_object_without_serializer
174218

0 commit comments

Comments
 (0)