@@ -18,6 +18,26 @@ def render_using_default_adapter_root
18
18
end
19
19
end
20
20
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
+
21
41
def render_array_using_implicit_serializer
22
42
array = [
23
43
Profile . new ( { name : 'Name 1' , description : 'Description 1' , comments : 'Comments 1' } ) ,
@@ -169,6 +189,30 @@ def test_render_using_default_root
169
189
assert_equal expected . to_json , @response . body
170
190
end
171
191
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
+
172
216
def test_render_json_object_without_serializer
173
217
get :render_json_object_without_serializer
174
218
0 commit comments