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.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -5
  3. data/.travis.yml +17 -5
  4. data/CHANGELOG.md +126 -2
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +5 -2
  7. data/README.md +166 -26
  8. data/Rakefile +3 -32
  9. data/active_model_serializers.gemspec +22 -25
  10. data/appveyor.yml +9 -3
  11. data/bin/rubocop +38 -0
  12. data/docs/README.md +2 -1
  13. data/docs/general/adapters.md +29 -11
  14. data/docs/general/caching.md +7 -1
  15. data/docs/general/configuration_options.md +70 -1
  16. data/docs/general/deserialization.md +1 -1
  17. data/docs/general/fields.md +31 -0
  18. data/docs/general/getting_started.md +1 -1
  19. data/docs/general/logging.md +7 -0
  20. data/docs/general/rendering.md +62 -24
  21. data/docs/general/serializers.md +121 -13
  22. data/docs/howto/add_pagination_links.md +16 -17
  23. data/docs/howto/add_relationship_links.md +140 -0
  24. data/docs/howto/add_root_key.md +4 -0
  25. data/docs/howto/grape_integration.md +42 -0
  26. data/docs/howto/outside_controller_use.md +12 -4
  27. data/docs/howto/passing_arbitrary_options.md +2 -2
  28. data/docs/howto/serialize_poro.md +46 -5
  29. data/docs/howto/test.md +2 -0
  30. data/docs/howto/upgrade_from_0_8_to_0_10.md +265 -0
  31. data/docs/integrations/ember-and-json-api.md +67 -32
  32. data/docs/jsonapi/schema.md +1 -1
  33. data/lib/action_controller/serialization.rb +13 -3
  34. data/lib/active_model/serializer/adapter/base.rb +2 -0
  35. data/lib/active_model/serializer/array_serializer.rb +8 -5
  36. data/lib/active_model/serializer/association.rb +62 -10
  37. data/lib/active_model/serializer/belongs_to_reflection.rb +4 -3
  38. data/lib/active_model/serializer/collection_serializer.rb +35 -12
  39. data/lib/active_model/serializer/{caching.rb → concerns/caching.rb} +82 -115
  40. data/lib/active_model/serializer/error_serializer.rb +11 -7
  41. data/lib/active_model/serializer/errors_serializer.rb +25 -20
  42. data/lib/active_model/serializer/has_many_reflection.rb +3 -3
  43. data/lib/active_model/serializer/has_one_reflection.rb +1 -4
  44. data/lib/active_model/serializer/lazy_association.rb +95 -0
  45. data/lib/active_model/serializer/lint.rb +134 -130
  46. data/lib/active_model/serializer/reflection.rb +127 -67
  47. data/lib/active_model/serializer/version.rb +1 -1
  48. data/lib/active_model/serializer.rb +296 -79
  49. data/lib/active_model_serializers/adapter/attributes.rb +3 -66
  50. data/lib/active_model_serializers/adapter/base.rb +39 -39
  51. data/lib/active_model_serializers/adapter/json_api/deserialization.rb +1 -1
  52. data/lib/active_model_serializers/adapter/json_api/link.rb +1 -1
  53. data/lib/active_model_serializers/adapter/json_api/pagination_links.rb +8 -1
  54. data/lib/active_model_serializers/adapter/json_api/relationship.rb +63 -23
  55. data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +32 -9
  56. data/lib/active_model_serializers/adapter/json_api.rb +71 -57
  57. data/lib/active_model_serializers/adapter.rb +6 -0
  58. data/lib/active_model_serializers/deprecate.rb +1 -2
  59. data/lib/active_model_serializers/deserialization.rb +2 -0
  60. data/lib/active_model_serializers/lookup_chain.rb +80 -0
  61. data/lib/active_model_serializers/model.rb +109 -28
  62. data/lib/active_model_serializers/railtie.rb +3 -1
  63. data/lib/active_model_serializers/register_jsonapi_renderer.rb +44 -31
  64. data/lib/active_model_serializers/serializable_resource.rb +6 -5
  65. data/lib/active_model_serializers/serialization_context.rb +10 -3
  66. data/lib/active_model_serializers/test/schema.rb +2 -2
  67. data/lib/active_model_serializers.rb +15 -0
  68. data/lib/generators/rails/resource_override.rb +1 -1
  69. data/lib/generators/rails/serializer_generator.rb +4 -4
  70. data/lib/grape/active_model_serializers.rb +7 -5
  71. data/lib/grape/formatters/active_model_serializers.rb +19 -2
  72. data/lib/grape/helpers/active_model_serializers.rb +1 -0
  73. data/lib/tasks/rubocop.rake +53 -0
  74. data/test/action_controller/adapter_selector_test.rb +14 -5
  75. data/test/action_controller/explicit_serializer_test.rb +5 -4
  76. data/test/action_controller/json/include_test.rb +106 -27
  77. data/test/action_controller/json_api/errors_test.rb +8 -9
  78. data/test/action_controller/json_api/fields_test.rb +66 -0
  79. data/test/action_controller/json_api/linked_test.rb +29 -24
  80. data/test/action_controller/json_api/pagination_test.rb +19 -19
  81. data/test/action_controller/json_api/transform_test.rb +11 -3
  82. data/test/action_controller/lookup_proc_test.rb +49 -0
  83. data/test/action_controller/namespace_lookup_test.rb +232 -0
  84. data/test/action_controller/serialization_scope_name_test.rb +12 -6
  85. data/test/action_controller/serialization_test.rb +12 -9
  86. data/test/active_model_serializers/json_pointer_test.rb +15 -13
  87. data/test/active_model_serializers/model_test.rb +137 -4
  88. data/test/active_model_serializers/railtie_test_isolated.rb +12 -7
  89. data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +161 -0
  90. data/test/active_model_serializers/serialization_context_test_isolated.rb +23 -10
  91. data/test/active_model_serializers/test/schema_test.rb +3 -2
  92. data/test/adapter/attributes_test.rb +40 -0
  93. data/test/adapter/json/collection_test.rb +14 -0
  94. data/test/adapter/json/has_many_test.rb +10 -2
  95. data/test/adapter/json/transform_test.rb +15 -15
  96. data/test/adapter/json_api/collection_test.rb +4 -3
  97. data/test/adapter/json_api/errors_test.rb +17 -19
  98. data/test/adapter/json_api/fields_test.rb +12 -3
  99. data/test/adapter/json_api/has_many_test.rb +49 -20
  100. data/test/adapter/json_api/include_data_if_sideloaded_test.rb +183 -0
  101. data/test/adapter/json_api/json_api_test.rb +5 -7
  102. data/test/adapter/json_api/linked_test.rb +33 -12
  103. data/test/adapter/json_api/links_test.rb +4 -2
  104. data/test/adapter/json_api/pagination_links_test.rb +35 -8
  105. data/test/adapter/json_api/relationship_test.rb +309 -73
  106. data/test/adapter/json_api/resource_identifier_test.rb +27 -2
  107. data/test/adapter/json_api/resource_meta_test.rb +3 -3
  108. data/test/adapter/json_api/transform_test.rb +263 -253
  109. data/test/adapter/json_api/type_test.rb +1 -1
  110. data/test/adapter/json_test.rb +8 -7
  111. data/test/adapter/null_test.rb +1 -2
  112. data/test/adapter/polymorphic_test.rb +5 -5
  113. data/test/adapter_test.rb +1 -1
  114. data/test/benchmark/app.rb +1 -1
  115. data/test/benchmark/benchmarking_support.rb +1 -1
  116. data/test/benchmark/bm_active_record.rb +81 -0
  117. data/test/benchmark/bm_adapter.rb +38 -0
  118. data/test/benchmark/bm_caching.rb +16 -16
  119. data/test/benchmark/bm_lookup_chain.rb +83 -0
  120. data/test/benchmark/bm_transform.rb +21 -10
  121. data/test/benchmark/controllers.rb +16 -17
  122. data/test/benchmark/fixtures.rb +72 -72
  123. data/test/cache_test.rb +235 -69
  124. data/test/collection_serializer_test.rb +25 -12
  125. data/test/fixtures/active_record.rb +45 -10
  126. data/test/fixtures/poro.rb +124 -181
  127. data/test/generators/serializer_generator_test.rb +23 -5
  128. data/test/grape_test.rb +170 -56
  129. data/test/lint_test.rb +1 -1
  130. data/test/logger_test.rb +13 -11
  131. data/test/serializable_resource_test.rb +18 -22
  132. data/test/serializers/association_macros_test.rb +3 -2
  133. data/test/serializers/associations_test.rb +178 -49
  134. data/test/serializers/attribute_test.rb +5 -3
  135. data/test/serializers/attributes_test.rb +1 -1
  136. data/test/serializers/caching_configuration_test_isolated.rb +6 -6
  137. data/test/serializers/fieldset_test.rb +1 -1
  138. data/test/serializers/meta_test.rb +12 -6
  139. data/test/serializers/options_test.rb +17 -6
  140. data/test/serializers/read_attribute_for_serialization_test.rb +3 -3
  141. data/test/serializers/reflection_test.rb +427 -0
  142. data/test/serializers/root_test.rb +1 -1
  143. data/test/serializers/serialization_test.rb +2 -2
  144. data/test/serializers/serializer_for_test.rb +12 -10
  145. data/test/serializers/serializer_for_with_namespace_test.rb +88 -0
  146. data/test/support/isolated_unit.rb +5 -2
  147. data/test/support/rails5_shims.rb +8 -2
  148. data/test/support/rails_app.rb +2 -9
  149. data/test/support/serialization_testing.rb +23 -5
  150. data/test/test_helper.rb +13 -0
  151. metadata +105 -42
  152. data/.rubocop_todo.yml +0 -167
  153. data/docs/ARCHITECTURE.md +0 -126
  154. data/lib/active_model/serializer/associations.rb +0 -100
  155. data/lib/active_model/serializer/attributes.rb +0 -82
  156. data/lib/active_model/serializer/collection_reflection.rb +0 -7
  157. data/lib/active_model/serializer/configuration.rb +0 -35
  158. data/lib/active_model/serializer/include_tree.rb +0 -111
  159. data/lib/active_model/serializer/links.rb +0 -35
  160. data/lib/active_model/serializer/meta.rb +0 -29
  161. data/lib/active_model/serializer/singular_reflection.rb +0 -7
  162. data/lib/active_model/serializer/type.rb +0 -25
  163. data/lib/active_model_serializers/key_transform.rb +0 -70
  164. data/test/active_model_serializers/key_transform_test.rb +0 -263
  165. data/test/adapter/json_api/relationships_test.rb +0 -199
  166. data/test/include_tree/from_include_args_test.rb +0 -26
  167. data/test/include_tree/from_string_test.rb +0 -94
  168. 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 = Class.new(::Model)
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
- data: {
74
- id: '1337',
75
- type: 'posts',
76
- attributes: {
77
- title: 'Title 1',
78
- body: 'Body 1',
79
- :"publish-at" => @publish_at
80
- },
81
- relationships: {
82
- author: {
83
- data: { id: '1', type: 'authors' }
84
- },
85
- comments: {
86
- data: [
87
- { id: '7', type: 'comments' },
88
- { id: '12', type: 'comments' }
89
- ] }
90
- },
91
- links: {
92
- self: 'http://example.com/posts/1337',
93
- :"post-authors" => 'http://example.com/posts/1337/authors',
94
- :"subscriber-comments" => 'http://example.com/posts/1337/comments'
95
- },
96
- meta: { rating: 5, :"favorite-count" => 10 }
97
- }
98
- }, result)
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
- data: {
110
- id: '1337',
111
- type: 'posts',
112
- attributes: {
113
- title: 'Title 1',
114
- body: 'Body 1',
115
- publishAt: @publish_at
116
- },
117
- relationships: {
118
- author: {
119
- data: { id: '1', type: 'authors' }
120
- },
121
- comments: {
122
- data: [
123
- { id: '7', type: 'comments' },
124
- { id: '12', type: 'comments' }
125
- ] }
126
- },
127
- links: {
128
- self: 'http://example.com/posts/1337',
129
- postAuthors: 'http://example.com/posts/1337/authors',
130
- subscriberComments: 'http://example.com/posts/1337/comments'
131
- },
132
- meta: { rating: 5, favoriteCount: 10 }
133
- }
134
- }, result)
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
- Data: {
146
- Id: '1337',
147
- Type: 'Posts',
148
- Attributes: {
149
- Title: 'Title 1',
150
- Body: 'Body 1',
151
- PublishAt: @publish_at
152
- },
153
- Relationships: {
154
- Author: {
155
- Data: { Id: '1', Type: 'Authors' }
156
- },
157
- Comments: {
158
- Data: [
159
- { Id: '7', Type: 'Comments' },
160
- { Id: '12', Type: 'Comments' }
161
- ] }
162
- },
163
- Links: {
164
- Self: 'http://example.com/posts/1337',
165
- PostAuthors: 'http://example.com/posts/1337/authors',
166
- SubscriberComments: 'http://example.com/posts/1337/comments'
167
- },
168
- Meta: { Rating: 5, FavoriteCount: 10 }
169
- }
170
- }, result)
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
- data: {
180
- id: '1337',
181
- type: 'posts',
182
- attributes: {
183
- title: 'Title 1',
184
- body: 'Body 1',
185
- :"publish-at" => @publish_at
186
- },
187
- relationships: {
188
- author: {
189
- data: { id: '1', type: 'authors' }
190
- },
191
- comments: {
192
- data: [
193
- { id: '7', type: 'comments' },
194
- { id: '12', type: 'comments' }
195
- ] }
196
- },
197
- links: {
198
- self: 'http://example.com/posts/1337',
199
- :"post-authors" => 'http://example.com/posts/1337/authors',
200
- :"subscriber-comments" => 'http://example.com/posts/1337/comments'
201
- },
202
- meta: { rating: 5, :"favorite-count" => 10 }
203
- }
204
- }, result)
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
- data: {
214
- id: '1337',
215
- type: 'posts',
216
- attributes: {
217
- title: 'Title 1',
218
- body: 'Body 1',
219
- publish_at: @publish_at
220
- },
221
- relationships: {
222
- author: {
223
- data: { id: '1', type: 'authors' }
224
- },
225
- comments: {
226
- data: [
227
- { id: '7', type: 'comments' },
228
- { id: '12', type: 'comments' }
229
- ] }
230
- },
231
- links: {
232
- self: 'http://example.com/posts/1337',
233
- post_authors: 'http://example.com/posts/1337/authors',
234
- subscriber_comments: 'http://example.com/posts/1337/comments'
235
- },
236
- meta: { rating: 5, favorite_count: 10 }
237
- }
238
- }, result)
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
- Data: {
258
- Id: '1337',
259
- Type: 'Posts',
260
- Attributes: {
261
- Title: 'Title 1',
262
- Body: 'Body 1',
263
- PublishAt: @publish_at
264
- },
265
- Relationships: {
266
- Author: {
267
- Data: { Id: '1', Type: 'Authors' }
268
- },
269
- Comments: {
270
- Data: [
271
- { Id: '7', Type: 'Comments' },
272
- { Id: '12', Type: 'Comments' }
273
- ] }
274
- },
275
- Links: {
276
- Self: 'http://example.com/posts/1337',
277
- PostAuthors: 'http://example.com/posts/1337/authors',
278
- SubscriberComments: 'http://example.com/posts/1337/comments'
279
- },
280
- Meta: { Rating: 5, FavoriteCount: 10 }
281
- }
282
- }, result)
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
- data: {
292
- id: '1337',
293
- type: 'posts',
294
- attributes: {
295
- title: 'Title 1',
296
- body: 'Body 1',
297
- publishAt: @publish_at
298
- },
299
- relationships: {
300
- author: {
301
- data: { id: '1', type: 'authors' }
302
- },
303
- comments: {
304
- data: [
305
- { id: '7', type: 'comments' },
306
- { id: '12', type: 'comments' }
307
- ] }
308
- },
309
- links: {
310
- self: 'http://example.com/posts/1337',
311
- postAuthors: 'http://example.com/posts/1337/authors',
312
- subscriberComments: 'http://example.com/posts/1337/comments'
313
- },
314
- meta: { rating: 5, favoriteCount: 10 }
315
- }
316
- }, result)
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
- { :errors =>
329
- [
330
- {
331
- :source => { :pointer => '/data/attributes/published-at' },
332
- :detail => 'must be in the future' },
333
- {
334
- :source => { :pointer => '/data/attributes/title' },
335
- :detail => 'must be longer'
336
- }
337
- ]
338
- }
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
- { :Errors =>
354
- [
355
- {
356
- :Source => { :Pointer => '/data/attributes/PublishedAt' },
357
- :Detail => 'must be in the future'
358
- },
359
- {
360
- :Source => { :Pointer => '/data/attributes/Title' },
361
- :Detail => 'must be longer'
362
- }
363
- ]
364
- }
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
- { :Errors =>
380
- [
381
- {
382
- :Source => { :Pointer => '/data/attributes/PublishedAt' },
383
- :Detail => 'must be in the future'
384
- },
385
- {
386
- :Source => { :Pointer => '/data/attributes/Title' },
387
- :Detail => 'must be longer'
388
- }
389
- ]
390
- }
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
- { :errors =>
407
- [
408
- {
409
- :source => { :pointer => '/data/attributes/published-at' },
410
- :detail => 'must be in the future'
411
- },
412
- {
413
- :source => { :pointer => '/data/attributes/title' },
414
- :detail => 'must be longer'
415
- }
416
- ]
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
- { :errors =>
434
- [
435
- { :source => { :pointer => '/data/attributes/published_at' }, :detail => 'must be in the future' },
436
- { :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
437
- ]
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
- { :Errors =>
471
- [
472
- { :Source => { :Pointer => '/data/attributes/PublishedAt' }, :Detail => 'must be in the future' },
473
- { :Source => { :Pointer => '/data/attributes/Title' }, :Detail => 'must be longer' }
474
- ]
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
- { :errors =>
492
- [
493
- { :source => { :pointer => '/data/attributes/publishedAt' }, :detail => 'must be in the future' },
494
- { :source => { :pointer => '/data/attributes/title' }, :detail => 'must be longer' }
495
- ]
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 inflection
50
+ def with_jsonapi_resource_type(inflection)
51
51
  old_inflection = ActiveModelSerializers.config.jsonapi_resource_type
52
52
  ActiveModelSerializers.config.jsonapi_resource_type = inflection
53
53
  yield