1
-
2
1
require 'test_helper'
3
2
4
3
module ActionController
@@ -12,31 +11,22 @@ def render_using_implicit_serializer
12
11
end
13
12
14
13
def render_using_default_adapter_root
15
- with_adapter ActiveModel ::Serializer ::Adapter ::JsonApi do
16
- # JSON-API adapter sets root by default
17
- @profile = Profile . new ( { name : 'Name 1' , description : 'Description 1' , comments : 'Comments 1' } )
18
- render json : @profile
19
- end
14
+ @profile = Profile . new ( { name : 'Name 1' , description : 'Description 1' , comments : 'Comments 1' } )
15
+ render json : @profile
20
16
end
21
17
22
18
def render_array_using_custom_root
23
- with_adapter ActiveModel ::Serializer ::Adapter ::Json do
24
- @profile = Profile . new ( { name : 'Name 1' , description : 'Description 1' , comments : 'Comments 1' } )
25
- render json : [ @profile ] , root : "custom_root"
26
- end
19
+ @profile = Profile . new ( { name : 'Name 1' , description : 'Description 1' , comments : 'Comments 1' } )
20
+ render json : [ @profile ] , root : "custom_root"
27
21
end
28
22
29
23
def render_array_that_is_empty_using_custom_root
30
- with_adapter ActiveModel ::Serializer ::Adapter ::Json do
31
- render json : [ ] , root : "custom_root"
32
- end
24
+ render json : [ ] , root : "custom_root"
33
25
end
34
26
35
27
def render_object_using_custom_root
36
- with_adapter ActiveModel ::Serializer ::Adapter ::Json do
37
- @profile = Profile . new ( { name : 'Name 1' , description : 'Description 1' , comments : 'Comments 1' } )
38
- render json : @profile , root : "custom_root"
39
- end
28
+ @profile = Profile . new ( { name : 'Name 1' , description : 'Description 1' , comments : 'Comments 1' } )
29
+ render json : @profile , root : "custom_root"
40
30
end
41
31
42
32
def render_array_using_implicit_serializer
@@ -48,14 +38,11 @@ def render_array_using_implicit_serializer
48
38
end
49
39
50
40
def render_array_using_implicit_serializer_and_meta
51
- with_adapter ActiveModel ::Serializer ::Adapter ::JsonApi do
52
-
53
- @profiles = [
54
- Profile . new ( { name : 'Name 1' , description : 'Description 1' , comments : 'Comments 1' } )
55
- ]
41
+ @profiles = [
42
+ Profile . new ( { name : 'Name 1' , description : 'Description 1' , comments : 'Comments 1' } )
43
+ ]
56
44
57
- render json : @profiles , meta : { total : 10 }
58
- end
45
+ render json : @profiles , meta : { total : 10 }
59
46
end
60
47
61
48
def render_object_with_cache_enabled
@@ -169,8 +156,9 @@ def test_render_using_implicit_serializer
169
156
end
170
157
171
158
def test_render_using_default_root
172
- get :render_using_default_adapter_root
173
-
159
+ with_adapter :json_api do
160
+ get :render_using_default_adapter_root
161
+ end
174
162
expected = {
175
163
data : {
176
164
id : assigns ( :profile ) . id . to_s ,
@@ -187,23 +175,28 @@ def test_render_using_default_root
187
175
end
188
176
189
177
def test_render_array_using_custom_root
190
- get :render_array_using_custom_root
191
-
178
+ with_adapter :json do
179
+ get :render_array_using_custom_root
180
+ end
192
181
expected = { custom_roots : [ { name : "Name 1" , description : "Description 1" } ] }
193
182
assert_equal 'application/json' , @response . content_type
194
183
assert_equal expected . to_json , @response . body
195
184
end
196
185
197
186
def test_render_array_that_is_empty_using_custom_root
198
- get :render_array_that_is_empty_using_custom_root
187
+ with_adapter :json do
188
+ get :render_array_that_is_empty_using_custom_root
189
+ end
199
190
200
191
expected = { custom_roots : [ ] }
201
192
assert_equal 'application/json' , @response . content_type
202
193
assert_equal expected . to_json , @response . body
203
194
end
204
195
205
196
def test_render_object_using_custom_root
206
- get :render_object_using_custom_root
197
+ with_adapter :json do
198
+ get :render_object_using_custom_root
199
+ end
207
200
208
201
expected = { custom_root : { name : "Name 1" , description : "Description 1" } }
209
202
assert_equal 'application/json' , @response . content_type
@@ -245,8 +238,9 @@ def test_render_array_using_implicit_serializer
245
238
end
246
239
247
240
def test_render_array_using_implicit_serializer_and_meta
248
- get :render_array_using_implicit_serializer_and_meta
249
-
241
+ with_adapter :json_api do
242
+ get :render_array_using_implicit_serializer_and_meta
243
+ end
250
244
expected = {
251
245
data : [
252
246
{
0 commit comments