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.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -4
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +39 -2
  5. data/Gemfile +1 -1
  6. data/README.md +21 -24
  7. data/Rakefile +3 -3
  8. data/active_model_serializers.gemspec +19 -23
  9. data/docs/general/adapters.md +4 -2
  10. data/docs/general/configuration_options.md +6 -1
  11. data/docs/general/deserialization.md +1 -1
  12. data/docs/general/fields.md +31 -0
  13. data/docs/general/rendering.md +7 -2
  14. data/docs/general/serializers.md +62 -3
  15. data/docs/howto/add_pagination_links.md +2 -3
  16. data/docs/integrations/ember-and-json-api.md +25 -10
  17. data/docs/jsonapi/schema.md +1 -1
  18. data/lib/action_controller/serialization.rb +4 -3
  19. data/lib/active_model/serializer/adapter/base.rb +2 -0
  20. data/lib/active_model/serializer/array_serializer.rb +8 -5
  21. data/lib/active_model/serializer/associations.rb +6 -7
  22. data/lib/active_model/serializer/belongs_to_reflection.rb +0 -3
  23. data/lib/active_model/serializer/caching.rb +67 -112
  24. data/lib/active_model/serializer/collection_serializer.rb +30 -10
  25. data/lib/active_model/serializer/configuration.rb +1 -0
  26. data/lib/active_model/serializer/error_serializer.rb +11 -7
  27. data/lib/active_model/serializer/errors_serializer.rb +25 -20
  28. data/lib/active_model/serializer/has_many_reflection.rb +0 -3
  29. data/lib/active_model/serializer/has_one_reflection.rb +0 -3
  30. data/lib/active_model/serializer/lint.rb +134 -130
  31. data/lib/active_model/serializer/reflection.rb +3 -3
  32. data/lib/active_model/serializer/version.rb +1 -1
  33. data/lib/active_model/serializer.rb +57 -15
  34. data/lib/active_model_serializers/adapter/attributes.rb +2 -67
  35. data/lib/active_model_serializers/adapter/base.rb +38 -38
  36. data/lib/active_model_serializers/adapter/json_api/link.rb +1 -1
  37. data/lib/active_model_serializers/adapter/json_api/pagination_links.rb +8 -1
  38. data/lib/active_model_serializers/adapter/json_api.rb +36 -28
  39. data/lib/active_model_serializers/adapter.rb +6 -0
  40. data/lib/active_model_serializers/deprecate.rb +1 -2
  41. data/lib/active_model_serializers/deserialization.rb +2 -0
  42. data/lib/active_model_serializers/model.rb +3 -1
  43. data/lib/active_model_serializers/railtie.rb +3 -1
  44. data/lib/active_model_serializers/register_jsonapi_renderer.rb +44 -31
  45. data/lib/active_model_serializers/serialization_context.rb +10 -3
  46. data/lib/active_model_serializers.rb +6 -0
  47. data/lib/generators/rails/serializer_generator.rb +3 -3
  48. data/lib/grape/active_model_serializers.rb +7 -5
  49. data/lib/grape/formatters/active_model_serializers.rb +19 -2
  50. data/lib/grape/helpers/active_model_serializers.rb +1 -0
  51. data/test/action_controller/adapter_selector_test.rb +4 -4
  52. data/test/action_controller/explicit_serializer_test.rb +5 -4
  53. data/test/action_controller/json/include_test.rb +106 -27
  54. data/test/action_controller/json_api/errors_test.rb +6 -7
  55. data/test/action_controller/json_api/linked_test.rb +29 -24
  56. data/test/action_controller/json_api/pagination_test.rb +19 -19
  57. data/test/action_controller/serialization_test.rb +10 -7
  58. data/test/active_model_serializers/json_pointer_test.rb +15 -13
  59. data/test/active_model_serializers/key_transform_test.rb +254 -252
  60. data/test/active_model_serializers/model_test.rb +6 -4
  61. data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +143 -0
  62. data/test/active_model_serializers/serialization_context_test_isolated.rb +23 -10
  63. data/test/adapter/json/collection_test.rb +14 -0
  64. data/test/adapter/json/transform_test.rb +14 -14
  65. data/test/adapter/json_api/collection_test.rb +4 -3
  66. data/test/adapter/json_api/errors_test.rb +17 -19
  67. data/test/adapter/json_api/has_many_test.rb +18 -18
  68. data/test/adapter/json_api/json_api_test.rb +5 -7
  69. data/test/adapter/json_api/linked_test.rb +9 -6
  70. data/test/adapter/json_api/links_test.rb +3 -1
  71. data/test/adapter/json_api/pagination_links_test.rb +19 -7
  72. data/test/adapter/json_api/relationships_test.rb +9 -4
  73. data/test/adapter/json_api/resource_identifier_test.rb +7 -2
  74. data/test/adapter/json_api/resource_meta_test.rb +3 -3
  75. data/test/adapter/json_api/transform_test.rb +251 -250
  76. data/test/adapter/json_api/type_test.rb +1 -1
  77. data/test/adapter/json_test.rb +8 -7
  78. data/test/adapter/null_test.rb +1 -2
  79. data/test/adapter/polymorphic_test.rb +5 -5
  80. data/test/adapter_test.rb +1 -1
  81. data/test/benchmark/app.rb +1 -1
  82. data/test/benchmark/bm_caching.rb +15 -15
  83. data/test/benchmark/bm_transform.rb +16 -5
  84. data/test/benchmark/controllers.rb +16 -17
  85. data/test/benchmark/fixtures.rb +72 -72
  86. data/test/cache_test.rb +101 -45
  87. data/test/collection_serializer_test.rb +2 -2
  88. data/test/fixtures/poro.rb +8 -7
  89. data/test/grape_test.rb +152 -56
  90. data/test/lint_test.rb +1 -1
  91. data/test/logger_test.rb +13 -11
  92. data/test/serializable_resource_test.rb +18 -22
  93. data/test/serializers/associations_test.rb +10 -10
  94. data/test/serializers/attribute_test.rb +1 -1
  95. data/test/serializers/attributes_test.rb +1 -1
  96. data/test/serializers/fieldset_test.rb +1 -1
  97. data/test/serializers/meta_test.rb +12 -6
  98. data/test/serializers/root_test.rb +1 -1
  99. data/test/serializers/serializer_for_test.rb +3 -1
  100. data/test/support/isolated_unit.rb +5 -2
  101. data/test/support/rails5_shims.rb +8 -2
  102. data/test/support/rails_app.rb +0 -9
  103. data/test/support/serialization_testing.rb +7 -5
  104. metadata +54 -24
  105. data/.rubocop_todo.yml +0 -167
  106. data/lib/active_model/serializer/include_tree.rb +0 -111
  107. data/test/include_tree/from_include_args_test.rb +0 -26
  108. data/test/include_tree/from_string_test.rb +0 -94
  109. 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
- 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
- links: {
92
- self: 'http://example.com/posts/1337',
93
- :"post-authors" => 'http://example.com/posts/1337/authors',
94
- :"subscriber-comments" => 'http://example.com/posts/1337/comments'
95
- },
96
- meta: { rating: 5, :"favorite-count" => 10 }
97
- }
98
- }, result)
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
- data: {
110
- id: '1337',
111
- type: 'posts',
112
- attributes: {
113
- title: 'Title 1',
114
- body: 'Body 1',
115
- publishAt: @publish_at
116
- },
117
- relationships: {
118
- author: {
119
- data: { id: '1', type: 'authors' }
120
- },
121
- comments: {
122
- data: [
123
- { id: '7', type: 'comments' },
124
- { id: '12', type: 'comments' }
125
- ] }
126
- },
127
- links: {
128
- self: 'http://example.com/posts/1337',
129
- postAuthors: 'http://example.com/posts/1337/authors',
130
- subscriberComments: 'http://example.com/posts/1337/comments'
131
- },
132
- meta: { rating: 5, favoriteCount: 10 }
133
- }
134
- }, result)
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
- Data: {
146
- Id: '1337',
147
- Type: 'Posts',
148
- Attributes: {
149
- Title: 'Title 1',
150
- Body: 'Body 1',
151
- PublishAt: @publish_at
152
- },
153
- Relationships: {
154
- Author: {
155
- Data: { Id: '1', Type: 'Authors' }
156
- },
157
- Comments: {
158
- Data: [
159
- { Id: '7', Type: 'Comments' },
160
- { Id: '12', Type: 'Comments' }
161
- ] }
162
- },
163
- Links: {
164
- Self: 'http://example.com/posts/1337',
165
- PostAuthors: 'http://example.com/posts/1337/authors',
166
- SubscriberComments: 'http://example.com/posts/1337/comments'
167
- },
168
- Meta: { Rating: 5, FavoriteCount: 10 }
169
- }
170
- }, result)
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
- data: {
180
- id: '1337',
181
- type: 'posts',
182
- attributes: {
183
- title: 'Title 1',
184
- body: 'Body 1',
185
- :"publish-at" => @publish_at
186
- },
187
- relationships: {
188
- author: {
189
- data: { id: '1', type: 'authors' }
190
- },
191
- comments: {
192
- data: [
193
- { id: '7', type: 'comments' },
194
- { id: '12', type: 'comments' }
195
- ] }
196
- },
197
- links: {
198
- self: 'http://example.com/posts/1337',
199
- :"post-authors" => 'http://example.com/posts/1337/authors',
200
- :"subscriber-comments" => 'http://example.com/posts/1337/comments'
201
- },
202
- meta: { rating: 5, :"favorite-count" => 10 }
203
- }
204
- }, result)
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
- data: {
214
- id: '1337',
215
- type: 'posts',
216
- attributes: {
217
- title: 'Title 1',
218
- body: 'Body 1',
219
- publish_at: @publish_at
220
- },
221
- relationships: {
222
- author: {
223
- data: { id: '1', type: 'authors' }
224
- },
225
- comments: {
226
- data: [
227
- { id: '7', type: 'comments' },
228
- { id: '12', type: 'comments' }
229
- ] }
230
- },
231
- links: {
232
- self: 'http://example.com/posts/1337',
233
- post_authors: 'http://example.com/posts/1337/authors',
234
- subscriber_comments: 'http://example.com/posts/1337/comments'
235
- },
236
- meta: { rating: 5, favorite_count: 10 }
237
- }
238
- }, result)
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
- Data: {
258
- Id: '1337',
259
- Type: 'Posts',
260
- Attributes: {
261
- Title: 'Title 1',
262
- Body: 'Body 1',
263
- PublishAt: @publish_at
264
- },
265
- Relationships: {
266
- Author: {
267
- Data: { Id: '1', Type: 'Authors' }
268
- },
269
- Comments: {
270
- Data: [
271
- { Id: '7', Type: 'Comments' },
272
- { Id: '12', Type: 'Comments' }
273
- ] }
274
- },
275
- Links: {
276
- Self: 'http://example.com/posts/1337',
277
- PostAuthors: 'http://example.com/posts/1337/authors',
278
- SubscriberComments: 'http://example.com/posts/1337/comments'
279
- },
280
- Meta: { Rating: 5, FavoriteCount: 10 }
281
- }
282
- }, result)
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
- data: {
292
- id: '1337',
293
- type: 'posts',
294
- attributes: {
295
- title: 'Title 1',
296
- body: 'Body 1',
297
- publishAt: @publish_at
298
- },
299
- relationships: {
300
- author: {
301
- data: { id: '1', type: 'authors' }
302
- },
303
- comments: {
304
- data: [
305
- { id: '7', type: 'comments' },
306
- { id: '12', type: 'comments' }
307
- ] }
308
- },
309
- links: {
310
- self: 'http://example.com/posts/1337',
311
- postAuthors: 'http://example.com/posts/1337/authors',
312
- subscriberComments: 'http://example.com/posts/1337/comments'
313
- },
314
- meta: { rating: 5, favoriteCount: 10 }
315
- }
316
- }, result)
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
- { :errors =>
329
- [
330
- {
331
- :source => { :pointer => '/data/attributes/published-at' },
332
- :detail => 'must be in the future' },
333
- {
334
- :source => { :pointer => '/data/attributes/title' },
335
- :detail => 'must be longer'
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
- { :Errors =>
354
- [
355
- {
356
- :Source => { :Pointer => '/data/attributes/PublishedAt' },
357
- :Detail => 'must be in the future'
358
- },
359
- {
360
- :Source => { :Pointer => '/data/attributes/Title' },
361
- :Detail => 'must be longer'
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
- { :Errors =>
380
- [
381
- {
382
- :Source => { :Pointer => '/data/attributes/PublishedAt' },
383
- :Detail => 'must be in the future'
384
- },
385
- {
386
- :Source => { :Pointer => '/data/attributes/Title' },
387
- :Detail => 'must be longer'
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
- { :errors =>
407
- [
408
- {
409
- :source => { :pointer => '/data/attributes/published-at' },
410
- :detail => 'must be in the future'
411
- },
412
- {
413
- :source => { :pointer => '/data/attributes/title' },
414
- :detail => 'must be longer'
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
- { :errors =>
434
- [
435
- { :source => { :pointer => '/data/attributes/published_at' }, :detail => 'must be in the future' },
436
- { :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
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
- { :Errors =>
471
- [
472
- { :Source => { :Pointer => '/data/attributes/PublishedAt' }, :Detail => 'must be in the future' },
473
- { :Source => { :Pointer => '/data/attributes/Title' }, :Detail => 'must be longer' }
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
- { :errors =>
492
- [
493
- { :source => { :pointer => '/data/attributes/publishedAt' }, :detail => 'must be in the future' },
494
- { :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
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 inflection
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
@@ -32,13 +32,14 @@ module ActiveModelSerializers
32
32
  adapter = ActiveModelSerializers::Adapter::Json.new(serializer)
33
33
 
34
34
  assert_equal({
35
- id: 1,
36
- reviews: [{ id: 1, body: 'ZOMG A COMMENT' },
37
- { id: 2, body: 'ZOMG ANOTHER COMMENT' }
38
- ],
39
- writer: { id: 1, name: 'Steve K.' },
40
- site: { id: 1, name: 'My Blog!!' }
41
- }, adapter.serializable_hash[:post])
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
@@ -4,7 +4,7 @@ module ActiveModelSerializers
4
4
  module Adapter
5
5
  class NullTest < ActiveSupport::TestCase
6
6
  def setup
7
- profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
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
-