active_model_serializers 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -2
- data/Gemfile +1 -1
- data/README.md +21 -24
- data/active_model_serializers.gemspec +4 -8
- data/docs/general/adapters.md +4 -2
- data/docs/general/configuration_options.md +6 -1
- data/docs/general/deserialization.md +1 -1
- data/docs/general/serializers.md +30 -3
- data/docs/jsonapi/schema.md +1 -1
- data/lib/active_model/serializer.rb +54 -11
- data/lib/active_model/serializer/adapter/base.rb +2 -0
- data/lib/active_model/serializer/associations.rb +4 -5
- data/lib/active_model/serializer/belongs_to_reflection.rb +0 -3
- data/lib/active_model/serializer/caching.rb +62 -110
- data/lib/active_model/serializer/collection_serializer.rb +30 -10
- data/lib/active_model/serializer/configuration.rb +1 -0
- 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/reflection.rb +3 -3
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model_serializers.rb +6 -0
- data/lib/active_model_serializers/adapter.rb +6 -0
- data/lib/active_model_serializers/adapter/attributes.rb +2 -67
- data/lib/active_model_serializers/adapter/base.rb +38 -38
- data/lib/active_model_serializers/adapter/json_api.rb +36 -28
- 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/deprecate.rb +1 -2
- data/lib/active_model_serializers/deserialization.rb +2 -0
- data/lib/active_model_serializers/model.rb +2 -0
- data/lib/active_model_serializers/railtie.rb +2 -0
- data/lib/active_model_serializers/register_jsonapi_renderer.rb +34 -23
- data/lib/active_model_serializers/serialization_context.rb +10 -3
- 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 +1 -1
- 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 +2 -2
- data/test/action_controller/json_api/linked_test.rb +26 -21
- data/test/action_controller/serialization_test.rb +9 -6
- data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +143 -0
- data/test/active_model_serializers/serialization_context_test_isolated.rb +23 -10
- data/test/adapter/json/collection_test.rb +14 -0
- data/test/adapter/json_api/collection_test.rb +4 -3
- data/test/adapter/json_api/errors_test.rb +13 -15
- data/test/adapter/json_api/linked_test.rb +8 -5
- data/test/adapter/json_api/links_test.rb +3 -1
- data/test/adapter/json_api/pagination_links_test.rb +13 -1
- data/test/adapter/json_api/relationships_test.rb +9 -4
- data/test/adapter/json_api/resource_identifier_test.rb +7 -2
- data/test/adapter/json_api/transform_test.rb +76 -75
- data/test/adapter/json_test.rb +4 -3
- data/test/benchmark/app.rb +1 -1
- data/test/benchmark/bm_caching.rb +14 -14
- 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 +73 -45
- data/test/fixtures/poro.rb +6 -5
- data/test/grape_test.rb +96 -2
- data/test/serializable_resource_test.rb +12 -12
- data/test/serializers/meta_test.rb +12 -6
- data/test/support/isolated_unit.rb +1 -0
- data/test/support/rails5_shims.rb +8 -2
- data/test/support/rails_app.rb +0 -9
- metadata +53 -23
- data/lib/active_model/serializer/include_tree.rb +0 -111
- data/test/include_tree/from_include_args_test.rb +0 -26
- data/test/include_tree/from_string_test.rb +0 -94
- data/test/include_tree/include_args_to_hash_test.rb +0 -64
@@ -5,13 +5,19 @@ require 'minitest/mock'
|
|
5
5
|
class SerializationContextTest < ActiveSupport::TestCase
|
6
6
|
include ActiveSupport::Testing::Isolation
|
7
7
|
|
8
|
-
def create_request
|
9
|
-
request = Minitest::Mock.new
|
10
|
-
request.expect(:original_url, 'original_url')
|
11
|
-
request.expect(:query_parameters, 'query_parameters')
|
12
|
-
end
|
13
|
-
|
14
8
|
class WithRails < SerializationContextTest
|
9
|
+
def create_request
|
10
|
+
request = ActionDispatch::Request.new({})
|
11
|
+
def request.original_url
|
12
|
+
'http://example.com/articles?page=2'
|
13
|
+
end
|
14
|
+
|
15
|
+
def request.query_parameters
|
16
|
+
{ 'page' => 2 }
|
17
|
+
end
|
18
|
+
request
|
19
|
+
end
|
20
|
+
|
15
21
|
setup do
|
16
22
|
require 'rails'
|
17
23
|
require 'active_model_serializers'
|
@@ -20,8 +26,8 @@ class SerializationContextTest < ActiveSupport::TestCase
|
|
20
26
|
end
|
21
27
|
|
22
28
|
test 'create context with request url and query parameters' do
|
23
|
-
assert_equal @context.request_url, '
|
24
|
-
assert_equal @context.query_parameters, '
|
29
|
+
assert_equal @context.request_url, 'http://example.com/articles'
|
30
|
+
assert_equal @context.query_parameters, 'page' => 2
|
25
31
|
end
|
26
32
|
|
27
33
|
test 'url_helpers is set up for Rails url_helpers' do
|
@@ -36,14 +42,21 @@ class SerializationContextTest < ActiveSupport::TestCase
|
|
36
42
|
end
|
37
43
|
|
38
44
|
class WithoutRails < SerializationContextTest
|
45
|
+
def create_request
|
46
|
+
{
|
47
|
+
request_url: 'http://example.com/articles',
|
48
|
+
query_parameters: { 'page' => 2 }
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
39
52
|
setup do
|
40
53
|
require 'active_model_serializers/serialization_context'
|
41
54
|
@context = ActiveModelSerializers::SerializationContext.new(create_request)
|
42
55
|
end
|
43
56
|
|
44
57
|
test 'create context with request url and query parameters' do
|
45
|
-
assert_equal @context.request_url, '
|
46
|
-
assert_equal @context.query_parameters, '
|
58
|
+
assert_equal @context.request_url, 'http://example.com/articles'
|
59
|
+
assert_equal @context.query_parameters, 'page' => 2
|
47
60
|
end
|
48
61
|
|
49
62
|
test 'url_helpers is a module when Rails is not present' do
|
@@ -84,6 +84,20 @@ module ActiveModelSerializers
|
|
84
84
|
|
85
85
|
assert_equal(expected, actual)
|
86
86
|
end
|
87
|
+
|
88
|
+
def test_fields_with_no_associations_include_option
|
89
|
+
actual = ActiveModelSerializers::SerializableResource.new(
|
90
|
+
[@first_post, @second_post], adapter: :json, fields: [:id], include: []
|
91
|
+
).as_json
|
92
|
+
|
93
|
+
expected = { posts: [{
|
94
|
+
id: 1
|
95
|
+
}, {
|
96
|
+
id: 2
|
97
|
+
}] }
|
98
|
+
|
99
|
+
assert_equal(expected, actual)
|
100
|
+
end
|
87
101
|
end
|
88
102
|
end
|
89
103
|
end
|
@@ -58,9 +58,10 @@ module ActiveModelSerializers
|
|
58
58
|
|
59
59
|
def test_limiting_fields
|
60
60
|
actual = ActiveModelSerializers::SerializableResource.new(
|
61
|
-
[@first_post, @second_post],
|
62
|
-
|
63
|
-
|
61
|
+
[@first_post, @second_post],
|
62
|
+
adapter: :json_api,
|
63
|
+
fields: { posts: %w(title comments blog author) }
|
64
|
+
).serializable_hash
|
64
65
|
expected = [
|
65
66
|
{
|
66
67
|
id: '1',
|
@@ -22,14 +22,13 @@ module ActiveModelSerializers
|
|
22
22
|
assert_equal serializable_resource.serializer_instance.attributes, {}
|
23
23
|
assert_equal serializable_resource.serializer_instance.object, @resource
|
24
24
|
|
25
|
-
expected_errors_object =
|
26
|
-
|
27
|
-
|
28
|
-
{
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
]
|
25
|
+
expected_errors_object = {
|
26
|
+
:errors => [
|
27
|
+
{
|
28
|
+
source: { pointer: '/data/attributes/name' },
|
29
|
+
detail: 'cannot be nil'
|
30
|
+
}
|
31
|
+
]
|
33
32
|
}
|
34
33
|
assert_equal serializable_resource.as_json, expected_errors_object
|
35
34
|
end
|
@@ -48,13 +47,12 @@ module ActiveModelSerializers
|
|
48
47
|
assert_equal serializable_resource.serializer_instance.attributes, {}
|
49
48
|
assert_equal serializable_resource.serializer_instance.object, @resource
|
50
49
|
|
51
|
-
expected_errors_object =
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
]
|
50
|
+
expected_errors_object = {
|
51
|
+
:errors => [
|
52
|
+
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'cannot be nil' },
|
53
|
+
{ :source => { :pointer => '/data/attributes/name' }, :detail => 'must be longer' },
|
54
|
+
{ :source => { :pointer => '/data/attributes/id' }, :detail => 'must be a uuid' }
|
55
|
+
]
|
58
56
|
}
|
59
57
|
assert_equal serializable_resource.as_json, expected_errors_object
|
60
58
|
end
|
@@ -341,9 +341,10 @@ module ActiveModelSerializers
|
|
341
341
|
|
342
342
|
def test_no_duplicates_collection
|
343
343
|
hash = ActiveModelSerializers::SerializableResource.new(
|
344
|
-
[@post1, @post2],
|
345
|
-
|
346
|
-
|
344
|
+
[@post1, @post2],
|
345
|
+
adapter: :json_api,
|
346
|
+
include: '*.*'
|
347
|
+
).serializable_hash
|
347
348
|
expected = [
|
348
349
|
{
|
349
350
|
type: 'authors', id: '1',
|
@@ -364,7 +365,8 @@ module ActiveModelSerializers
|
|
364
365
|
hash = ActiveModelSerializers::SerializableResource.new(
|
365
366
|
@nestedpost1,
|
366
367
|
adapter: :json_api,
|
367
|
-
include: '*'
|
368
|
+
include: '*'
|
369
|
+
).serializable_hash
|
368
370
|
expected = [
|
369
371
|
type: 'nested-posts', id: '2',
|
370
372
|
relationships: {
|
@@ -383,7 +385,8 @@ module ActiveModelSerializers
|
|
383
385
|
hash = ActiveModelSerializers::SerializableResource.new(
|
384
386
|
[@nestedpost1, @nestedpost2],
|
385
387
|
adapter: :json_api,
|
386
|
-
include: '*'
|
388
|
+
include: '*'
|
389
|
+
).serializable_hash
|
387
390
|
assert_nil(hash[:included])
|
388
391
|
end
|
389
392
|
end
|
@@ -17,6 +17,7 @@ module ActiveModelSerializers
|
|
17
17
|
link :yet_another do
|
18
18
|
"http://example.com/resource/#{object.id}"
|
19
19
|
end
|
20
|
+
link(:nil) { nil }
|
20
21
|
end
|
21
22
|
|
22
23
|
def setup
|
@@ -40,7 +41,8 @@ module ActiveModelSerializers
|
|
40
41
|
stuff: 'value'
|
41
42
|
}
|
42
43
|
}
|
43
|
-
}
|
44
|
+
}
|
45
|
+
).serializable_hash
|
44
46
|
expected = {
|
45
47
|
self: {
|
46
48
|
href: 'http://example.com/posts',
|
@@ -43,7 +43,8 @@ module ActiveModelSerializers
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def data
|
46
|
-
{
|
46
|
+
{
|
47
|
+
data: [
|
47
48
|
{ id: '1', type: 'profiles', attributes: { name: 'Name 1', description: 'Description 1' } },
|
48
49
|
{ id: '2', type: 'profiles', attributes: { name: 'Name 2', description: 'Description 2' } },
|
49
50
|
{ id: '3', type: 'profiles', attributes: { name: 'Name 3', description: 'Description 3' } },
|
@@ -160,6 +161,17 @@ module ActiveModelSerializers
|
|
160
161
|
|
161
162
|
assert_equal expected_response_without_pagination_links, adapter.serializable_hash
|
162
163
|
end
|
164
|
+
|
165
|
+
def test_raises_descriptive_error_when_serialization_context_unset
|
166
|
+
render_options = { adapter: :json_api }
|
167
|
+
adapter = serializable(using_kaminari, render_options)
|
168
|
+
exception = assert_raises do
|
169
|
+
adapter.as_json
|
170
|
+
end
|
171
|
+
exception_class = ActiveModelSerializers::Adapter::JsonApi::PaginationLinks::MissingSerializationContextError
|
172
|
+
assert_equal exception_class, exception.class
|
173
|
+
assert_match(/CollectionSerializer#paginated\?/, exception.message)
|
174
|
+
end
|
163
175
|
end
|
164
176
|
end
|
165
177
|
end
|
@@ -5,7 +5,8 @@ module ActiveModel
|
|
5
5
|
module Adapter
|
6
6
|
class JsonApi
|
7
7
|
class RelationshipTest < ActiveSupport::TestCase
|
8
|
-
RelationshipAuthor
|
8
|
+
class RelationshipAuthor < ::Model; end
|
9
|
+
|
9
10
|
class RelationshipAuthorSerializer < ActiveModel::Serializer
|
10
11
|
has_one :bio do
|
11
12
|
link :self, '//example.com/link_author/relationships/bio'
|
@@ -71,7 +72,6 @@ module ActiveModel
|
|
71
72
|
|
72
73
|
def setup
|
73
74
|
@post = Post.new(id: 1337, comments: [], author: nil)
|
74
|
-
@blog = Blog.new(id: 1337, name: 'extra')
|
75
75
|
@bio = Bio.new(id: 1337)
|
76
76
|
@like = Like.new(id: 1337)
|
77
77
|
@role = Role.new(id: 'from-record')
|
@@ -82,7 +82,6 @@ module ActiveModel
|
|
82
82
|
@author = RelationshipAuthor.new(
|
83
83
|
id: 1337,
|
84
84
|
posts: [@post],
|
85
|
-
blog: @blog,
|
86
85
|
reviewer: @reviewer,
|
87
86
|
bio: @bio,
|
88
87
|
likes: [@like],
|
@@ -158,10 +157,16 @@ module ActiveModel
|
|
158
157
|
end
|
159
158
|
|
160
159
|
def test_relationship_not_including_data
|
160
|
+
@author.define_singleton_method(:read_attribute_for_serialization) do |attr|
|
161
|
+
fail 'should not be called' if attr == :blog
|
162
|
+
super(attr)
|
163
|
+
end
|
161
164
|
expected = {
|
162
165
|
links: { self: '//example.com/link_author/relationships/blog' }
|
163
166
|
}
|
164
|
-
|
167
|
+
assert_nothing_raised do
|
168
|
+
assert_relationship(:blog, expected)
|
169
|
+
end
|
165
170
|
end
|
166
171
|
|
167
172
|
def test_relationship_including_data_explicit
|
@@ -14,7 +14,13 @@ module ActiveModelSerializers
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
class FragmentedSerializer < ActiveModel::Serializer
|
17
|
+
class FragmentedSerializer < ActiveModel::Serializer
|
18
|
+
cache only: :id
|
19
|
+
|
20
|
+
def id
|
21
|
+
'special_id'
|
22
|
+
end
|
23
|
+
end
|
18
24
|
|
19
25
|
setup do
|
20
26
|
@model = Author.new(id: 1, name: 'Steve K.')
|
@@ -42,7 +48,6 @@ module ActiveModelSerializers
|
|
42
48
|
end
|
43
49
|
|
44
50
|
def test_id_defined_on_fragmented
|
45
|
-
FragmentedSerializer.fragmented(WithDefinedIdSerializer.new(@model))
|
46
51
|
test_id(FragmentedSerializer, 'special_id')
|
47
52
|
end
|
48
53
|
|
@@ -86,7 +86,8 @@ module ActiveModelSerializers
|
|
86
86
|
data: [
|
87
87
|
{ id: '7', type: 'comments' },
|
88
88
|
{ id: '12', type: 'comments' }
|
89
|
-
|
89
|
+
]
|
90
|
+
}
|
90
91
|
},
|
91
92
|
links: {
|
92
93
|
self: 'http://example.com/posts/1337',
|
@@ -122,7 +123,8 @@ module ActiveModelSerializers
|
|
122
123
|
data: [
|
123
124
|
{ id: '7', type: 'comments' },
|
124
125
|
{ id: '12', type: 'comments' }
|
125
|
-
|
126
|
+
]
|
127
|
+
}
|
126
128
|
},
|
127
129
|
links: {
|
128
130
|
self: 'http://example.com/posts/1337',
|
@@ -158,7 +160,8 @@ module ActiveModelSerializers
|
|
158
160
|
Data: [
|
159
161
|
{ Id: '7', Type: 'Comments' },
|
160
162
|
{ Id: '12', Type: 'Comments' }
|
161
|
-
|
163
|
+
]
|
164
|
+
}
|
162
165
|
},
|
163
166
|
Links: {
|
164
167
|
Self: 'http://example.com/posts/1337',
|
@@ -192,7 +195,8 @@ module ActiveModelSerializers
|
|
192
195
|
data: [
|
193
196
|
{ id: '7', type: 'comments' },
|
194
197
|
{ id: '12', type: 'comments' }
|
195
|
-
|
198
|
+
]
|
199
|
+
}
|
196
200
|
},
|
197
201
|
links: {
|
198
202
|
self: 'http://example.com/posts/1337',
|
@@ -226,7 +230,8 @@ module ActiveModelSerializers
|
|
226
230
|
data: [
|
227
231
|
{ id: '7', type: 'comments' },
|
228
232
|
{ id: '12', type: 'comments' }
|
229
|
-
|
233
|
+
]
|
234
|
+
}
|
230
235
|
},
|
231
236
|
links: {
|
232
237
|
self: 'http://example.com/posts/1337',
|
@@ -270,7 +275,8 @@ module ActiveModelSerializers
|
|
270
275
|
Data: [
|
271
276
|
{ Id: '7', Type: 'Comments' },
|
272
277
|
{ Id: '12', Type: 'Comments' }
|
273
|
-
|
278
|
+
]
|
279
|
+
}
|
274
280
|
},
|
275
281
|
Links: {
|
276
282
|
Self: 'http://example.com/posts/1337',
|
@@ -304,7 +310,8 @@ module ActiveModelSerializers
|
|
304
310
|
data: [
|
305
311
|
{ id: '7', type: 'comments' },
|
306
312
|
{ id: '12', type: 'comments' }
|
307
|
-
|
313
|
+
]
|
314
|
+
}
|
308
315
|
},
|
309
316
|
links: {
|
310
317
|
self: 'http://example.com/posts/1337',
|
@@ -324,18 +331,18 @@ module ActiveModelSerializers
|
|
324
331
|
serializer = ActiveModel::Serializer::ErrorSerializer.new(resource)
|
325
332
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
326
333
|
result = adapter.serializable_hash
|
327
|
-
expected_errors_object =
|
328
|
-
|
329
|
-
|
330
|
-
{
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
334
|
+
expected_errors_object = {
|
335
|
+
:errors => [
|
336
|
+
{
|
337
|
+
:source => { :pointer => '/data/attributes/published-at' },
|
338
|
+
:detail => 'must be in the future'
|
339
|
+
},
|
340
|
+
{
|
341
|
+
:source => { :pointer => '/data/attributes/title' },
|
342
|
+
:detail => 'must be longer'
|
343
|
+
}
|
344
|
+
]
|
345
|
+
}
|
339
346
|
assert_equal expected_errors_object, result
|
340
347
|
end
|
341
348
|
|
@@ -349,19 +356,18 @@ module ActiveModelSerializers
|
|
349
356
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
350
357
|
adapter.serializable_hash
|
351
358
|
end
|
352
|
-
expected_errors_object =
|
353
|
-
|
354
|
-
|
355
|
-
{
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
{
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
}
|
359
|
+
expected_errors_object = {
|
360
|
+
:Errors => [
|
361
|
+
{
|
362
|
+
:Source => { :Pointer => '/data/attributes/PublishedAt' },
|
363
|
+
:Detail => 'must be in the future'
|
364
|
+
},
|
365
|
+
{
|
366
|
+
:Source => { :Pointer => '/data/attributes/Title' },
|
367
|
+
:Detail => 'must be longer'
|
368
|
+
}
|
369
|
+
]
|
370
|
+
}
|
365
371
|
assert_equal expected_errors_object, result
|
366
372
|
end
|
367
373
|
|
@@ -375,19 +381,18 @@ module ActiveModelSerializers
|
|
375
381
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
376
382
|
adapter.serializable_hash
|
377
383
|
end
|
378
|
-
expected_errors_object =
|
379
|
-
|
380
|
-
|
381
|
-
{
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
{
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
}
|
384
|
+
expected_errors_object = {
|
385
|
+
:Errors => [
|
386
|
+
{
|
387
|
+
:Source => { :Pointer => '/data/attributes/PublishedAt' },
|
388
|
+
:Detail => 'must be in the future'
|
389
|
+
},
|
390
|
+
{
|
391
|
+
:Source => { :Pointer => '/data/attributes/Title' },
|
392
|
+
:Detail => 'must be longer'
|
393
|
+
}
|
394
|
+
]
|
395
|
+
}
|
391
396
|
assert_equal expected_errors_object, result
|
392
397
|
end
|
393
398
|
|
@@ -402,18 +407,17 @@ module ActiveModelSerializers
|
|
402
407
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
403
408
|
result = adapter.serializable_hash
|
404
409
|
|
405
|
-
expected_errors_object =
|
406
|
-
|
407
|
-
|
408
|
-
{
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
{
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
]
|
410
|
+
expected_errors_object = {
|
411
|
+
:errors => [
|
412
|
+
{
|
413
|
+
:source => { :pointer => '/data/attributes/published-at' },
|
414
|
+
:detail => 'must be in the future'
|
415
|
+
},
|
416
|
+
{
|
417
|
+
:source => { :pointer => '/data/attributes/title' },
|
418
|
+
:detail => 'must be longer'
|
419
|
+
}
|
420
|
+
]
|
417
421
|
}
|
418
422
|
assert_equal expected_errors_object, result
|
419
423
|
end
|
@@ -429,12 +433,11 @@ module ActiveModelSerializers
|
|
429
433
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
430
434
|
result = adapter.serializable_hash
|
431
435
|
|
432
|
-
expected_errors_object =
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
]
|
436
|
+
expected_errors_object = {
|
437
|
+
:errors => [
|
438
|
+
{ :source => { :pointer => '/data/attributes/published_at' }, :detail => 'must be in the future' },
|
439
|
+
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
|
440
|
+
]
|
438
441
|
}
|
439
442
|
assert_equal expected_errors_object, result
|
440
443
|
end
|
@@ -466,12 +469,11 @@ module ActiveModelSerializers
|
|
466
469
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
467
470
|
result = adapter.serializable_hash
|
468
471
|
|
469
|
-
expected_errors_object =
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
]
|
472
|
+
expected_errors_object = {
|
473
|
+
:Errors => [
|
474
|
+
{ :Source => { :Pointer => '/data/attributes/PublishedAt' }, :Detail => 'must be in the future' },
|
475
|
+
{ :Source => { :Pointer => '/data/attributes/Title' }, :Detail => 'must be longer' }
|
476
|
+
]
|
475
477
|
}
|
476
478
|
assert_equal expected_errors_object, result
|
477
479
|
end
|
@@ -487,12 +489,11 @@ module ActiveModelSerializers
|
|
487
489
|
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
|
488
490
|
result = adapter.serializable_hash
|
489
491
|
|
490
|
-
expected_errors_object =
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
]
|
492
|
+
expected_errors_object = {
|
493
|
+
:errors => [
|
494
|
+
{ :source => { :pointer => '/data/attributes/publishedAt' }, :detail => 'must be in the future' },
|
495
|
+
{ :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
|
496
|
+
]
|
496
497
|
}
|
497
498
|
assert_equal expected_errors_object, result
|
498
499
|
end
|