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.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -4
- data/.travis.yml +9 -1
- data/CHANGELOG.md +81 -2
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -2
- data/README.md +24 -24
- data/Rakefile +3 -3
- data/active_model_serializers.gemspec +20 -24
- data/docs/ARCHITECTURE.md +6 -7
- data/docs/README.md +2 -0
- data/docs/general/adapters.md +4 -2
- data/docs/general/caching.md +7 -1
- data/docs/general/configuration_options.md +70 -1
- data/docs/general/deserialization.md +1 -1
- data/docs/general/fields.md +31 -0
- data/docs/general/rendering.md +42 -3
- data/docs/general/serializers.md +97 -8
- data/docs/howto/add_pagination_links.md +4 -5
- data/docs/howto/add_relationship_links.md +137 -0
- data/docs/howto/add_root_key.md +4 -0
- data/docs/howto/grape_integration.md +42 -0
- data/docs/howto/outside_controller_use.md +9 -2
- data/docs/howto/passing_arbitrary_options.md +2 -2
- data/docs/howto/test.md +2 -0
- data/docs/howto/upgrade_from_0_8_to_0_10.md +265 -0
- data/docs/integrations/ember-and-json-api.md +64 -32
- data/docs/jsonapi/schema.md +1 -1
- data/lib/action_controller/serialization.rb +13 -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/association.rb +19 -4
- data/lib/active_model/serializer/belongs_to_reflection.rb +0 -3
- data/lib/active_model/serializer/collection_serializer.rb +35 -12
- data/lib/active_model/serializer/{associations.rb → concerns/associations.rb} +13 -11
- data/lib/active_model/serializer/{attributes.rb → concerns/attributes.rb} +0 -0
- data/lib/active_model/serializer/{caching.rb → concerns/caching.rb} +72 -113
- data/lib/active_model/serializer/{configuration.rb → concerns/configuration.rb} +25 -1
- data/lib/active_model/serializer/{links.rb → concerns/links.rb} +0 -0
- data/lib/active_model/serializer/{meta.rb → concerns/meta.rb} +0 -0
- data/lib/active_model/serializer/{type.rb → concerns/type.rb} +0 -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 +37 -21
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model/serializer.rb +76 -37
- data/lib/active_model_serializers/adapter/attributes.rb +3 -66
- 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/relationship.rb +30 -19
- data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +23 -9
- data/lib/active_model_serializers/adapter/json_api.rb +44 -43
- 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/key_transform.rb +4 -0
- data/lib/active_model_serializers/lookup_chain.rb +80 -0
- data/lib/active_model_serializers/model.rb +4 -2
- 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/serializable_resource.rb +6 -5
- data/lib/active_model_serializers/serialization_context.rb +10 -3
- data/lib/active_model_serializers.rb +7 -0
- data/lib/generators/rails/serializer_generator.rb +4 -4
- 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/fields_test.rb +57 -0
- 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/json_api/transform_test.rb +3 -3
- data/test/action_controller/lookup_proc_test.rb +49 -0
- data/test/action_controller/namespace_lookup_test.rb +226 -0
- 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 +286 -252
- data/test/active_model_serializers/model_test.rb +17 -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/attributes_test.rb +43 -0
- data/test/adapter/json/collection_test.rb +14 -0
- data/test/adapter/json/transform_test.rb +15 -15
- 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/fields_test.rb +4 -3
- data/test/adapter/json_api/has_many_test.rb +39 -18
- data/test/adapter/json_api/include_data_if_sideloaded_test.rb +166 -0
- data/test/adapter/json_api/json_api_test.rb +5 -7
- data/test/adapter/json_api/linked_test.rb +33 -12
- data/test/adapter/json_api/links_test.rb +4 -2
- data/test/adapter/json_api/pagination_links_test.rb +35 -8
- data/test/adapter/json_api/relationship_test.rb +309 -73
- data/test/adapter/json_api/resource_identifier_test.rb +27 -2
- data/test/adapter/json_api/resource_meta_test.rb +3 -3
- data/test/adapter/json_api/transform_test.rb +255 -253
- 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/benchmarking_support.rb +1 -1
- data/test/benchmark/bm_active_record.rb +81 -0
- data/test/benchmark/bm_adapter.rb +38 -0
- data/test/benchmark/bm_caching.rb +16 -16
- data/test/benchmark/bm_lookup_chain.rb +83 -0
- 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 +143 -49
- data/test/collection_serializer_test.rb +3 -3
- data/test/fixtures/poro.rb +52 -48
- data/test/generators/serializer_generator_test.rb +22 -5
- 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/association_macros_test.rb +3 -2
- data/test/serializers/associations_test.rb +107 -32
- data/test/serializers/attribute_test.rb +2 -2
- 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 +6 -4
- data/test/serializers/serializer_for_with_namespace_test.rb +87 -0
- 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 +23 -5
- data/test/test_helper.rb +1 -0
- metadata +85 -34
- data/.rubocop_todo.yml +0 -167
- data/lib/active_model/serializer/include_tree.rb +0 -111
- data/test/adapter/json_api/relationships_test.rb +0 -199
- 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
@@ -4,7 +4,10 @@ module ActiveModelSerializers
|
|
4
4
|
module Adapter
|
5
5
|
class JsonApi
|
6
6
|
class KeyCaseTest < ActiveSupport::TestCase
|
7
|
-
Post
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
329
|
-
|
330
|
-
{
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
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
|
-
|
354
|
-
|
355
|
-
{
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
{
|
360
|
-
|
361
|
-
|
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
|
-
|
380
|
-
|
381
|
-
{
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
{
|
386
|
-
|
387
|
-
|
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
|
-
|
407
|
-
|
408
|
-
{
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
{
|
413
|
-
|
414
|
-
|
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
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
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
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
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
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
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
|
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
|