active_model_serializers 0.10.0 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -4
  3. data/.travis.yml +9 -1
  4. data/CHANGELOG.md +81 -2
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +5 -2
  7. data/README.md +24 -24
  8. data/Rakefile +3 -3
  9. data/active_model_serializers.gemspec +20 -24
  10. data/docs/ARCHITECTURE.md +6 -7
  11. data/docs/README.md +2 -0
  12. data/docs/general/adapters.md +4 -2
  13. data/docs/general/caching.md +7 -1
  14. data/docs/general/configuration_options.md +70 -1
  15. data/docs/general/deserialization.md +1 -1
  16. data/docs/general/fields.md +31 -0
  17. data/docs/general/rendering.md +42 -3
  18. data/docs/general/serializers.md +97 -8
  19. data/docs/howto/add_pagination_links.md +4 -5
  20. data/docs/howto/add_relationship_links.md +137 -0
  21. data/docs/howto/add_root_key.md +4 -0
  22. data/docs/howto/grape_integration.md +42 -0
  23. data/docs/howto/outside_controller_use.md +9 -2
  24. data/docs/howto/passing_arbitrary_options.md +2 -2
  25. data/docs/howto/test.md +2 -0
  26. data/docs/howto/upgrade_from_0_8_to_0_10.md +265 -0
  27. data/docs/integrations/ember-and-json-api.md +64 -32
  28. data/docs/jsonapi/schema.md +1 -1
  29. data/lib/action_controller/serialization.rb +13 -3
  30. data/lib/active_model/serializer/adapter/base.rb +2 -0
  31. data/lib/active_model/serializer/array_serializer.rb +8 -5
  32. data/lib/active_model/serializer/association.rb +19 -4
  33. data/lib/active_model/serializer/belongs_to_reflection.rb +0 -3
  34. data/lib/active_model/serializer/collection_serializer.rb +35 -12
  35. data/lib/active_model/serializer/{associations.rb → concerns/associations.rb} +13 -11
  36. data/lib/active_model/serializer/{attributes.rb → concerns/attributes.rb} +0 -0
  37. data/lib/active_model/serializer/{caching.rb → concerns/caching.rb} +72 -113
  38. data/lib/active_model/serializer/{configuration.rb → concerns/configuration.rb} +25 -1
  39. data/lib/active_model/serializer/{links.rb → concerns/links.rb} +0 -0
  40. data/lib/active_model/serializer/{meta.rb → concerns/meta.rb} +0 -0
  41. data/lib/active_model/serializer/{type.rb → concerns/type.rb} +0 -0
  42. data/lib/active_model/serializer/error_serializer.rb +11 -7
  43. data/lib/active_model/serializer/errors_serializer.rb +25 -20
  44. data/lib/active_model/serializer/has_many_reflection.rb +0 -3
  45. data/lib/active_model/serializer/has_one_reflection.rb +0 -3
  46. data/lib/active_model/serializer/lint.rb +134 -130
  47. data/lib/active_model/serializer/reflection.rb +37 -21
  48. data/lib/active_model/serializer/version.rb +1 -1
  49. data/lib/active_model/serializer.rb +76 -37
  50. data/lib/active_model_serializers/adapter/attributes.rb +3 -66
  51. data/lib/active_model_serializers/adapter/base.rb +38 -38
  52. data/lib/active_model_serializers/adapter/json_api/link.rb +1 -1
  53. data/lib/active_model_serializers/adapter/json_api/pagination_links.rb +8 -1
  54. data/lib/active_model_serializers/adapter/json_api/relationship.rb +30 -19
  55. data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +23 -9
  56. data/lib/active_model_serializers/adapter/json_api.rb +44 -43
  57. data/lib/active_model_serializers/adapter.rb +6 -0
  58. data/lib/active_model_serializers/deprecate.rb +1 -2
  59. data/lib/active_model_serializers/deserialization.rb +2 -0
  60. data/lib/active_model_serializers/key_transform.rb +4 -0
  61. data/lib/active_model_serializers/lookup_chain.rb +80 -0
  62. data/lib/active_model_serializers/model.rb +4 -2
  63. data/lib/active_model_serializers/railtie.rb +3 -1
  64. data/lib/active_model_serializers/register_jsonapi_renderer.rb +44 -31
  65. data/lib/active_model_serializers/serializable_resource.rb +6 -5
  66. data/lib/active_model_serializers/serialization_context.rb +10 -3
  67. data/lib/active_model_serializers.rb +7 -0
  68. data/lib/generators/rails/serializer_generator.rb +4 -4
  69. data/lib/grape/active_model_serializers.rb +7 -5
  70. data/lib/grape/formatters/active_model_serializers.rb +19 -2
  71. data/lib/grape/helpers/active_model_serializers.rb +1 -0
  72. data/test/action_controller/adapter_selector_test.rb +4 -4
  73. data/test/action_controller/explicit_serializer_test.rb +5 -4
  74. data/test/action_controller/json/include_test.rb +106 -27
  75. data/test/action_controller/json_api/errors_test.rb +6 -7
  76. data/test/action_controller/json_api/fields_test.rb +57 -0
  77. data/test/action_controller/json_api/linked_test.rb +29 -24
  78. data/test/action_controller/json_api/pagination_test.rb +19 -19
  79. data/test/action_controller/json_api/transform_test.rb +3 -3
  80. data/test/action_controller/lookup_proc_test.rb +49 -0
  81. data/test/action_controller/namespace_lookup_test.rb +226 -0
  82. data/test/action_controller/serialization_test.rb +10 -7
  83. data/test/active_model_serializers/json_pointer_test.rb +15 -13
  84. data/test/active_model_serializers/key_transform_test.rb +286 -252
  85. data/test/active_model_serializers/model_test.rb +17 -4
  86. data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +143 -0
  87. data/test/active_model_serializers/serialization_context_test_isolated.rb +23 -10
  88. data/test/adapter/attributes_test.rb +43 -0
  89. data/test/adapter/json/collection_test.rb +14 -0
  90. data/test/adapter/json/transform_test.rb +15 -15
  91. data/test/adapter/json_api/collection_test.rb +4 -3
  92. data/test/adapter/json_api/errors_test.rb +17 -19
  93. data/test/adapter/json_api/fields_test.rb +4 -3
  94. data/test/adapter/json_api/has_many_test.rb +39 -18
  95. data/test/adapter/json_api/include_data_if_sideloaded_test.rb +166 -0
  96. data/test/adapter/json_api/json_api_test.rb +5 -7
  97. data/test/adapter/json_api/linked_test.rb +33 -12
  98. data/test/adapter/json_api/links_test.rb +4 -2
  99. data/test/adapter/json_api/pagination_links_test.rb +35 -8
  100. data/test/adapter/json_api/relationship_test.rb +309 -73
  101. data/test/adapter/json_api/resource_identifier_test.rb +27 -2
  102. data/test/adapter/json_api/resource_meta_test.rb +3 -3
  103. data/test/adapter/json_api/transform_test.rb +255 -253
  104. data/test/adapter/json_api/type_test.rb +1 -1
  105. data/test/adapter/json_test.rb +8 -7
  106. data/test/adapter/null_test.rb +1 -2
  107. data/test/adapter/polymorphic_test.rb +5 -5
  108. data/test/adapter_test.rb +1 -1
  109. data/test/benchmark/app.rb +1 -1
  110. data/test/benchmark/benchmarking_support.rb +1 -1
  111. data/test/benchmark/bm_active_record.rb +81 -0
  112. data/test/benchmark/bm_adapter.rb +38 -0
  113. data/test/benchmark/bm_caching.rb +16 -16
  114. data/test/benchmark/bm_lookup_chain.rb +83 -0
  115. data/test/benchmark/bm_transform.rb +16 -5
  116. data/test/benchmark/controllers.rb +16 -17
  117. data/test/benchmark/fixtures.rb +72 -72
  118. data/test/cache_test.rb +143 -49
  119. data/test/collection_serializer_test.rb +3 -3
  120. data/test/fixtures/poro.rb +52 -48
  121. data/test/generators/serializer_generator_test.rb +22 -5
  122. data/test/grape_test.rb +152 -56
  123. data/test/lint_test.rb +1 -1
  124. data/test/logger_test.rb +13 -11
  125. data/test/serializable_resource_test.rb +18 -22
  126. data/test/serializers/association_macros_test.rb +3 -2
  127. data/test/serializers/associations_test.rb +107 -32
  128. data/test/serializers/attribute_test.rb +2 -2
  129. data/test/serializers/attributes_test.rb +1 -1
  130. data/test/serializers/fieldset_test.rb +1 -1
  131. data/test/serializers/meta_test.rb +12 -6
  132. data/test/serializers/root_test.rb +1 -1
  133. data/test/serializers/serializer_for_test.rb +6 -4
  134. data/test/serializers/serializer_for_with_namespace_test.rb +87 -0
  135. data/test/support/isolated_unit.rb +5 -2
  136. data/test/support/rails5_shims.rb +8 -2
  137. data/test/support/rails_app.rb +0 -9
  138. data/test/support/serialization_testing.rb +23 -5
  139. data/test/test_helper.rb +1 -0
  140. metadata +85 -34
  141. data/.rubocop_todo.yml +0 -167
  142. data/lib/active_model/serializer/include_tree.rb +0 -111
  143. data/test/adapter/json_api/relationships_test.rb +0 -199
  144. data/test/include_tree/from_include_args_test.rb +0 -26
  145. data/test/include_tree/from_string_test.rb +0 -94
  146. data/test/include_tree/include_args_to_hash_test.rb +0 -64
@@ -4,7 +4,10 @@ module ActiveModelSerializers
4
4
  module Adapter
5
5
  class JsonApi
6
6
  class KeyCaseTest < ActiveSupport::TestCase
7
- Post = Class.new(::Model)
7
+ class Post < ::Model; end
8
+ class Author < ::Model; end
9
+ class Comment < ::Model; end
10
+
8
11
  class PostSerializer < ActiveModel::Serializer
9
12
  type 'posts'
10
13
  attributes :title, :body, :publish_at
@@ -23,13 +26,11 @@ module ActiveModelSerializers
23
26
  end
24
27
  end
25
28
 
26
- Author = Class.new(::Model)
27
29
  class AuthorSerializer < ActiveModel::Serializer
28
30
  type 'authors'
29
31
  attributes :first_name, :last_name
30
32
  end
31
33
 
32
- Comment = Class.new(::Model)
33
34
  class CommentSerializer < ActiveModel::Serializer
34
35
  type 'comments'
35
36
  attributes :body
@@ -70,32 +71,33 @@ module ActiveModelSerializers
70
71
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
71
72
  result = adapter.serializable_hash
72
73
  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)
74
+ data: {
75
+ id: '1337',
76
+ type: 'posts',
77
+ attributes: {
78
+ title: 'Title 1',
79
+ body: 'Body 1',
80
+ :"publish-at" => @publish_at
81
+ },
82
+ relationships: {
83
+ author: {
84
+ data: { id: '1', type: 'authors' }
85
+ },
86
+ comments: {
87
+ data: [
88
+ { id: '7', type: 'comments' },
89
+ { id: '12', type: 'comments' }
90
+ ]
91
+ }
92
+ },
93
+ links: {
94
+ self: 'http://example.com/posts/1337',
95
+ :"post-authors" => 'http://example.com/posts/1337/authors',
96
+ :"subscriber-comments" => 'http://example.com/posts/1337/comments'
97
+ },
98
+ meta: { rating: 5, :"favorite-count" => 10 }
99
+ }
100
+ }, result)
99
101
  end
100
102
 
101
103
  def test_success_document_transform_global_config
@@ -106,32 +108,33 @@ module ActiveModelSerializers
106
108
  adapter.serializable_hash
107
109
  end
108
110
  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)
111
+ data: {
112
+ id: '1337',
113
+ type: 'posts',
114
+ attributes: {
115
+ title: 'Title 1',
116
+ body: 'Body 1',
117
+ publishAt: @publish_at
118
+ },
119
+ relationships: {
120
+ author: {
121
+ data: { id: '1', type: 'authors' }
122
+ },
123
+ comments: {
124
+ data: [
125
+ { id: '7', type: 'comments' },
126
+ { id: '12', type: 'comments' }
127
+ ]
128
+ }
129
+ },
130
+ links: {
131
+ self: 'http://example.com/posts/1337',
132
+ postAuthors: 'http://example.com/posts/1337/authors',
133
+ subscriberComments: 'http://example.com/posts/1337/comments'
134
+ },
135
+ meta: { rating: 5, favoriteCount: 10 }
136
+ }
137
+ }, result)
135
138
  end
136
139
 
137
140
  def test_success_doc_transform_serialization_ctx_overrides_global
@@ -142,32 +145,33 @@ module ActiveModelSerializers
142
145
  adapter.serializable_hash
143
146
  end
144
147
  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)
148
+ Data: {
149
+ Id: '1337',
150
+ Type: 'Posts',
151
+ Attributes: {
152
+ Title: 'Title 1',
153
+ Body: 'Body 1',
154
+ PublishAt: @publish_at
155
+ },
156
+ Relationships: {
157
+ Author: {
158
+ Data: { Id: '1', Type: 'Authors' }
159
+ },
160
+ Comments: {
161
+ Data: [
162
+ { Id: '7', Type: 'Comments' },
163
+ { Id: '12', Type: 'Comments' }
164
+ ]
165
+ }
166
+ },
167
+ Links: {
168
+ Self: 'http://example.com/posts/1337',
169
+ PostAuthors: 'http://example.com/posts/1337/authors',
170
+ SubscriberComments: 'http://example.com/posts/1337/comments'
171
+ },
172
+ Meta: { Rating: 5, FavoriteCount: 10 }
173
+ }
174
+ }, result)
171
175
  end
172
176
 
173
177
  def test_success_document_transform_dash
@@ -176,32 +180,33 @@ module ActiveModelSerializers
176
180
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
177
181
  result = adapter.serializable_hash
178
182
  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)
183
+ data: {
184
+ id: '1337',
185
+ type: 'posts',
186
+ attributes: {
187
+ title: 'Title 1',
188
+ body: 'Body 1',
189
+ :"publish-at" => @publish_at
190
+ },
191
+ relationships: {
192
+ author: {
193
+ data: { id: '1', type: 'authors' }
194
+ },
195
+ comments: {
196
+ data: [
197
+ { id: '7', type: 'comments' },
198
+ { id: '12', type: 'comments' }
199
+ ]
200
+ }
201
+ },
202
+ links: {
203
+ self: 'http://example.com/posts/1337',
204
+ :"post-authors" => 'http://example.com/posts/1337/authors',
205
+ :"subscriber-comments" => 'http://example.com/posts/1337/comments'
206
+ },
207
+ meta: { rating: 5, :"favorite-count" => 10 }
208
+ }
209
+ }, result)
205
210
  end
206
211
 
207
212
  def test_success_document_transform_unaltered
@@ -210,32 +215,33 @@ module ActiveModelSerializers
210
215
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
211
216
  result = adapter.serializable_hash
212
217
  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)
218
+ data: {
219
+ id: '1337',
220
+ type: 'posts',
221
+ attributes: {
222
+ title: 'Title 1',
223
+ body: 'Body 1',
224
+ publish_at: @publish_at
225
+ },
226
+ relationships: {
227
+ author: {
228
+ data: { id: '1', type: 'authors' }
229
+ },
230
+ comments: {
231
+ data: [
232
+ { id: '7', type: 'comments' },
233
+ { id: '12', type: 'comments' }
234
+ ]
235
+ }
236
+ },
237
+ links: {
238
+ self: 'http://example.com/posts/1337',
239
+ post_authors: 'http://example.com/posts/1337/authors',
240
+ subscriber_comments: 'http://example.com/posts/1337/comments'
241
+ },
242
+ meta: { rating: 5, favorite_count: 10 }
243
+ }
244
+ }, result)
239
245
  end
240
246
 
241
247
  def test_success_document_transform_undefined
@@ -254,32 +260,33 @@ module ActiveModelSerializers
254
260
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
255
261
  result = adapter.serializable_hash
256
262
  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)
263
+ Data: {
264
+ Id: '1337',
265
+ Type: 'Posts',
266
+ Attributes: {
267
+ Title: 'Title 1',
268
+ Body: 'Body 1',
269
+ PublishAt: @publish_at
270
+ },
271
+ Relationships: {
272
+ Author: {
273
+ Data: { Id: '1', Type: 'Authors' }
274
+ },
275
+ Comments: {
276
+ Data: [
277
+ { Id: '7', Type: 'Comments' },
278
+ { Id: '12', Type: 'Comments' }
279
+ ]
280
+ }
281
+ },
282
+ Links: {
283
+ Self: 'http://example.com/posts/1337',
284
+ PostAuthors: 'http://example.com/posts/1337/authors',
285
+ SubscriberComments: 'http://example.com/posts/1337/comments'
286
+ },
287
+ Meta: { Rating: 5, FavoriteCount: 10 }
288
+ }
289
+ }, result)
283
290
  end
284
291
 
285
292
  def test_success_document_transform_camel_lower
@@ -288,32 +295,33 @@ module ActiveModelSerializers
288
295
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
289
296
  result = adapter.serializable_hash
290
297
  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)
298
+ data: {
299
+ id: '1337',
300
+ type: 'posts',
301
+ attributes: {
302
+ title: 'Title 1',
303
+ body: 'Body 1',
304
+ publishAt: @publish_at
305
+ },
306
+ relationships: {
307
+ author: {
308
+ data: { id: '1', type: 'authors' }
309
+ },
310
+ comments: {
311
+ data: [
312
+ { id: '7', type: 'comments' },
313
+ { id: '12', type: 'comments' }
314
+ ]
315
+ }
316
+ },
317
+ links: {
318
+ self: 'http://example.com/posts/1337',
319
+ postAuthors: 'http://example.com/posts/1337/authors',
320
+ subscriberComments: 'http://example.com/posts/1337/comments'
321
+ },
322
+ meta: { rating: 5, favoriteCount: 10 }
323
+ }
324
+ }, result)
317
325
  end
318
326
 
319
327
  def test_error_document_transform_default
@@ -324,18 +332,18 @@ module ActiveModelSerializers
324
332
  serializer = ActiveModel::Serializer::ErrorSerializer.new(resource)
325
333
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
326
334
  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
- }
335
+ expected_errors_object = {
336
+ errors: [
337
+ {
338
+ source: { pointer: '/data/attributes/published-at' },
339
+ detail: 'must be in the future'
340
+ },
341
+ {
342
+ source: { pointer: '/data/attributes/title' },
343
+ detail: 'must be longer'
344
+ }
345
+ ]
346
+ }
339
347
  assert_equal expected_errors_object, result
340
348
  end
341
349
 
@@ -349,19 +357,18 @@ module ActiveModelSerializers
349
357
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
350
358
  adapter.serializable_hash
351
359
  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
- }
360
+ expected_errors_object = {
361
+ Errors: [
362
+ {
363
+ Source: { Pointer: '/data/attributes/PublishedAt' },
364
+ Detail: 'must be in the future'
365
+ },
366
+ {
367
+ Source: { Pointer: '/data/attributes/Title' },
368
+ Detail: 'must be longer'
369
+ }
370
+ ]
371
+ }
365
372
  assert_equal expected_errors_object, result
366
373
  end
367
374
 
@@ -375,19 +382,18 @@ module ActiveModelSerializers
375
382
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
376
383
  adapter.serializable_hash
377
384
  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
- }
385
+ expected_errors_object = {
386
+ Errors: [
387
+ {
388
+ Source: { Pointer: '/data/attributes/PublishedAt' },
389
+ Detail: 'must be in the future'
390
+ },
391
+ {
392
+ Source: { Pointer: '/data/attributes/Title' },
393
+ Detail: 'must be longer'
394
+ }
395
+ ]
396
+ }
391
397
  assert_equal expected_errors_object, result
392
398
  end
393
399
 
@@ -402,18 +408,17 @@ module ActiveModelSerializers
402
408
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
403
409
  result = adapter.serializable_hash
404
410
 
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
- ]
411
+ expected_errors_object = {
412
+ errors: [
413
+ {
414
+ source: { pointer: '/data/attributes/published-at' },
415
+ detail: 'must be in the future'
416
+ },
417
+ {
418
+ source: { pointer: '/data/attributes/title' },
419
+ detail: 'must be longer'
420
+ }
421
+ ]
417
422
  }
418
423
  assert_equal expected_errors_object, result
419
424
  end
@@ -429,12 +434,11 @@ module ActiveModelSerializers
429
434
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
430
435
  result = adapter.serializable_hash
431
436
 
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
- ]
437
+ expected_errors_object = {
438
+ errors: [
439
+ { source: { pointer: '/data/attributes/published_at' }, detail: 'must be in the future' },
440
+ { source: { pointer: '/data/attributes/title' }, detail: 'must be longer' }
441
+ ]
438
442
  }
439
443
  assert_equal expected_errors_object, result
440
444
  end
@@ -466,12 +470,11 @@ module ActiveModelSerializers
466
470
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
467
471
  result = adapter.serializable_hash
468
472
 
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
- ]
473
+ expected_errors_object = {
474
+ Errors: [
475
+ { Source: { Pointer: '/data/attributes/PublishedAt' }, Detail: 'must be in the future' },
476
+ { Source: { Pointer: '/data/attributes/Title' }, Detail: 'must be longer' }
477
+ ]
475
478
  }
476
479
  assert_equal expected_errors_object, result
477
480
  end
@@ -487,12 +490,11 @@ module ActiveModelSerializers
487
490
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
488
491
  result = adapter.serializable_hash
489
492
 
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
- ]
493
+ expected_errors_object = {
494
+ errors: [
495
+ { source: { pointer: '/data/attributes/publishedAt' }, detail: 'must be in the future' },
496
+ { source: { pointer: '/data/attributes/title' }, detail: 'must be longer' }
497
+ ]
496
498
  }
497
499
  assert_equal expected_errors_object, result
498
500
  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