active_model_serializers 0.10.0 → 0.10.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -5
- data/.travis.yml +17 -5
- data/CHANGELOG.md +126 -2
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -2
- data/README.md +166 -26
- data/Rakefile +3 -32
- data/active_model_serializers.gemspec +22 -25
- data/appveyor.yml +9 -3
- data/bin/rubocop +38 -0
- data/docs/README.md +2 -1
- data/docs/general/adapters.md +29 -11
- 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/getting_started.md +1 -1
- data/docs/general/logging.md +7 -0
- data/docs/general/rendering.md +62 -24
- data/docs/general/serializers.md +121 -13
- data/docs/howto/add_pagination_links.md +16 -17
- data/docs/howto/add_relationship_links.md +140 -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 +12 -4
- data/docs/howto/passing_arbitrary_options.md +2 -2
- data/docs/howto/serialize_poro.md +46 -5
- 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 +67 -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 +62 -10
- data/lib/active_model/serializer/belongs_to_reflection.rb +4 -3
- data/lib/active_model/serializer/collection_serializer.rb +35 -12
- data/lib/active_model/serializer/{caching.rb → concerns/caching.rb} +82 -115
- 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 +3 -3
- data/lib/active_model/serializer/has_one_reflection.rb +1 -4
- data/lib/active_model/serializer/lazy_association.rb +95 -0
- data/lib/active_model/serializer/lint.rb +134 -130
- data/lib/active_model/serializer/reflection.rb +127 -67
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model/serializer.rb +296 -79
- data/lib/active_model_serializers/adapter/attributes.rb +3 -66
- data/lib/active_model_serializers/adapter/base.rb +39 -39
- data/lib/active_model_serializers/adapter/json_api/deserialization.rb +1 -1
- 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 +63 -23
- data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +32 -9
- data/lib/active_model_serializers/adapter/json_api.rb +71 -57
- 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/lookup_chain.rb +80 -0
- data/lib/active_model_serializers/model.rb +109 -28
- 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/test/schema.rb +2 -2
- data/lib/active_model_serializers.rb +15 -0
- data/lib/generators/rails/resource_override.rb +1 -1
- 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/lib/tasks/rubocop.rake +53 -0
- data/test/action_controller/adapter_selector_test.rb +14 -5
- 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 +8 -9
- data/test/action_controller/json_api/fields_test.rb +66 -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 +11 -3
- data/test/action_controller/lookup_proc_test.rb +49 -0
- data/test/action_controller/namespace_lookup_test.rb +232 -0
- data/test/action_controller/serialization_scope_name_test.rb +12 -6
- data/test/action_controller/serialization_test.rb +12 -9
- data/test/active_model_serializers/json_pointer_test.rb +15 -13
- data/test/active_model_serializers/model_test.rb +137 -4
- data/test/active_model_serializers/railtie_test_isolated.rb +12 -7
- data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +161 -0
- data/test/active_model_serializers/serialization_context_test_isolated.rb +23 -10
- data/test/active_model_serializers/test/schema_test.rb +3 -2
- data/test/adapter/attributes_test.rb +40 -0
- data/test/adapter/json/collection_test.rb +14 -0
- data/test/adapter/json/has_many_test.rb +10 -2
- 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 +12 -3
- data/test/adapter/json_api/has_many_test.rb +49 -20
- data/test/adapter/json_api/include_data_if_sideloaded_test.rb +183 -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 +263 -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 +21 -10
- data/test/benchmark/controllers.rb +16 -17
- data/test/benchmark/fixtures.rb +72 -72
- data/test/cache_test.rb +235 -69
- data/test/collection_serializer_test.rb +25 -12
- data/test/fixtures/active_record.rb +45 -10
- data/test/fixtures/poro.rb +124 -181
- data/test/generators/serializer_generator_test.rb +23 -5
- data/test/grape_test.rb +170 -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 +178 -49
- data/test/serializers/attribute_test.rb +5 -3
- data/test/serializers/attributes_test.rb +1 -1
- data/test/serializers/caching_configuration_test_isolated.rb +6 -6
- data/test/serializers/fieldset_test.rb +1 -1
- data/test/serializers/meta_test.rb +12 -6
- data/test/serializers/options_test.rb +17 -6
- data/test/serializers/read_attribute_for_serialization_test.rb +3 -3
- data/test/serializers/reflection_test.rb +427 -0
- data/test/serializers/root_test.rb +1 -1
- data/test/serializers/serialization_test.rb +2 -2
- data/test/serializers/serializer_for_test.rb +12 -10
- data/test/serializers/serializer_for_with_namespace_test.rb +88 -0
- data/test/support/isolated_unit.rb +5 -2
- data/test/support/rails5_shims.rb +8 -2
- data/test/support/rails_app.rb +2 -9
- data/test/support/serialization_testing.rb +23 -5
- data/test/test_helper.rb +13 -0
- metadata +105 -42
- data/.rubocop_todo.yml +0 -167
- data/docs/ARCHITECTURE.md +0 -126
- data/lib/active_model/serializer/associations.rb +0 -100
- data/lib/active_model/serializer/attributes.rb +0 -82
- data/lib/active_model/serializer/collection_reflection.rb +0 -7
- data/lib/active_model/serializer/configuration.rb +0 -35
- data/lib/active_model/serializer/include_tree.rb +0 -111
- data/lib/active_model/serializer/links.rb +0 -35
- data/lib/active_model/serializer/meta.rb +0 -29
- data/lib/active_model/serializer/singular_reflection.rb +0 -7
- data/lib/active_model/serializer/type.rb +0 -25
- data/lib/active_model_serializers/key_transform.rb +0 -70
- data/test/active_model_serializers/key_transform_test.rb +0 -263
- 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,18 @@ module ActiveModelSerializers
|
|
4
4
|
module Adapter
|
5
5
|
class JsonApi
|
6
6
|
class KeyCaseTest < ActiveSupport::TestCase
|
7
|
-
Post
|
7
|
+
class Post < ::Model
|
8
|
+
attributes :title, :body, :publish_at
|
9
|
+
associations :author, :comments
|
10
|
+
end
|
11
|
+
class Author < ::Model
|
12
|
+
attributes :first_name, :last_name
|
13
|
+
end
|
14
|
+
class Comment < ::Model
|
15
|
+
attributes :body
|
16
|
+
associations :author, :post
|
17
|
+
end
|
18
|
+
|
8
19
|
class PostSerializer < ActiveModel::Serializer
|
9
20
|
type 'posts'
|
10
21
|
attributes :title, :body, :publish_at
|
@@ -23,13 +34,11 @@ module ActiveModelSerializers
|
|
23
34
|
end
|
24
35
|
end
|
25
36
|
|
26
|
-
Author = Class.new(::Model)
|
27
37
|
class AuthorSerializer < ActiveModel::Serializer
|
28
38
|
type 'authors'
|
29
39
|
attributes :first_name, :last_name
|
30
40
|
end
|
31
41
|
|
32
|
-
Comment = Class.new(::Model)
|
33
42
|
class CommentSerializer < ActiveModel::Serializer
|
34
43
|
type 'comments'
|
35
44
|
attributes :body
|
@@ -70,32 +79,33 @@ module ActiveModelSerializers
|
|
70
79
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
71
80
|
result = adapter.serializable_hash
|
72
81
|
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
|
-
|
82
|
+
data: {
|
83
|
+
id: '1337',
|
84
|
+
type: 'posts',
|
85
|
+
attributes: {
|
86
|
+
title: 'Title 1',
|
87
|
+
body: 'Body 1',
|
88
|
+
:"publish-at" => @publish_at
|
89
|
+
},
|
90
|
+
relationships: {
|
91
|
+
author: {
|
92
|
+
data: { id: '1', type: 'authors' }
|
93
|
+
},
|
94
|
+
comments: {
|
95
|
+
data: [
|
96
|
+
{ id: '7', type: 'comments' },
|
97
|
+
{ id: '12', type: 'comments' }
|
98
|
+
]
|
99
|
+
}
|
100
|
+
},
|
101
|
+
links: {
|
102
|
+
self: 'http://example.com/posts/1337',
|
103
|
+
:"post-authors" => 'http://example.com/posts/1337/authors',
|
104
|
+
:"subscriber-comments" => 'http://example.com/posts/1337/comments'
|
105
|
+
},
|
106
|
+
meta: { rating: 5, :"favorite-count" => 10 }
|
107
|
+
}
|
108
|
+
}, result)
|
99
109
|
end
|
100
110
|
|
101
111
|
def test_success_document_transform_global_config
|
@@ -106,32 +116,33 @@ module ActiveModelSerializers
|
|
106
116
|
adapter.serializable_hash
|
107
117
|
end
|
108
118
|
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
|
-
|
119
|
+
data: {
|
120
|
+
id: '1337',
|
121
|
+
type: 'posts',
|
122
|
+
attributes: {
|
123
|
+
title: 'Title 1',
|
124
|
+
body: 'Body 1',
|
125
|
+
publishAt: @publish_at
|
126
|
+
},
|
127
|
+
relationships: {
|
128
|
+
author: {
|
129
|
+
data: { id: '1', type: 'authors' }
|
130
|
+
},
|
131
|
+
comments: {
|
132
|
+
data: [
|
133
|
+
{ id: '7', type: 'comments' },
|
134
|
+
{ id: '12', type: 'comments' }
|
135
|
+
]
|
136
|
+
}
|
137
|
+
},
|
138
|
+
links: {
|
139
|
+
self: 'http://example.com/posts/1337',
|
140
|
+
postAuthors: 'http://example.com/posts/1337/authors',
|
141
|
+
subscriberComments: 'http://example.com/posts/1337/comments'
|
142
|
+
},
|
143
|
+
meta: { rating: 5, favoriteCount: 10 }
|
144
|
+
}
|
145
|
+
}, result)
|
135
146
|
end
|
136
147
|
|
137
148
|
def test_success_doc_transform_serialization_ctx_overrides_global
|
@@ -142,32 +153,33 @@ module ActiveModelSerializers
|
|
142
153
|
adapter.serializable_hash
|
143
154
|
end
|
144
155
|
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
|
-
|
156
|
+
Data: {
|
157
|
+
Id: '1337',
|
158
|
+
Type: 'Posts',
|
159
|
+
Attributes: {
|
160
|
+
Title: 'Title 1',
|
161
|
+
Body: 'Body 1',
|
162
|
+
PublishAt: @publish_at
|
163
|
+
},
|
164
|
+
Relationships: {
|
165
|
+
Author: {
|
166
|
+
Data: { Id: '1', Type: 'Authors' }
|
167
|
+
},
|
168
|
+
Comments: {
|
169
|
+
Data: [
|
170
|
+
{ Id: '7', Type: 'Comments' },
|
171
|
+
{ Id: '12', Type: 'Comments' }
|
172
|
+
]
|
173
|
+
}
|
174
|
+
},
|
175
|
+
Links: {
|
176
|
+
Self: 'http://example.com/posts/1337',
|
177
|
+
PostAuthors: 'http://example.com/posts/1337/authors',
|
178
|
+
SubscriberComments: 'http://example.com/posts/1337/comments'
|
179
|
+
},
|
180
|
+
Meta: { Rating: 5, FavoriteCount: 10 }
|
181
|
+
}
|
182
|
+
}, result)
|
171
183
|
end
|
172
184
|
|
173
185
|
def test_success_document_transform_dash
|
@@ -176,32 +188,33 @@ module ActiveModelSerializers
|
|
176
188
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
177
189
|
result = adapter.serializable_hash
|
178
190
|
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
|
-
|
191
|
+
data: {
|
192
|
+
id: '1337',
|
193
|
+
type: 'posts',
|
194
|
+
attributes: {
|
195
|
+
title: 'Title 1',
|
196
|
+
body: 'Body 1',
|
197
|
+
:"publish-at" => @publish_at
|
198
|
+
},
|
199
|
+
relationships: {
|
200
|
+
author: {
|
201
|
+
data: { id: '1', type: 'authors' }
|
202
|
+
},
|
203
|
+
comments: {
|
204
|
+
data: [
|
205
|
+
{ id: '7', type: 'comments' },
|
206
|
+
{ id: '12', type: 'comments' }
|
207
|
+
]
|
208
|
+
}
|
209
|
+
},
|
210
|
+
links: {
|
211
|
+
self: 'http://example.com/posts/1337',
|
212
|
+
:"post-authors" => 'http://example.com/posts/1337/authors',
|
213
|
+
:"subscriber-comments" => 'http://example.com/posts/1337/comments'
|
214
|
+
},
|
215
|
+
meta: { rating: 5, :"favorite-count" => 10 }
|
216
|
+
}
|
217
|
+
}, result)
|
205
218
|
end
|
206
219
|
|
207
220
|
def test_success_document_transform_unaltered
|
@@ -210,32 +223,33 @@ module ActiveModelSerializers
|
|
210
223
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
211
224
|
result = adapter.serializable_hash
|
212
225
|
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
|
-
|
226
|
+
data: {
|
227
|
+
id: '1337',
|
228
|
+
type: 'posts',
|
229
|
+
attributes: {
|
230
|
+
title: 'Title 1',
|
231
|
+
body: 'Body 1',
|
232
|
+
publish_at: @publish_at
|
233
|
+
},
|
234
|
+
relationships: {
|
235
|
+
author: {
|
236
|
+
data: { id: '1', type: 'authors' }
|
237
|
+
},
|
238
|
+
comments: {
|
239
|
+
data: [
|
240
|
+
{ id: '7', type: 'comments' },
|
241
|
+
{ id: '12', type: 'comments' }
|
242
|
+
]
|
243
|
+
}
|
244
|
+
},
|
245
|
+
links: {
|
246
|
+
self: 'http://example.com/posts/1337',
|
247
|
+
post_authors: 'http://example.com/posts/1337/authors',
|
248
|
+
subscriber_comments: 'http://example.com/posts/1337/comments'
|
249
|
+
},
|
250
|
+
meta: { rating: 5, favorite_count: 10 }
|
251
|
+
}
|
252
|
+
}, result)
|
239
253
|
end
|
240
254
|
|
241
255
|
def test_success_document_transform_undefined
|
@@ -254,32 +268,33 @@ module ActiveModelSerializers
|
|
254
268
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
255
269
|
result = adapter.serializable_hash
|
256
270
|
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
|
-
|
271
|
+
Data: {
|
272
|
+
Id: '1337',
|
273
|
+
Type: 'Posts',
|
274
|
+
Attributes: {
|
275
|
+
Title: 'Title 1',
|
276
|
+
Body: 'Body 1',
|
277
|
+
PublishAt: @publish_at
|
278
|
+
},
|
279
|
+
Relationships: {
|
280
|
+
Author: {
|
281
|
+
Data: { Id: '1', Type: 'Authors' }
|
282
|
+
},
|
283
|
+
Comments: {
|
284
|
+
Data: [
|
285
|
+
{ Id: '7', Type: 'Comments' },
|
286
|
+
{ Id: '12', Type: 'Comments' }
|
287
|
+
]
|
288
|
+
}
|
289
|
+
},
|
290
|
+
Links: {
|
291
|
+
Self: 'http://example.com/posts/1337',
|
292
|
+
PostAuthors: 'http://example.com/posts/1337/authors',
|
293
|
+
SubscriberComments: 'http://example.com/posts/1337/comments'
|
294
|
+
},
|
295
|
+
Meta: { Rating: 5, FavoriteCount: 10 }
|
296
|
+
}
|
297
|
+
}, result)
|
283
298
|
end
|
284
299
|
|
285
300
|
def test_success_document_transform_camel_lower
|
@@ -288,32 +303,33 @@ module ActiveModelSerializers
|
|
288
303
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
289
304
|
result = adapter.serializable_hash
|
290
305
|
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
|
-
|
306
|
+
data: {
|
307
|
+
id: '1337',
|
308
|
+
type: 'posts',
|
309
|
+
attributes: {
|
310
|
+
title: 'Title 1',
|
311
|
+
body: 'Body 1',
|
312
|
+
publishAt: @publish_at
|
313
|
+
},
|
314
|
+
relationships: {
|
315
|
+
author: {
|
316
|
+
data: { id: '1', type: 'authors' }
|
317
|
+
},
|
318
|
+
comments: {
|
319
|
+
data: [
|
320
|
+
{ id: '7', type: 'comments' },
|
321
|
+
{ id: '12', type: 'comments' }
|
322
|
+
]
|
323
|
+
}
|
324
|
+
},
|
325
|
+
links: {
|
326
|
+
self: 'http://example.com/posts/1337',
|
327
|
+
postAuthors: 'http://example.com/posts/1337/authors',
|
328
|
+
subscriberComments: 'http://example.com/posts/1337/comments'
|
329
|
+
},
|
330
|
+
meta: { rating: 5, favoriteCount: 10 }
|
331
|
+
}
|
332
|
+
}, result)
|
317
333
|
end
|
318
334
|
|
319
335
|
def test_error_document_transform_default
|
@@ -324,18 +340,18 @@ module ActiveModelSerializers
|
|
324
340
|
serializer = ActiveModel::Serializer::ErrorSerializer.new(resource)
|
325
341
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
326
342
|
result = adapter.serializable_hash
|
327
|
-
expected_errors_object =
|
328
|
-
|
329
|
-
|
330
|
-
{
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
343
|
+
expected_errors_object = {
|
344
|
+
errors: [
|
345
|
+
{
|
346
|
+
source: { pointer: '/data/attributes/published-at' },
|
347
|
+
detail: 'must be in the future'
|
348
|
+
},
|
349
|
+
{
|
350
|
+
source: { pointer: '/data/attributes/title' },
|
351
|
+
detail: 'must be longer'
|
352
|
+
}
|
353
|
+
]
|
354
|
+
}
|
339
355
|
assert_equal expected_errors_object, result
|
340
356
|
end
|
341
357
|
|
@@ -349,19 +365,18 @@ module ActiveModelSerializers
|
|
349
365
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
350
366
|
adapter.serializable_hash
|
351
367
|
end
|
352
|
-
expected_errors_object =
|
353
|
-
|
354
|
-
|
355
|
-
{
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
{
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
}
|
368
|
+
expected_errors_object = {
|
369
|
+
Errors: [
|
370
|
+
{
|
371
|
+
Source: { Pointer: '/data/attributes/PublishedAt' },
|
372
|
+
Detail: 'must be in the future'
|
373
|
+
},
|
374
|
+
{
|
375
|
+
Source: { Pointer: '/data/attributes/Title' },
|
376
|
+
Detail: 'must be longer'
|
377
|
+
}
|
378
|
+
]
|
379
|
+
}
|
365
380
|
assert_equal expected_errors_object, result
|
366
381
|
end
|
367
382
|
|
@@ -375,19 +390,18 @@ module ActiveModelSerializers
|
|
375
390
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
376
391
|
adapter.serializable_hash
|
377
392
|
end
|
378
|
-
expected_errors_object =
|
379
|
-
|
380
|
-
|
381
|
-
{
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
{
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
}
|
393
|
+
expected_errors_object = {
|
394
|
+
Errors: [
|
395
|
+
{
|
396
|
+
Source: { Pointer: '/data/attributes/PublishedAt' },
|
397
|
+
Detail: 'must be in the future'
|
398
|
+
},
|
399
|
+
{
|
400
|
+
Source: { Pointer: '/data/attributes/Title' },
|
401
|
+
Detail: 'must be longer'
|
402
|
+
}
|
403
|
+
]
|
404
|
+
}
|
391
405
|
assert_equal expected_errors_object, result
|
392
406
|
end
|
393
407
|
|
@@ -402,18 +416,17 @@ module ActiveModelSerializers
|
|
402
416
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
403
417
|
result = adapter.serializable_hash
|
404
418
|
|
405
|
-
expected_errors_object =
|
406
|
-
|
407
|
-
|
408
|
-
{
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
{
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
]
|
419
|
+
expected_errors_object = {
|
420
|
+
errors: [
|
421
|
+
{
|
422
|
+
source: { pointer: '/data/attributes/published-at' },
|
423
|
+
detail: 'must be in the future'
|
424
|
+
},
|
425
|
+
{
|
426
|
+
source: { pointer: '/data/attributes/title' },
|
427
|
+
detail: 'must be longer'
|
428
|
+
}
|
429
|
+
]
|
417
430
|
}
|
418
431
|
assert_equal expected_errors_object, result
|
419
432
|
end
|
@@ -429,12 +442,11 @@ module ActiveModelSerializers
|
|
429
442
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
430
443
|
result = adapter.serializable_hash
|
431
444
|
|
432
|
-
expected_errors_object =
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
]
|
445
|
+
expected_errors_object = {
|
446
|
+
errors: [
|
447
|
+
{ source: { pointer: '/data/attributes/published_at' }, detail: 'must be in the future' },
|
448
|
+
{ source: { pointer: '/data/attributes/title' }, detail: 'must be longer' }
|
449
|
+
]
|
438
450
|
}
|
439
451
|
assert_equal expected_errors_object, result
|
440
452
|
end
|
@@ -466,12 +478,11 @@ module ActiveModelSerializers
|
|
466
478
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
467
479
|
result = adapter.serializable_hash
|
468
480
|
|
469
|
-
expected_errors_object =
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
]
|
481
|
+
expected_errors_object = {
|
482
|
+
Errors: [
|
483
|
+
{ Source: { Pointer: '/data/attributes/PublishedAt' }, Detail: 'must be in the future' },
|
484
|
+
{ Source: { Pointer: '/data/attributes/Title' }, Detail: 'must be longer' }
|
485
|
+
]
|
475
486
|
}
|
476
487
|
assert_equal expected_errors_object, result
|
477
488
|
end
|
@@ -487,12 +498,11 @@ module ActiveModelSerializers
|
|
487
498
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
488
499
|
result = adapter.serializable_hash
|
489
500
|
|
490
|
-
expected_errors_object =
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
]
|
501
|
+
expected_errors_object = {
|
502
|
+
errors: [
|
503
|
+
{ source: { pointer: '/data/attributes/publishedAt' }, detail: 'must be in the future' },
|
504
|
+
{ source: { pointer: '/data/attributes/title' }, detail: 'must be longer' }
|
505
|
+
]
|
496
506
|
}
|
497
507
|
assert_equal expected_errors_object, result
|
498
508
|
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
|