active_model_serializers 0.10.1 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -4
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +9 -1
  5. data/Rakefile +3 -3
  6. data/active_model_serializers.gemspec +15 -15
  7. data/docs/general/fields.md +31 -0
  8. data/docs/general/rendering.md +7 -2
  9. data/docs/general/serializers.md +32 -0
  10. data/docs/howto/add_pagination_links.md +2 -3
  11. data/docs/integrations/ember-and-json-api.md +25 -10
  12. data/lib/action_controller/serialization.rb +4 -3
  13. data/lib/active_model/serializer.rb +3 -4
  14. data/lib/active_model/serializer/array_serializer.rb +8 -5
  15. data/lib/active_model/serializer/associations.rb +2 -2
  16. data/lib/active_model/serializer/caching.rb +11 -8
  17. data/lib/active_model/serializer/error_serializer.rb +11 -7
  18. data/lib/active_model/serializer/errors_serializer.rb +25 -20
  19. data/lib/active_model/serializer/lint.rb +134 -130
  20. data/lib/active_model/serializer/version.rb +1 -1
  21. data/lib/active_model_serializers/deprecate.rb +1 -1
  22. data/lib/active_model_serializers/model.rb +1 -1
  23. data/lib/active_model_serializers/railtie.rb +1 -1
  24. data/lib/active_model_serializers/register_jsonapi_renderer.rb +37 -35
  25. data/lib/generators/rails/serializer_generator.rb +3 -3
  26. data/lib/grape/active_model_serializers.rb +7 -5
  27. data/test/action_controller/adapter_selector_test.rb +3 -3
  28. data/test/action_controller/json_api/errors_test.rb +5 -6
  29. data/test/action_controller/json_api/linked_test.rb +4 -4
  30. data/test/action_controller/json_api/pagination_test.rb +19 -19
  31. data/test/action_controller/serialization_test.rb +1 -1
  32. data/test/active_model_serializers/json_pointer_test.rb +15 -13
  33. data/test/active_model_serializers/key_transform_test.rb +254 -252
  34. data/test/active_model_serializers/model_test.rb +6 -4
  35. data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +2 -2
  36. data/test/adapter/json/transform_test.rb +14 -14
  37. data/test/adapter/json_api/errors_test.rb +9 -9
  38. data/test/adapter/json_api/has_many_test.rb +18 -18
  39. data/test/adapter/json_api/json_api_test.rb +5 -7
  40. data/test/adapter/json_api/linked_test.rb +1 -1
  41. data/test/adapter/json_api/pagination_links_test.rb +6 -6
  42. data/test/adapter/json_api/resource_meta_test.rb +3 -3
  43. data/test/adapter/json_api/transform_test.rb +218 -218
  44. data/test/adapter/json_api/type_test.rb +1 -1
  45. data/test/adapter/json_test.rb +8 -8
  46. data/test/adapter/null_test.rb +1 -2
  47. data/test/adapter/polymorphic_test.rb +5 -5
  48. data/test/adapter_test.rb +1 -1
  49. data/test/benchmark/bm_caching.rb +1 -1
  50. data/test/cache_test.rb +29 -1
  51. data/test/collection_serializer_test.rb +2 -2
  52. data/test/fixtures/poro.rb +2 -2
  53. data/test/grape_test.rb +130 -128
  54. data/test/lint_test.rb +1 -1
  55. data/test/logger_test.rb +13 -11
  56. data/test/serializable_resource_test.rb +12 -16
  57. data/test/serializers/associations_test.rb +10 -10
  58. data/test/serializers/attribute_test.rb +1 -1
  59. data/test/serializers/attributes_test.rb +1 -1
  60. data/test/serializers/fieldset_test.rb +1 -1
  61. data/test/serializers/root_test.rb +1 -1
  62. data/test/serializers/serializer_for_test.rb +3 -1
  63. data/test/support/isolated_unit.rb +4 -2
  64. data/test/support/serialization_testing.rb +7 -5
  65. metadata +3 -3
  66. data/.rubocop_todo.yml +0 -167
@@ -1,9 +1,11 @@
1
1
  require 'test_helper'
2
2
 
3
- class ActiveModelSerializers::ModelTest < ActiveSupport::TestCase
4
- include ActiveModel::Serializer::Lint::Tests
3
+ module ActiveModelSerializers
4
+ class ModelTest < ActiveSupport::TestCase
5
+ include ActiveModel::Serializer::Lint::Tests
5
6
 
6
- def setup
7
- @resource = ActiveModelSerializers::Model.new
7
+ def setup
8
+ @resource = ActiveModelSerializers::Model.new
9
+ end
8
10
  end
9
11
  end
@@ -44,7 +44,7 @@ class JsonApiRendererTest < ActionDispatch::IntegrationTest
44
44
 
45
45
  Rails.application.routes.draw do
46
46
  ActiveSupport::Deprecation.silence do
47
- match ':action', :to => TestController, via: [:get, :post]
47
+ match ':action', to: TestController, via: [:get, :post]
48
48
  end
49
49
  end
50
50
  end
@@ -95,7 +95,7 @@ class JsonApiRendererTest < ActionDispatch::IntegrationTest
95
95
 
96
96
  Rails.application.routes.draw do
97
97
  ActiveSupport::Deprecation.silence do
98
- match ':action', :to => TestController, via: [:get, :post]
98
+ match ':action', to: TestController, via: [:get, :post]
99
99
  end
100
100
  end
101
101
  end
@@ -28,8 +28,8 @@ module ActiveModelSerializers
28
28
  def test_transform_default
29
29
  mock_request
30
30
  assert_equal({
31
- blog: { id: 1, special_attribute: 'neat', articles: nil }
32
- }, @adapter.serializable_hash)
31
+ blog: { id: 1, special_attribute: 'neat', articles: nil }
32
+ }, @adapter.serializable_hash)
33
33
  end
34
34
 
35
35
  def test_transform_global_config
@@ -38,8 +38,8 @@ module ActiveModelSerializers
38
38
  @adapter.serializable_hash
39
39
  end
40
40
  assert_equal({
41
- blog: { id: 1, specialAttribute: 'neat', articles: nil }
42
- }, result)
41
+ blog: { id: 1, specialAttribute: 'neat', articles: nil }
42
+ }, result)
43
43
  end
44
44
 
45
45
  def test_transform_serialization_ctx_overrides_global_config
@@ -48,8 +48,8 @@ module ActiveModelSerializers
48
48
  @adapter.serializable_hash
49
49
  end
50
50
  assert_equal({
51
- Blog: { Id: 1, SpecialAttribute: 'neat', Articles: nil }
52
- }, result)
51
+ Blog: { Id: 1, SpecialAttribute: 'neat', Articles: nil }
52
+ }, result)
53
53
  end
54
54
 
55
55
  def test_transform_undefined
@@ -63,29 +63,29 @@ module ActiveModelSerializers
63
63
  def test_transform_dash
64
64
  mock_request(:dash)
65
65
  assert_equal({
66
- blog: { id: 1, :"special-attribute" => 'neat', articles: nil }
67
- }, @adapter.serializable_hash)
66
+ blog: { id: 1, :"special-attribute" => 'neat', articles: nil }
67
+ }, @adapter.serializable_hash)
68
68
  end
69
69
 
70
70
  def test_transform_unaltered
71
71
  mock_request(:unaltered)
72
72
  assert_equal({
73
- blog: { id: 1, special_attribute: 'neat', articles: nil }
74
- }, @adapter.serializable_hash)
73
+ blog: { id: 1, special_attribute: 'neat', articles: nil }
74
+ }, @adapter.serializable_hash)
75
75
  end
76
76
 
77
77
  def test_transform_camel
78
78
  mock_request(:camel)
79
79
  assert_equal({
80
- Blog: { Id: 1, SpecialAttribute: 'neat', Articles: nil }
81
- }, @adapter.serializable_hash)
80
+ Blog: { Id: 1, SpecialAttribute: 'neat', Articles: nil }
81
+ }, @adapter.serializable_hash)
82
82
  end
83
83
 
84
84
  def test_transform_camel_lower
85
85
  mock_request(:camel_lower)
86
86
  assert_equal({
87
- blog: { id: 1, specialAttribute: 'neat', articles: nil }
88
- }, @adapter.serializable_hash)
87
+ blog: { id: 1, specialAttribute: 'neat', articles: nil }
88
+ }, @adapter.serializable_hash)
89
89
  end
90
90
  end
91
91
  end
@@ -12,8 +12,8 @@ module ActiveModelSerializers
12
12
 
13
13
  def test_active_model_with_error
14
14
  options = {
15
- serializer: ActiveModel::Serializer::ErrorSerializer,
16
- adapter: :json_api
15
+ serializer: ActiveModel::Serializer::ErrorSerializer,
16
+ adapter: :json_api
17
17
  }
18
18
 
19
19
  @resource.errors.add(:name, 'cannot be nil')
@@ -23,7 +23,7 @@ module ActiveModelSerializers
23
23
  assert_equal serializable_resource.serializer_instance.object, @resource
24
24
 
25
25
  expected_errors_object = {
26
- :errors => [
26
+ errors: [
27
27
  {
28
28
  source: { pointer: '/data/attributes/name' },
29
29
  detail: 'cannot be nil'
@@ -35,8 +35,8 @@ module ActiveModelSerializers
35
35
 
36
36
  def test_active_model_with_multiple_errors
37
37
  options = {
38
- serializer: ActiveModel::Serializer::ErrorSerializer,
39
- adapter: :json_api
38
+ serializer: ActiveModel::Serializer::ErrorSerializer,
39
+ adapter: :json_api
40
40
  }
41
41
 
42
42
  @resource.errors.add(:name, 'cannot be nil')
@@ -48,10 +48,10 @@ module ActiveModelSerializers
48
48
  assert_equal serializable_resource.serializer_instance.object, @resource
49
49
 
50
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' }
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
55
  ]
56
56
  }
57
57
  assert_equal serializable_resource.as_json, expected_errors_object
@@ -112,14 +112,14 @@ module ActiveModelSerializers
112
112
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer)
113
113
 
114
114
  assert_equal({
115
- data: {
116
- id: '1',
117
- type: 'posts',
118
- relationships: {
119
- tags: { data: [@tag.as_json] }
120
- }
121
- }
122
- }, adapter.serializable_hash)
115
+ data: {
116
+ id: '1',
117
+ type: 'posts',
118
+ relationships: {
119
+ tags: { data: [@tag.as_json] }
120
+ }
121
+ }
122
+ }, adapter.serializable_hash)
123
123
  end
124
124
 
125
125
  def test_has_many_with_virtual_value
@@ -127,16 +127,16 @@ module ActiveModelSerializers
127
127
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer)
128
128
 
129
129
  assert_equal({
130
- data: {
131
- id: '1',
132
- type: 'virtual-values',
133
- relationships: {
134
- maker: { data: { type: 'makers', id: '1' } },
135
- reviews: { data: [{ type: 'reviews', id: '1' },
136
- { type: 'reviews', id: '2' }] }
137
- }
138
- }
139
- }, adapter.serializable_hash)
130
+ data: {
131
+ id: '1',
132
+ type: 'virtual-values',
133
+ relationships: {
134
+ maker: { data: { type: 'makers', id: '1' } },
135
+ reviews: { data: [{ type: 'reviews', id: '1' },
136
+ { type: 'reviews', id: '2' }] }
137
+ }
138
+ }
139
+ }, adapter.serializable_hash)
140
140
  end
141
141
  end
142
142
  end
@@ -22,13 +22,11 @@ module ActiveModelSerializers
22
22
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer)
23
23
 
24
24
  assert_equal({
25
- reviews: { data: [
26
- { type: 'comments', id: '1' },
27
- { type: 'comments', id: '2' }
28
- ] },
29
- writer: { data: { type: 'authors', id: '1' } },
30
- site: { data: { type: 'blogs', id: '1' } }
31
- }, adapter.serializable_hash[:data][:relationships])
25
+ reviews: { data: [{ type: 'comments', id: '1' },
26
+ { type: 'comments', id: '2' }] },
27
+ writer: { data: { type: 'authors', id: '1' } },
28
+ site: { data: { type: 'blogs', id: '1' } }
29
+ }, adapter.serializable_hash[:data][:relationships])
32
30
  end
33
31
  end
34
32
  end
@@ -17,7 +17,7 @@ module ActiveModelSerializers
17
17
  @first_post = Post.new(id: 10, title: 'Hello!!', body: 'Hello, world!!')
18
18
  @second_post = Post.new(id: 20, title: 'New Post', body: 'Body')
19
19
  @third_post = Post.new(id: 30, title: 'Yet Another Post', body: 'Body')
20
- @blog = Blog.new({ name: 'AMS Blog' })
20
+ @blog = Blog.new(name: 'AMS Blog')
21
21
  @first_comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
22
22
  @second_comment = Comment.new(id: 2, body: 'ZOMG ANOTHER COMMENT')
23
23
  @first_post.blog = @blog
@@ -13,11 +13,11 @@ module ActiveModelSerializers
13
13
  def setup
14
14
  ActionController::Base.cache_store.clear
15
15
  @array = [
16
- Profile.new({ id: 1, name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
17
- Profile.new({ id: 2, name: 'Name 2', description: 'Description 2', comments: 'Comments 2' }),
18
- Profile.new({ id: 3, name: 'Name 3', description: 'Description 3', comments: 'Comments 3' }),
19
- Profile.new({ id: 4, name: 'Name 4', description: 'Description 4', comments: 'Comments 4' }),
20
- Profile.new({ id: 5, name: 'Name 5', description: 'Description 5', comments: 'Comments 5' })
16
+ Profile.new(id: 1, name: 'Name 1', description: 'Description 1', comments: 'Comments 1'),
17
+ Profile.new(id: 2, name: 'Name 2', description: 'Description 2', comments: 'Comments 2'),
18
+ Profile.new(id: 3, name: 'Name 3', description: 'Description 3', comments: 'Comments 3'),
19
+ Profile.new(id: 4, name: 'Name 4', description: 'Description 4', comments: 'Comments 4'),
20
+ Profile.new(id: 5, name: 'Name 5', description: 'Description 5', comments: 'Comments 5')
21
21
  ]
22
22
  end
23
23
 
@@ -122,7 +122,7 @@ module ActiveModelSerializers
122
122
  end
123
123
 
124
124
  def test_pagination_links_with_additional_params
125
- adapter = load_adapter(using_will_paginate, mock_request({ test: 'test' }))
125
+ adapter = load_adapter(using_will_paginate, mock_request(test: 'test'))
126
126
 
127
127
  assert_equal expected_response_with_pagination_links_and_additional_params,
128
128
  adapter.serializable_hash
@@ -68,9 +68,9 @@ module ActiveModel
68
68
  adapter: :json_api
69
69
  ).serializable_hash
70
70
  expected = {
71
- :data => [
72
- { :id => '1337', :type => 'posts', :meta => { :"comments-count" => 0 } },
73
- { :id => '1339', :type => 'posts', :meta => { :"comments-count" => 1 } }
71
+ data: [
72
+ { id: '1337', type: 'posts', meta: { :"comments-count" => 0 } },
73
+ { id: '1339', type: 'posts', meta: { :"comments-count" => 1 } }
74
74
  ]
75
75
  }
76
76
  assert_equal(expected, hash)
@@ -70,33 +70,33 @@ module ActiveModelSerializers
70
70
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
71
71
  result = adapter.serializable_hash
72
72
  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
- },
92
- links: {
93
- self: 'http://example.com/posts/1337',
94
- :"post-authors" => 'http://example.com/posts/1337/authors',
95
- :"subscriber-comments" => 'http://example.com/posts/1337/comments'
96
- },
97
- meta: { rating: 5, :"favorite-count" => 10 }
98
- }
99
- }, result)
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
+ },
92
+ links: {
93
+ self: 'http://example.com/posts/1337',
94
+ :"post-authors" => 'http://example.com/posts/1337/authors',
95
+ :"subscriber-comments" => 'http://example.com/posts/1337/comments'
96
+ },
97
+ meta: { rating: 5, :"favorite-count" => 10 }
98
+ }
99
+ }, result)
100
100
  end
101
101
 
102
102
  def test_success_document_transform_global_config
@@ -107,33 +107,33 @@ module ActiveModelSerializers
107
107
  adapter.serializable_hash
108
108
  end
109
109
  assert_equal({
110
- data: {
111
- id: '1337',
112
- type: 'posts',
113
- attributes: {
114
- title: 'Title 1',
115
- body: 'Body 1',
116
- publishAt: @publish_at
117
- },
118
- relationships: {
119
- author: {
120
- data: { id: '1', type: 'authors' }
121
- },
122
- comments: {
123
- data: [
124
- { id: '7', type: 'comments' },
125
- { id: '12', type: 'comments' }
126
- ]
127
- }
128
- },
129
- links: {
130
- self: 'http://example.com/posts/1337',
131
- postAuthors: 'http://example.com/posts/1337/authors',
132
- subscriberComments: 'http://example.com/posts/1337/comments'
133
- },
134
- meta: { rating: 5, favoriteCount: 10 }
135
- }
136
- }, result)
110
+ data: {
111
+ id: '1337',
112
+ type: 'posts',
113
+ attributes: {
114
+ title: 'Title 1',
115
+ body: 'Body 1',
116
+ publishAt: @publish_at
117
+ },
118
+ relationships: {
119
+ author: {
120
+ data: { id: '1', type: 'authors' }
121
+ },
122
+ comments: {
123
+ data: [
124
+ { id: '7', type: 'comments' },
125
+ { id: '12', type: 'comments' }
126
+ ]
127
+ }
128
+ },
129
+ links: {
130
+ self: 'http://example.com/posts/1337',
131
+ postAuthors: 'http://example.com/posts/1337/authors',
132
+ subscriberComments: 'http://example.com/posts/1337/comments'
133
+ },
134
+ meta: { rating: 5, favoriteCount: 10 }
135
+ }
136
+ }, result)
137
137
  end
138
138
 
139
139
  def test_success_doc_transform_serialization_ctx_overrides_global
@@ -144,33 +144,33 @@ module ActiveModelSerializers
144
144
  adapter.serializable_hash
145
145
  end
146
146
  assert_equal({
147
- Data: {
148
- Id: '1337',
149
- Type: 'Posts',
150
- Attributes: {
151
- Title: 'Title 1',
152
- Body: 'Body 1',
153
- PublishAt: @publish_at
154
- },
155
- Relationships: {
156
- Author: {
157
- Data: { Id: '1', Type: 'Authors' }
158
- },
159
- Comments: {
160
- Data: [
161
- { Id: '7', Type: 'Comments' },
162
- { Id: '12', Type: 'Comments' }
163
- ]
164
- }
165
- },
166
- Links: {
167
- Self: 'http://example.com/posts/1337',
168
- PostAuthors: 'http://example.com/posts/1337/authors',
169
- SubscriberComments: 'http://example.com/posts/1337/comments'
170
- },
171
- Meta: { Rating: 5, FavoriteCount: 10 }
172
- }
173
- }, result)
147
+ Data: {
148
+ Id: '1337',
149
+ Type: 'Posts',
150
+ Attributes: {
151
+ Title: 'Title 1',
152
+ Body: 'Body 1',
153
+ PublishAt: @publish_at
154
+ },
155
+ Relationships: {
156
+ Author: {
157
+ Data: { Id: '1', Type: 'Authors' }
158
+ },
159
+ Comments: {
160
+ Data: [
161
+ { Id: '7', Type: 'Comments' },
162
+ { Id: '12', Type: 'Comments' }
163
+ ]
164
+ }
165
+ },
166
+ Links: {
167
+ Self: 'http://example.com/posts/1337',
168
+ PostAuthors: 'http://example.com/posts/1337/authors',
169
+ SubscriberComments: 'http://example.com/posts/1337/comments'
170
+ },
171
+ Meta: { Rating: 5, FavoriteCount: 10 }
172
+ }
173
+ }, result)
174
174
  end
175
175
 
176
176
  def test_success_document_transform_dash
@@ -179,33 +179,33 @@ module ActiveModelSerializers
179
179
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
180
180
  result = adapter.serializable_hash
181
181
  assert_equal({
182
- data: {
183
- id: '1337',
184
- type: 'posts',
185
- attributes: {
186
- title: 'Title 1',
187
- body: 'Body 1',
188
- :"publish-at" => @publish_at
189
- },
190
- relationships: {
191
- author: {
192
- data: { id: '1', type: 'authors' }
193
- },
194
- comments: {
195
- data: [
196
- { id: '7', type: 'comments' },
197
- { id: '12', type: 'comments' }
198
- ]
199
- }
200
- },
201
- links: {
202
- self: 'http://example.com/posts/1337',
203
- :"post-authors" => 'http://example.com/posts/1337/authors',
204
- :"subscriber-comments" => 'http://example.com/posts/1337/comments'
205
- },
206
- meta: { rating: 5, :"favorite-count" => 10 }
207
- }
208
- }, result)
182
+ data: {
183
+ id: '1337',
184
+ type: 'posts',
185
+ attributes: {
186
+ title: 'Title 1',
187
+ body: 'Body 1',
188
+ :"publish-at" => @publish_at
189
+ },
190
+ relationships: {
191
+ author: {
192
+ data: { id: '1', type: 'authors' }
193
+ },
194
+ comments: {
195
+ data: [
196
+ { id: '7', type: 'comments' },
197
+ { id: '12', type: 'comments' }
198
+ ]
199
+ }
200
+ },
201
+ links: {
202
+ self: 'http://example.com/posts/1337',
203
+ :"post-authors" => 'http://example.com/posts/1337/authors',
204
+ :"subscriber-comments" => 'http://example.com/posts/1337/comments'
205
+ },
206
+ meta: { rating: 5, :"favorite-count" => 10 }
207
+ }
208
+ }, result)
209
209
  end
210
210
 
211
211
  def test_success_document_transform_unaltered
@@ -214,33 +214,33 @@ module ActiveModelSerializers
214
214
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
215
215
  result = adapter.serializable_hash
216
216
  assert_equal({
217
- data: {
218
- id: '1337',
219
- type: 'posts',
220
- attributes: {
221
- title: 'Title 1',
222
- body: 'Body 1',
223
- publish_at: @publish_at
224
- },
225
- relationships: {
226
- author: {
227
- data: { id: '1', type: 'authors' }
228
- },
229
- comments: {
230
- data: [
231
- { id: '7', type: 'comments' },
232
- { id: '12', type: 'comments' }
233
- ]
234
- }
235
- },
236
- links: {
237
- self: 'http://example.com/posts/1337',
238
- post_authors: 'http://example.com/posts/1337/authors',
239
- subscriber_comments: 'http://example.com/posts/1337/comments'
240
- },
241
- meta: { rating: 5, favorite_count: 10 }
242
- }
243
- }, result)
217
+ data: {
218
+ id: '1337',
219
+ type: 'posts',
220
+ attributes: {
221
+ title: 'Title 1',
222
+ body: 'Body 1',
223
+ publish_at: @publish_at
224
+ },
225
+ relationships: {
226
+ author: {
227
+ data: { id: '1', type: 'authors' }
228
+ },
229
+ comments: {
230
+ data: [
231
+ { id: '7', type: 'comments' },
232
+ { id: '12', type: 'comments' }
233
+ ]
234
+ }
235
+ },
236
+ links: {
237
+ self: 'http://example.com/posts/1337',
238
+ post_authors: 'http://example.com/posts/1337/authors',
239
+ subscriber_comments: 'http://example.com/posts/1337/comments'
240
+ },
241
+ meta: { rating: 5, favorite_count: 10 }
242
+ }
243
+ }, result)
244
244
  end
245
245
 
246
246
  def test_success_document_transform_undefined
@@ -259,33 +259,33 @@ module ActiveModelSerializers
259
259
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
260
260
  result = adapter.serializable_hash
261
261
  assert_equal({
262
- Data: {
263
- Id: '1337',
264
- Type: 'Posts',
265
- Attributes: {
266
- Title: 'Title 1',
267
- Body: 'Body 1',
268
- PublishAt: @publish_at
269
- },
270
- Relationships: {
271
- Author: {
272
- Data: { Id: '1', Type: 'Authors' }
273
- },
274
- Comments: {
275
- Data: [
276
- { Id: '7', Type: 'Comments' },
277
- { Id: '12', Type: 'Comments' }
278
- ]
279
- }
280
- },
281
- Links: {
282
- Self: 'http://example.com/posts/1337',
283
- PostAuthors: 'http://example.com/posts/1337/authors',
284
- SubscriberComments: 'http://example.com/posts/1337/comments'
285
- },
286
- Meta: { Rating: 5, FavoriteCount: 10 }
287
- }
288
- }, result)
262
+ Data: {
263
+ Id: '1337',
264
+ Type: 'Posts',
265
+ Attributes: {
266
+ Title: 'Title 1',
267
+ Body: 'Body 1',
268
+ PublishAt: @publish_at
269
+ },
270
+ Relationships: {
271
+ Author: {
272
+ Data: { Id: '1', Type: 'Authors' }
273
+ },
274
+ Comments: {
275
+ Data: [
276
+ { Id: '7', Type: 'Comments' },
277
+ { Id: '12', Type: 'Comments' }
278
+ ]
279
+ }
280
+ },
281
+ Links: {
282
+ Self: 'http://example.com/posts/1337',
283
+ PostAuthors: 'http://example.com/posts/1337/authors',
284
+ SubscriberComments: 'http://example.com/posts/1337/comments'
285
+ },
286
+ Meta: { Rating: 5, FavoriteCount: 10 }
287
+ }
288
+ }, result)
289
289
  end
290
290
 
291
291
  def test_success_document_transform_camel_lower
@@ -294,33 +294,33 @@ module ActiveModelSerializers
294
294
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
295
295
  result = adapter.serializable_hash
296
296
  assert_equal({
297
- data: {
298
- id: '1337',
299
- type: 'posts',
300
- attributes: {
301
- title: 'Title 1',
302
- body: 'Body 1',
303
- publishAt: @publish_at
304
- },
305
- relationships: {
306
- author: {
307
- data: { id: '1', type: 'authors' }
308
- },
309
- comments: {
310
- data: [
311
- { id: '7', type: 'comments' },
312
- { id: '12', type: 'comments' }
313
- ]
314
- }
315
- },
316
- links: {
317
- self: 'http://example.com/posts/1337',
318
- postAuthors: 'http://example.com/posts/1337/authors',
319
- subscriberComments: 'http://example.com/posts/1337/comments'
320
- },
321
- meta: { rating: 5, favoriteCount: 10 }
322
- }
323
- }, result)
297
+ data: {
298
+ id: '1337',
299
+ type: 'posts',
300
+ attributes: {
301
+ title: 'Title 1',
302
+ body: 'Body 1',
303
+ publishAt: @publish_at
304
+ },
305
+ relationships: {
306
+ author: {
307
+ data: { id: '1', type: 'authors' }
308
+ },
309
+ comments: {
310
+ data: [
311
+ { id: '7', type: 'comments' },
312
+ { id: '12', type: 'comments' }
313
+ ]
314
+ }
315
+ },
316
+ links: {
317
+ self: 'http://example.com/posts/1337',
318
+ postAuthors: 'http://example.com/posts/1337/authors',
319
+ subscriberComments: 'http://example.com/posts/1337/comments'
320
+ },
321
+ meta: { rating: 5, favoriteCount: 10 }
322
+ }
323
+ }, result)
324
324
  end
325
325
 
326
326
  def test_error_document_transform_default
@@ -332,14 +332,14 @@ module ActiveModelSerializers
332
332
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer, @options)
333
333
  result = adapter.serializable_hash
334
334
  expected_errors_object = {
335
- :errors => [
335
+ errors: [
336
336
  {
337
- :source => { :pointer => '/data/attributes/published-at' },
338
- :detail => 'must be in the future'
337
+ source: { pointer: '/data/attributes/published-at' },
338
+ detail: 'must be in the future'
339
339
  },
340
340
  {
341
- :source => { :pointer => '/data/attributes/title' },
342
- :detail => 'must be longer'
341
+ source: { pointer: '/data/attributes/title' },
342
+ detail: 'must be longer'
343
343
  }
344
344
  ]
345
345
  }
@@ -357,14 +357,14 @@ module ActiveModelSerializers
357
357
  adapter.serializable_hash
358
358
  end
359
359
  expected_errors_object = {
360
- :Errors => [
360
+ Errors: [
361
361
  {
362
- :Source => { :Pointer => '/data/attributes/PublishedAt' },
363
- :Detail => 'must be in the future'
362
+ Source: { Pointer: '/data/attributes/PublishedAt' },
363
+ Detail: 'must be in the future'
364
364
  },
365
365
  {
366
- :Source => { :Pointer => '/data/attributes/Title' },
367
- :Detail => 'must be longer'
366
+ Source: { Pointer: '/data/attributes/Title' },
367
+ Detail: 'must be longer'
368
368
  }
369
369
  ]
370
370
  }
@@ -382,14 +382,14 @@ module ActiveModelSerializers
382
382
  adapter.serializable_hash
383
383
  end
384
384
  expected_errors_object = {
385
- :Errors => [
385
+ Errors: [
386
386
  {
387
- :Source => { :Pointer => '/data/attributes/PublishedAt' },
388
- :Detail => 'must be in the future'
387
+ Source: { Pointer: '/data/attributes/PublishedAt' },
388
+ Detail: 'must be in the future'
389
389
  },
390
390
  {
391
- :Source => { :Pointer => '/data/attributes/Title' },
392
- :Detail => 'must be longer'
391
+ Source: { Pointer: '/data/attributes/Title' },
392
+ Detail: 'must be longer'
393
393
  }
394
394
  ]
395
395
  }
@@ -408,14 +408,14 @@ module ActiveModelSerializers
408
408
  result = adapter.serializable_hash
409
409
 
410
410
  expected_errors_object = {
411
- :errors => [
411
+ errors: [
412
412
  {
413
- :source => { :pointer => '/data/attributes/published-at' },
414
- :detail => 'must be in the future'
413
+ source: { pointer: '/data/attributes/published-at' },
414
+ detail: 'must be in the future'
415
415
  },
416
416
  {
417
- :source => { :pointer => '/data/attributes/title' },
418
- :detail => 'must be longer'
417
+ source: { pointer: '/data/attributes/title' },
418
+ detail: 'must be longer'
419
419
  }
420
420
  ]
421
421
  }
@@ -434,9 +434,9 @@ module ActiveModelSerializers
434
434
  result = adapter.serializable_hash
435
435
 
436
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' }
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
440
  ]
441
441
  }
442
442
  assert_equal expected_errors_object, result
@@ -470,9 +470,9 @@ module ActiveModelSerializers
470
470
  result = adapter.serializable_hash
471
471
 
472
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' }
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
476
  ]
477
477
  }
478
478
  assert_equal expected_errors_object, result
@@ -490,9 +490,9 @@ module ActiveModelSerializers
490
490
  result = adapter.serializable_hash
491
491
 
492
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' }
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
498
  assert_equal expected_errors_object, result