active_model_serializers 0.10.0 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +39 -2
- data/Gemfile +1 -1
- data/README.md +21 -24
- data/Rakefile +3 -3
- data/active_model_serializers.gemspec +19 -23
- data/docs/general/adapters.md +4 -2
- data/docs/general/configuration_options.md +6 -1
- data/docs/general/deserialization.md +1 -1
- data/docs/general/fields.md +31 -0
- data/docs/general/rendering.md +7 -2
- data/docs/general/serializers.md +62 -3
- data/docs/howto/add_pagination_links.md +2 -3
- data/docs/integrations/ember-and-json-api.md +25 -10
- data/docs/jsonapi/schema.md +1 -1
- data/lib/action_controller/serialization.rb +4 -3
- data/lib/active_model/serializer/adapter/base.rb +2 -0
- data/lib/active_model/serializer/array_serializer.rb +8 -5
- data/lib/active_model/serializer/associations.rb +6 -7
- data/lib/active_model/serializer/belongs_to_reflection.rb +0 -3
- data/lib/active_model/serializer/caching.rb +67 -112
- data/lib/active_model/serializer/collection_serializer.rb +30 -10
- data/lib/active_model/serializer/configuration.rb +1 -0
- data/lib/active_model/serializer/error_serializer.rb +11 -7
- data/lib/active_model/serializer/errors_serializer.rb +25 -20
- data/lib/active_model/serializer/has_many_reflection.rb +0 -3
- data/lib/active_model/serializer/has_one_reflection.rb +0 -3
- data/lib/active_model/serializer/lint.rb +134 -130
- data/lib/active_model/serializer/reflection.rb +3 -3
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model/serializer.rb +57 -15
- data/lib/active_model_serializers/adapter/attributes.rb +2 -67
- data/lib/active_model_serializers/adapter/base.rb +38 -38
- data/lib/active_model_serializers/adapter/json_api/link.rb +1 -1
- data/lib/active_model_serializers/adapter/json_api/pagination_links.rb +8 -1
- data/lib/active_model_serializers/adapter/json_api.rb +36 -28
- data/lib/active_model_serializers/adapter.rb +6 -0
- data/lib/active_model_serializers/deprecate.rb +1 -2
- data/lib/active_model_serializers/deserialization.rb +2 -0
- data/lib/active_model_serializers/model.rb +3 -1
- data/lib/active_model_serializers/railtie.rb +3 -1
- data/lib/active_model_serializers/register_jsonapi_renderer.rb +44 -31
- data/lib/active_model_serializers/serialization_context.rb +10 -3
- data/lib/active_model_serializers.rb +6 -0
- data/lib/generators/rails/serializer_generator.rb +3 -3
- data/lib/grape/active_model_serializers.rb +7 -5
- data/lib/grape/formatters/active_model_serializers.rb +19 -2
- data/lib/grape/helpers/active_model_serializers.rb +1 -0
- data/test/action_controller/adapter_selector_test.rb +4 -4
- data/test/action_controller/explicit_serializer_test.rb +5 -4
- data/test/action_controller/json/include_test.rb +106 -27
- data/test/action_controller/json_api/errors_test.rb +6 -7
- data/test/action_controller/json_api/linked_test.rb +29 -24
- data/test/action_controller/json_api/pagination_test.rb +19 -19
- data/test/action_controller/serialization_test.rb +10 -7
- data/test/active_model_serializers/json_pointer_test.rb +15 -13
- data/test/active_model_serializers/key_transform_test.rb +254 -252
- data/test/active_model_serializers/model_test.rb +6 -4
- data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +143 -0
- data/test/active_model_serializers/serialization_context_test_isolated.rb +23 -10
- data/test/adapter/json/collection_test.rb +14 -0
- data/test/adapter/json/transform_test.rb +14 -14
- data/test/adapter/json_api/collection_test.rb +4 -3
- data/test/adapter/json_api/errors_test.rb +17 -19
- data/test/adapter/json_api/has_many_test.rb +18 -18
- data/test/adapter/json_api/json_api_test.rb +5 -7
- data/test/adapter/json_api/linked_test.rb +9 -6
- data/test/adapter/json_api/links_test.rb +3 -1
- data/test/adapter/json_api/pagination_links_test.rb +19 -7
- data/test/adapter/json_api/relationships_test.rb +9 -4
- data/test/adapter/json_api/resource_identifier_test.rb +7 -2
- data/test/adapter/json_api/resource_meta_test.rb +3 -3
- data/test/adapter/json_api/transform_test.rb +251 -250
- data/test/adapter/json_api/type_test.rb +1 -1
- data/test/adapter/json_test.rb +8 -7
- data/test/adapter/null_test.rb +1 -2
- data/test/adapter/polymorphic_test.rb +5 -5
- data/test/adapter_test.rb +1 -1
- data/test/benchmark/app.rb +1 -1
- data/test/benchmark/bm_caching.rb +15 -15
- data/test/benchmark/bm_transform.rb +16 -5
- data/test/benchmark/controllers.rb +16 -17
- data/test/benchmark/fixtures.rb +72 -72
- data/test/cache_test.rb +101 -45
- data/test/collection_serializer_test.rb +2 -2
- data/test/fixtures/poro.rb +8 -7
- data/test/grape_test.rb +152 -56
- data/test/lint_test.rb +1 -1
- data/test/logger_test.rb +13 -11
- data/test/serializable_resource_test.rb +18 -22
- data/test/serializers/associations_test.rb +10 -10
- data/test/serializers/attribute_test.rb +1 -1
- data/test/serializers/attributes_test.rb +1 -1
- data/test/serializers/fieldset_test.rb +1 -1
- data/test/serializers/meta_test.rb +12 -6
- data/test/serializers/root_test.rb +1 -1
- data/test/serializers/serializer_for_test.rb +3 -1
- data/test/support/isolated_unit.rb +5 -2
- data/test/support/rails5_shims.rb +8 -2
- data/test/support/rails_app.rb +0 -9
- data/test/support/serialization_testing.rb +7 -5
- metadata +54 -24
- data/.rubocop_todo.yml +0 -167
- data/lib/active_model/serializer/include_tree.rb +0 -111
- data/test/include_tree/from_include_args_test.rb +0 -26
- data/test/include_tree/from_string_test.rb +0 -94
- data/test/include_tree/include_args_to_hash_test.rb +0 -64
@@ -70,32 +70,33 @@ module ActiveModelSerializers
|
|
70
70
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
71
71
|
result = adapter.serializable_hash
|
72
72
|
assert_equal({
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
73
|
+
data: {
|
74
|
+
id: '1337',
|
75
|
+
type: 'posts',
|
76
|
+
attributes: {
|
77
|
+
title: 'Title 1',
|
78
|
+
body: 'Body 1',
|
79
|
+
:"publish-at" => @publish_at
|
80
|
+
},
|
81
|
+
relationships: {
|
82
|
+
author: {
|
83
|
+
data: { id: '1', type: 'authors' }
|
84
|
+
},
|
85
|
+
comments: {
|
86
|
+
data: [
|
87
|
+
{ id: '7', type: 'comments' },
|
88
|
+
{ id: '12', type: 'comments' }
|
89
|
+
]
|
90
|
+
}
|
91
|
+
},
|
92
|
+
links: {
|
93
|
+
self: 'http://example.com/posts/1337',
|
94
|
+
:"post-authors" => 'http://example.com/posts/1337/authors',
|
95
|
+
:"subscriber-comments" => 'http://example.com/posts/1337/comments'
|
96
|
+
},
|
97
|
+
meta: { rating: 5, :"favorite-count" => 10 }
|
98
|
+
}
|
99
|
+
}, result)
|
99
100
|
end
|
100
101
|
|
101
102
|
def test_success_document_transform_global_config
|
@@ -106,32 +107,33 @@ module ActiveModelSerializers
|
|
106
107
|
adapter.serializable_hash
|
107
108
|
end
|
108
109
|
assert_equal({
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
110
|
+
data: {
|
111
|
+
id: '1337',
|
112
|
+
type: 'posts',
|
113
|
+
attributes: {
|
114
|
+
title: 'Title 1',
|
115
|
+
body: 'Body 1',
|
116
|
+
publishAt: @publish_at
|
117
|
+
},
|
118
|
+
relationships: {
|
119
|
+
author: {
|
120
|
+
data: { id: '1', type: 'authors' }
|
121
|
+
},
|
122
|
+
comments: {
|
123
|
+
data: [
|
124
|
+
{ id: '7', type: 'comments' },
|
125
|
+
{ id: '12', type: 'comments' }
|
126
|
+
]
|
127
|
+
}
|
128
|
+
},
|
129
|
+
links: {
|
130
|
+
self: 'http://example.com/posts/1337',
|
131
|
+
postAuthors: 'http://example.com/posts/1337/authors',
|
132
|
+
subscriberComments: 'http://example.com/posts/1337/comments'
|
133
|
+
},
|
134
|
+
meta: { rating: 5, favoriteCount: 10 }
|
135
|
+
}
|
136
|
+
}, result)
|
135
137
|
end
|
136
138
|
|
137
139
|
def test_success_doc_transform_serialization_ctx_overrides_global
|
@@ -142,32 +144,33 @@ module ActiveModelSerializers
|
|
142
144
|
adapter.serializable_hash
|
143
145
|
end
|
144
146
|
assert_equal({
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
147
|
+
Data: {
|
148
|
+
Id: '1337',
|
149
|
+
Type: 'Posts',
|
150
|
+
Attributes: {
|
151
|
+
Title: 'Title 1',
|
152
|
+
Body: 'Body 1',
|
153
|
+
PublishAt: @publish_at
|
154
|
+
},
|
155
|
+
Relationships: {
|
156
|
+
Author: {
|
157
|
+
Data: { Id: '1', Type: 'Authors' }
|
158
|
+
},
|
159
|
+
Comments: {
|
160
|
+
Data: [
|
161
|
+
{ Id: '7', Type: 'Comments' },
|
162
|
+
{ Id: '12', Type: 'Comments' }
|
163
|
+
]
|
164
|
+
}
|
165
|
+
},
|
166
|
+
Links: {
|
167
|
+
Self: 'http://example.com/posts/1337',
|
168
|
+
PostAuthors: 'http://example.com/posts/1337/authors',
|
169
|
+
SubscriberComments: 'http://example.com/posts/1337/comments'
|
170
|
+
},
|
171
|
+
Meta: { Rating: 5, FavoriteCount: 10 }
|
172
|
+
}
|
173
|
+
}, result)
|
171
174
|
end
|
172
175
|
|
173
176
|
def test_success_document_transform_dash
|
@@ -176,32 +179,33 @@ module ActiveModelSerializers
|
|
176
179
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
177
180
|
result = adapter.serializable_hash
|
178
181
|
assert_equal({
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
182
|
+
data: {
|
183
|
+
id: '1337',
|
184
|
+
type: 'posts',
|
185
|
+
attributes: {
|
186
|
+
title: 'Title 1',
|
187
|
+
body: 'Body 1',
|
188
|
+
:"publish-at" => @publish_at
|
189
|
+
},
|
190
|
+
relationships: {
|
191
|
+
author: {
|
192
|
+
data: { id: '1', type: 'authors' }
|
193
|
+
},
|
194
|
+
comments: {
|
195
|
+
data: [
|
196
|
+
{ id: '7', type: 'comments' },
|
197
|
+
{ id: '12', type: 'comments' }
|
198
|
+
]
|
199
|
+
}
|
200
|
+
},
|
201
|
+
links: {
|
202
|
+
self: 'http://example.com/posts/1337',
|
203
|
+
:"post-authors" => 'http://example.com/posts/1337/authors',
|
204
|
+
:"subscriber-comments" => 'http://example.com/posts/1337/comments'
|
205
|
+
},
|
206
|
+
meta: { rating: 5, :"favorite-count" => 10 }
|
207
|
+
}
|
208
|
+
}, result)
|
205
209
|
end
|
206
210
|
|
207
211
|
def test_success_document_transform_unaltered
|
@@ -210,32 +214,33 @@ module ActiveModelSerializers
|
|
210
214
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
211
215
|
result = adapter.serializable_hash
|
212
216
|
assert_equal({
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
217
|
+
data: {
|
218
|
+
id: '1337',
|
219
|
+
type: 'posts',
|
220
|
+
attributes: {
|
221
|
+
title: 'Title 1',
|
222
|
+
body: 'Body 1',
|
223
|
+
publish_at: @publish_at
|
224
|
+
},
|
225
|
+
relationships: {
|
226
|
+
author: {
|
227
|
+
data: { id: '1', type: 'authors' }
|
228
|
+
},
|
229
|
+
comments: {
|
230
|
+
data: [
|
231
|
+
{ id: '7', type: 'comments' },
|
232
|
+
{ id: '12', type: 'comments' }
|
233
|
+
]
|
234
|
+
}
|
235
|
+
},
|
236
|
+
links: {
|
237
|
+
self: 'http://example.com/posts/1337',
|
238
|
+
post_authors: 'http://example.com/posts/1337/authors',
|
239
|
+
subscriber_comments: 'http://example.com/posts/1337/comments'
|
240
|
+
},
|
241
|
+
meta: { rating: 5, favorite_count: 10 }
|
242
|
+
}
|
243
|
+
}, result)
|
239
244
|
end
|
240
245
|
|
241
246
|
def test_success_document_transform_undefined
|
@@ -254,32 +259,33 @@ module ActiveModelSerializers
|
|
254
259
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
255
260
|
result = adapter.serializable_hash
|
256
261
|
assert_equal({
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
262
|
+
Data: {
|
263
|
+
Id: '1337',
|
264
|
+
Type: 'Posts',
|
265
|
+
Attributes: {
|
266
|
+
Title: 'Title 1',
|
267
|
+
Body: 'Body 1',
|
268
|
+
PublishAt: @publish_at
|
269
|
+
},
|
270
|
+
Relationships: {
|
271
|
+
Author: {
|
272
|
+
Data: { Id: '1', Type: 'Authors' }
|
273
|
+
},
|
274
|
+
Comments: {
|
275
|
+
Data: [
|
276
|
+
{ Id: '7', Type: 'Comments' },
|
277
|
+
{ Id: '12', Type: 'Comments' }
|
278
|
+
]
|
279
|
+
}
|
280
|
+
},
|
281
|
+
Links: {
|
282
|
+
Self: 'http://example.com/posts/1337',
|
283
|
+
PostAuthors: 'http://example.com/posts/1337/authors',
|
284
|
+
SubscriberComments: 'http://example.com/posts/1337/comments'
|
285
|
+
},
|
286
|
+
Meta: { Rating: 5, FavoriteCount: 10 }
|
287
|
+
}
|
288
|
+
}, result)
|
283
289
|
end
|
284
290
|
|
285
291
|
def test_success_document_transform_camel_lower
|
@@ -288,32 +294,33 @@ module ActiveModelSerializers
|
|
288
294
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
289
295
|
result = adapter.serializable_hash
|
290
296
|
assert_equal({
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
297
|
+
data: {
|
298
|
+
id: '1337',
|
299
|
+
type: 'posts',
|
300
|
+
attributes: {
|
301
|
+
title: 'Title 1',
|
302
|
+
body: 'Body 1',
|
303
|
+
publishAt: @publish_at
|
304
|
+
},
|
305
|
+
relationships: {
|
306
|
+
author: {
|
307
|
+
data: { id: '1', type: 'authors' }
|
308
|
+
},
|
309
|
+
comments: {
|
310
|
+
data: [
|
311
|
+
{ id: '7', type: 'comments' },
|
312
|
+
{ id: '12', type: 'comments' }
|
313
|
+
]
|
314
|
+
}
|
315
|
+
},
|
316
|
+
links: {
|
317
|
+
self: 'http://example.com/posts/1337',
|
318
|
+
postAuthors: 'http://example.com/posts/1337/authors',
|
319
|
+
subscriberComments: 'http://example.com/posts/1337/comments'
|
320
|
+
},
|
321
|
+
meta: { rating: 5, favoriteCount: 10 }
|
322
|
+
}
|
323
|
+
}, result)
|
317
324
|
end
|
318
325
|
|
319
326
|
def test_error_document_transform_default
|
@@ -324,18 +331,18 @@ module ActiveModelSerializers
|
|
324
331
|
serializer = ActiveModel::Serializer::ErrorSerializer.new(resource)
|
325
332
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
326
333
|
result = adapter.serializable_hash
|
327
|
-
expected_errors_object =
|
328
|
-
|
329
|
-
|
330
|
-
{
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
334
|
+
expected_errors_object = {
|
335
|
+
errors: [
|
336
|
+
{
|
337
|
+
source: { pointer: '/data/attributes/published-at' },
|
338
|
+
detail: 'must be in the future'
|
339
|
+
},
|
340
|
+
{
|
341
|
+
source: { pointer: '/data/attributes/title' },
|
342
|
+
detail: 'must be longer'
|
343
|
+
}
|
344
|
+
]
|
345
|
+
}
|
339
346
|
assert_equal expected_errors_object, result
|
340
347
|
end
|
341
348
|
|
@@ -349,19 +356,18 @@ module ActiveModelSerializers
|
|
349
356
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
350
357
|
adapter.serializable_hash
|
351
358
|
end
|
352
|
-
expected_errors_object =
|
353
|
-
|
354
|
-
|
355
|
-
{
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
{
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
}
|
359
|
+
expected_errors_object = {
|
360
|
+
Errors: [
|
361
|
+
{
|
362
|
+
Source: { Pointer: '/data/attributes/PublishedAt' },
|
363
|
+
Detail: 'must be in the future'
|
364
|
+
},
|
365
|
+
{
|
366
|
+
Source: { Pointer: '/data/attributes/Title' },
|
367
|
+
Detail: 'must be longer'
|
368
|
+
}
|
369
|
+
]
|
370
|
+
}
|
365
371
|
assert_equal expected_errors_object, result
|
366
372
|
end
|
367
373
|
|
@@ -375,19 +381,18 @@ module ActiveModelSerializers
|
|
375
381
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
376
382
|
adapter.serializable_hash
|
377
383
|
end
|
378
|
-
expected_errors_object =
|
379
|
-
|
380
|
-
|
381
|
-
{
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
{
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
}
|
384
|
+
expected_errors_object = {
|
385
|
+
Errors: [
|
386
|
+
{
|
387
|
+
Source: { Pointer: '/data/attributes/PublishedAt' },
|
388
|
+
Detail: 'must be in the future'
|
389
|
+
},
|
390
|
+
{
|
391
|
+
Source: { Pointer: '/data/attributes/Title' },
|
392
|
+
Detail: 'must be longer'
|
393
|
+
}
|
394
|
+
]
|
395
|
+
}
|
391
396
|
assert_equal expected_errors_object, result
|
392
397
|
end
|
393
398
|
|
@@ -402,18 +407,17 @@ module ActiveModelSerializers
|
|
402
407
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
403
408
|
result = adapter.serializable_hash
|
404
409
|
|
405
|
-
expected_errors_object =
|
406
|
-
|
407
|
-
|
408
|
-
{
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
{
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
]
|
410
|
+
expected_errors_object = {
|
411
|
+
errors: [
|
412
|
+
{
|
413
|
+
source: { pointer: '/data/attributes/published-at' },
|
414
|
+
detail: 'must be in the future'
|
415
|
+
},
|
416
|
+
{
|
417
|
+
source: { pointer: '/data/attributes/title' },
|
418
|
+
detail: 'must be longer'
|
419
|
+
}
|
420
|
+
]
|
417
421
|
}
|
418
422
|
assert_equal expected_errors_object, result
|
419
423
|
end
|
@@ -429,12 +433,11 @@ module ActiveModelSerializers
|
|
429
433
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
430
434
|
result = adapter.serializable_hash
|
431
435
|
|
432
|
-
expected_errors_object =
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
]
|
436
|
+
expected_errors_object = {
|
437
|
+
errors: [
|
438
|
+
{ source: { pointer: '/data/attributes/published_at' }, detail: 'must be in the future' },
|
439
|
+
{ source: { pointer: '/data/attributes/title' }, detail: 'must be longer' }
|
440
|
+
]
|
438
441
|
}
|
439
442
|
assert_equal expected_errors_object, result
|
440
443
|
end
|
@@ -466,12 +469,11 @@ module ActiveModelSerializers
|
|
466
469
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
467
470
|
result = adapter.serializable_hash
|
468
471
|
|
469
|
-
expected_errors_object =
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
]
|
472
|
+
expected_errors_object = {
|
473
|
+
Errors: [
|
474
|
+
{ Source: { Pointer: '/data/attributes/PublishedAt' }, Detail: 'must be in the future' },
|
475
|
+
{ Source: { Pointer: '/data/attributes/Title' }, Detail: 'must be longer' }
|
476
|
+
]
|
475
477
|
}
|
476
478
|
assert_equal expected_errors_object, result
|
477
479
|
end
|
@@ -487,12 +489,11 @@ module ActiveModelSerializers
|
|
487
489
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
488
490
|
result = adapter.serializable_hash
|
489
491
|
|
490
|
-
expected_errors_object =
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
]
|
492
|
+
expected_errors_object = {
|
493
|
+
errors: [
|
494
|
+
{ source: { pointer: '/data/attributes/publishedAt' }, detail: 'must be in the future' },
|
495
|
+
{ source: { pointer: '/data/attributes/title' }, detail: 'must be longer' }
|
496
|
+
]
|
496
497
|
}
|
497
498
|
assert_equal expected_errors_object, result
|
498
499
|
end
|
@@ -47,7 +47,7 @@ module ActiveModel
|
|
47
47
|
assert_equal(expected_type, hash.fetch(:data).fetch(:type))
|
48
48
|
end
|
49
49
|
|
50
|
-
def with_jsonapi_resource_type
|
50
|
+
def with_jsonapi_resource_type(inflection)
|
51
51
|
old_inflection = ActiveModelSerializers.config.jsonapi_resource_type
|
52
52
|
ActiveModelSerializers.config.jsonapi_resource_type = inflection
|
53
53
|
yield
|
data/test/adapter/json_test.rb
CHANGED
@@ -32,13 +32,14 @@ module ActiveModelSerializers
|
|
32
32
|
adapter = ActiveModelSerializers::Adapter::Json.new(serializer)
|
33
33
|
|
34
34
|
assert_equal({
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
id: 1,
|
36
|
+
reviews: [
|
37
|
+
{ id: 1, body: 'ZOMG A COMMENT' },
|
38
|
+
{ id: 2, body: 'ZOMG ANOTHER COMMENT' }
|
39
|
+
],
|
40
|
+
writer: { id: 1, name: 'Steve K.' },
|
41
|
+
site: { id: 1, name: 'My Blog!!' }
|
42
|
+
}, adapter.serializable_hash[:post])
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
data/test/adapter/null_test.rb
CHANGED
@@ -4,7 +4,7 @@ module ActiveModelSerializers
|
|
4
4
|
module Adapter
|
5
5
|
class NullTest < ActiveSupport::TestCase
|
6
6
|
def setup
|
7
|
-
profile = Profile.new(
|
7
|
+
profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
8
8
|
serializer = ProfileSerializer.new(profile)
|
9
9
|
|
10
10
|
@adapter = Null.new(serializer)
|
@@ -20,4 +20,3 @@ module ActiveModelSerializers
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|