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