active_model_serializers 0.10.0 → 0.10.3

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 (146) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -4
  3. data/.travis.yml +9 -1
  4. data/CHANGELOG.md +81 -2
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +5 -2
  7. data/README.md +24 -24
  8. data/Rakefile +3 -3
  9. data/active_model_serializers.gemspec +20 -24
  10. data/docs/ARCHITECTURE.md +6 -7
  11. data/docs/README.md +2 -0
  12. data/docs/general/adapters.md +4 -2
  13. data/docs/general/caching.md +7 -1
  14. data/docs/general/configuration_options.md +70 -1
  15. data/docs/general/deserialization.md +1 -1
  16. data/docs/general/fields.md +31 -0
  17. data/docs/general/rendering.md +42 -3
  18. data/docs/general/serializers.md +97 -8
  19. data/docs/howto/add_pagination_links.md +4 -5
  20. data/docs/howto/add_relationship_links.md +137 -0
  21. data/docs/howto/add_root_key.md +4 -0
  22. data/docs/howto/grape_integration.md +42 -0
  23. data/docs/howto/outside_controller_use.md +9 -2
  24. data/docs/howto/passing_arbitrary_options.md +2 -2
  25. data/docs/howto/test.md +2 -0
  26. data/docs/howto/upgrade_from_0_8_to_0_10.md +265 -0
  27. data/docs/integrations/ember-and-json-api.md +64 -32
  28. data/docs/jsonapi/schema.md +1 -1
  29. data/lib/action_controller/serialization.rb +13 -3
  30. data/lib/active_model/serializer/adapter/base.rb +2 -0
  31. data/lib/active_model/serializer/array_serializer.rb +8 -5
  32. data/lib/active_model/serializer/association.rb +19 -4
  33. data/lib/active_model/serializer/belongs_to_reflection.rb +0 -3
  34. data/lib/active_model/serializer/collection_serializer.rb +35 -12
  35. data/lib/active_model/serializer/{associations.rb → concerns/associations.rb} +13 -11
  36. data/lib/active_model/serializer/{attributes.rb → concerns/attributes.rb} +0 -0
  37. data/lib/active_model/serializer/{caching.rb → concerns/caching.rb} +72 -113
  38. data/lib/active_model/serializer/{configuration.rb → concerns/configuration.rb} +25 -1
  39. data/lib/active_model/serializer/{links.rb → concerns/links.rb} +0 -0
  40. data/lib/active_model/serializer/{meta.rb → concerns/meta.rb} +0 -0
  41. data/lib/active_model/serializer/{type.rb → concerns/type.rb} +0 -0
  42. data/lib/active_model/serializer/error_serializer.rb +11 -7
  43. data/lib/active_model/serializer/errors_serializer.rb +25 -20
  44. data/lib/active_model/serializer/has_many_reflection.rb +0 -3
  45. data/lib/active_model/serializer/has_one_reflection.rb +0 -3
  46. data/lib/active_model/serializer/lint.rb +134 -130
  47. data/lib/active_model/serializer/reflection.rb +37 -21
  48. data/lib/active_model/serializer/version.rb +1 -1
  49. data/lib/active_model/serializer.rb +76 -37
  50. data/lib/active_model_serializers/adapter/attributes.rb +3 -66
  51. data/lib/active_model_serializers/adapter/base.rb +38 -38
  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 +30 -19
  55. data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +23 -9
  56. data/lib/active_model_serializers/adapter/json_api.rb +44 -43
  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/key_transform.rb +4 -0
  61. data/lib/active_model_serializers/lookup_chain.rb +80 -0
  62. data/lib/active_model_serializers/model.rb +4 -2
  63. data/lib/active_model_serializers/railtie.rb +3 -1
  64. data/lib/active_model_serializers/register_jsonapi_renderer.rb +44 -31
  65. data/lib/active_model_serializers/serializable_resource.rb +6 -5
  66. data/lib/active_model_serializers/serialization_context.rb +10 -3
  67. data/lib/active_model_serializers.rb +7 -0
  68. data/lib/generators/rails/serializer_generator.rb +4 -4
  69. data/lib/grape/active_model_serializers.rb +7 -5
  70. data/lib/grape/formatters/active_model_serializers.rb +19 -2
  71. data/lib/grape/helpers/active_model_serializers.rb +1 -0
  72. data/test/action_controller/adapter_selector_test.rb +4 -4
  73. data/test/action_controller/explicit_serializer_test.rb +5 -4
  74. data/test/action_controller/json/include_test.rb +106 -27
  75. data/test/action_controller/json_api/errors_test.rb +6 -7
  76. data/test/action_controller/json_api/fields_test.rb +57 -0
  77. data/test/action_controller/json_api/linked_test.rb +29 -24
  78. data/test/action_controller/json_api/pagination_test.rb +19 -19
  79. data/test/action_controller/json_api/transform_test.rb +3 -3
  80. data/test/action_controller/lookup_proc_test.rb +49 -0
  81. data/test/action_controller/namespace_lookup_test.rb +226 -0
  82. data/test/action_controller/serialization_test.rb +10 -7
  83. data/test/active_model_serializers/json_pointer_test.rb +15 -13
  84. data/test/active_model_serializers/key_transform_test.rb +286 -252
  85. data/test/active_model_serializers/model_test.rb +17 -4
  86. data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +143 -0
  87. data/test/active_model_serializers/serialization_context_test_isolated.rb +23 -10
  88. data/test/adapter/attributes_test.rb +43 -0
  89. data/test/adapter/json/collection_test.rb +14 -0
  90. data/test/adapter/json/transform_test.rb +15 -15
  91. data/test/adapter/json_api/collection_test.rb +4 -3
  92. data/test/adapter/json_api/errors_test.rb +17 -19
  93. data/test/adapter/json_api/fields_test.rb +4 -3
  94. data/test/adapter/json_api/has_many_test.rb +39 -18
  95. data/test/adapter/json_api/include_data_if_sideloaded_test.rb +166 -0
  96. data/test/adapter/json_api/json_api_test.rb +5 -7
  97. data/test/adapter/json_api/linked_test.rb +33 -12
  98. data/test/adapter/json_api/links_test.rb +4 -2
  99. data/test/adapter/json_api/pagination_links_test.rb +35 -8
  100. data/test/adapter/json_api/relationship_test.rb +309 -73
  101. data/test/adapter/json_api/resource_identifier_test.rb +27 -2
  102. data/test/adapter/json_api/resource_meta_test.rb +3 -3
  103. data/test/adapter/json_api/transform_test.rb +255 -253
  104. data/test/adapter/json_api/type_test.rb +1 -1
  105. data/test/adapter/json_test.rb +8 -7
  106. data/test/adapter/null_test.rb +1 -2
  107. data/test/adapter/polymorphic_test.rb +5 -5
  108. data/test/adapter_test.rb +1 -1
  109. data/test/benchmark/app.rb +1 -1
  110. data/test/benchmark/benchmarking_support.rb +1 -1
  111. data/test/benchmark/bm_active_record.rb +81 -0
  112. data/test/benchmark/bm_adapter.rb +38 -0
  113. data/test/benchmark/bm_caching.rb +16 -16
  114. data/test/benchmark/bm_lookup_chain.rb +83 -0
  115. data/test/benchmark/bm_transform.rb +16 -5
  116. data/test/benchmark/controllers.rb +16 -17
  117. data/test/benchmark/fixtures.rb +72 -72
  118. data/test/cache_test.rb +143 -49
  119. data/test/collection_serializer_test.rb +3 -3
  120. data/test/fixtures/poro.rb +52 -48
  121. data/test/generators/serializer_generator_test.rb +22 -5
  122. data/test/grape_test.rb +152 -56
  123. data/test/lint_test.rb +1 -1
  124. data/test/logger_test.rb +13 -11
  125. data/test/serializable_resource_test.rb +18 -22
  126. data/test/serializers/association_macros_test.rb +3 -2
  127. data/test/serializers/associations_test.rb +107 -32
  128. data/test/serializers/attribute_test.rb +2 -2
  129. data/test/serializers/attributes_test.rb +1 -1
  130. data/test/serializers/fieldset_test.rb +1 -1
  131. data/test/serializers/meta_test.rb +12 -6
  132. data/test/serializers/root_test.rb +1 -1
  133. data/test/serializers/serializer_for_test.rb +6 -4
  134. data/test/serializers/serializer_for_with_namespace_test.rb +87 -0
  135. data/test/support/isolated_unit.rb +5 -2
  136. data/test/support/rails5_shims.rb +8 -2
  137. data/test/support/rails_app.rb +0 -9
  138. data/test/support/serialization_testing.rb +23 -5
  139. data/test/test_helper.rb +1 -0
  140. metadata +85 -34
  141. data/.rubocop_todo.yml +0 -167
  142. data/lib/active_model/serializer/include_tree.rb +0 -111
  143. data/test/adapter/json_api/relationships_test.rb +0 -199
  144. data/test/include_tree/from_include_args_test.rb +0 -26
  145. data/test/include_tree/from_string_test.rb +0 -94
  146. data/test/include_tree/include_args_to_hash_test.rb +0 -64
@@ -0,0 +1,166 @@
1
+ require 'test_helper'
2
+
3
+ module ActiveModel
4
+ class Serializer
5
+ module Adapter
6
+ class JsonApi
7
+ class IncludeParamTest < ActiveSupport::TestCase
8
+ IncludeParamAuthor = Class.new(::Model)
9
+
10
+ class CustomCommentLoader
11
+ def all
12
+ [{ foo: 'bar' }]
13
+ end
14
+ end
15
+
16
+ class TagSerializer < ActiveModel::Serializer
17
+ attributes :id, :name
18
+ end
19
+
20
+ class IncludeParamAuthorSerializer < ActiveModel::Serializer
21
+ class_attribute :comment_loader
22
+
23
+ has_many :tags, serializer: TagSerializer do
24
+ link :self, '//example.com/link_author/relationships/tags'
25
+ include_data :if_sideloaded
26
+ end
27
+
28
+ has_many :unlinked_tags, serializer: TagSerializer do
29
+ include_data :if_sideloaded
30
+ end
31
+
32
+ has_many :posts, serializer: PostWithTagsSerializer do
33
+ include_data :if_sideloaded
34
+ end
35
+ has_many :locations do
36
+ include_data :if_sideloaded
37
+ end
38
+ has_many :comments do
39
+ include_data :if_sideloaded
40
+ IncludeParamAuthorSerializer.comment_loader.all
41
+ end
42
+ end
43
+
44
+ def setup
45
+ IncludeParamAuthorSerializer.comment_loader = Class.new(CustomCommentLoader).new
46
+ @tag = Tag.new(id: 1337, name: 'mytag')
47
+ @author = IncludeParamAuthor.new(
48
+ id: 1337,
49
+ tags: [@tag]
50
+ )
51
+ end
52
+
53
+ def test_relationship_not_loaded_when_not_included
54
+ expected = {
55
+ links: {
56
+ self: '//example.com/link_author/relationships/tags'
57
+ }
58
+ }
59
+
60
+ @author.define_singleton_method(:read_attribute_for_serialization) do |attr|
61
+ fail 'should not be called' if attr == :tags
62
+ super(attr)
63
+ end
64
+
65
+ assert_relationship(:tags, expected)
66
+ end
67
+
68
+ def test_relationship_included
69
+ expected = {
70
+ data: [
71
+ {
72
+ id: '1337',
73
+ type: 'tags'
74
+ }
75
+ ],
76
+ links: {
77
+ self: '//example.com/link_author/relationships/tags'
78
+ }
79
+ }
80
+
81
+ assert_relationship(:tags, expected, include: :tags)
82
+ end
83
+
84
+ def test_sideloads_included
85
+ expected = [
86
+ {
87
+ id: '1337',
88
+ type: 'tags',
89
+ attributes: { name: 'mytag' }
90
+ }
91
+ ]
92
+ hash = result(include: :tags)
93
+ assert_equal(expected, hash[:included])
94
+ end
95
+
96
+ def test_nested_relationship
97
+ expected = {
98
+ data: [
99
+ {
100
+ id: '1337',
101
+ type: 'tags'
102
+ }
103
+ ],
104
+ links: {
105
+ self: '//example.com/link_author/relationships/tags'
106
+ }
107
+ }
108
+
109
+ expected_no_data = {
110
+ links: {
111
+ self: '//example.com/link_author/relationships/tags'
112
+ }
113
+ }
114
+
115
+ assert_relationship(:tags, expected, include: [:tags, { posts: :tags }])
116
+
117
+ @author.define_singleton_method(:read_attribute_for_serialization) do |attr|
118
+ fail 'should not be called' if attr == :tags
119
+ super(attr)
120
+ end
121
+
122
+ assert_relationship(:tags, expected_no_data, include: { posts: :tags })
123
+ end
124
+
125
+ def test_include_params_with_no_block
126
+ @author.define_singleton_method(:read_attribute_for_serialization) do |attr|
127
+ fail 'should not be called' if attr == :locations
128
+ super(attr)
129
+ end
130
+
131
+ expected = { meta: {} }
132
+
133
+ assert_relationship(:locations, expected)
134
+ end
135
+
136
+ def test_block_relationship
137
+ expected = {
138
+ data: [
139
+ { 'foo' => 'bar' }
140
+ ]
141
+ }
142
+
143
+ assert_relationship(:comments, expected, include: [:comments])
144
+ end
145
+
146
+ def test_node_not_included_when_no_link
147
+ expected = nil
148
+ assert_relationship(:unlinked_tags, expected)
149
+ end
150
+
151
+ private
152
+
153
+ def result(opts)
154
+ opts = { adapter: :json_api }.merge(opts)
155
+ serializable(@author, opts).serializable_hash
156
+ end
157
+
158
+ def assert_relationship(relationship_name, expected, opts = {})
159
+ hash = result(opts)
160
+ assert_equal(expected, hash[:data][:relationships][relationship_name])
161
+ end
162
+ end
163
+ end
164
+ end
165
+ end
166
+ 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
@@ -1,10 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
- NestedPost = Class.new(Model)
3
+ class NestedPost < ::Model; end
4
4
  class NestedPostSerializer < ActiveModel::Serializer
5
5
  has_many :nested_posts
6
6
  end
7
-
8
7
  module ActiveModelSerializers
9
8
  module Adapter
10
9
  class JsonApi
@@ -17,7 +16,7 @@ module ActiveModelSerializers
17
16
  @first_post = Post.new(id: 10, title: 'Hello!!', body: 'Hello, world!!')
18
17
  @second_post = Post.new(id: 20, title: 'New Post', body: 'Body')
19
18
  @third_post = Post.new(id: 30, title: 'Yet Another Post', body: 'Body')
20
- @blog = Blog.new({ name: 'AMS Blog' })
19
+ @blog = Blog.new(name: 'AMS Blog')
21
20
  @first_comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
22
21
  @second_comment = Comment.new(id: 2, body: 'ZOMG ANOTHER COMMENT')
23
22
  @first_post.blog = @blog
@@ -224,6 +223,25 @@ module ActiveModelSerializers
224
223
  assert_equal expected, relationships
225
224
  end
226
225
 
226
+ def test_underscore_model_namespace_with_namespace_separator_for_linked_resource_type
227
+ spammy_post = Post.new(id: 123)
228
+ spammy_post.related = [Spam::UnrelatedLink.new(id: 456)]
229
+ serializer = SpammyPostSerializer.new(spammy_post)
230
+ adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer)
231
+ relationships = with_namespace_separator '--' do
232
+ adapter.serializable_hash[:data][:relationships]
233
+ end
234
+ expected = {
235
+ related: {
236
+ data: [{
237
+ type: 'spam--unrelated-links',
238
+ id: '456'
239
+ }]
240
+ }
241
+ }
242
+ assert_equal expected, relationships
243
+ end
244
+
227
245
  def test_multiple_references_to_same_resource
228
246
  serializer = ActiveModel::Serializer::CollectionSerializer.new([@first_comment, @second_comment])
229
247
  adapter = ActiveModelSerializers::Adapter::JsonApi.new(
@@ -283,8 +301,8 @@ module ActiveModelSerializers
283
301
  end
284
302
 
285
303
  class NoDuplicatesTest < ActiveSupport::TestCase
286
- Post = Class.new(::Model)
287
- Author = Class.new(::Model)
304
+ class Post < ::Model; end
305
+ class Author < ::Model; end
288
306
 
289
307
  class PostSerializer < ActiveModel::Serializer
290
308
  type 'posts'
@@ -303,8 +321,8 @@ module ActiveModelSerializers
303
321
  @author.posts << @post1
304
322
  @author.posts << @post2
305
323
 
306
- @nestedpost1 = ::NestedPost.new(id: 1, nested_posts: [])
307
- @nestedpost2 = ::NestedPost.new(id: 2, nested_posts: [])
324
+ @nestedpost1 = NestedPost.new(id: 1, nested_posts: [])
325
+ @nestedpost2 = NestedPost.new(id: 2, nested_posts: [])
308
326
  @nestedpost1.nested_posts << @nestedpost1
309
327
  @nestedpost1.nested_posts << @nestedpost2
310
328
  @nestedpost2.nested_posts << @nestedpost1
@@ -341,9 +359,10 @@ module ActiveModelSerializers
341
359
 
342
360
  def test_no_duplicates_collection
343
361
  hash = ActiveModelSerializers::SerializableResource.new(
344
- [@post1, @post2], adapter: :json_api,
345
- include: '*.*')
346
- .serializable_hash
362
+ [@post1, @post2],
363
+ adapter: :json_api,
364
+ include: '*.*'
365
+ ).serializable_hash
347
366
  expected = [
348
367
  {
349
368
  type: 'authors', id: '1',
@@ -364,7 +383,8 @@ module ActiveModelSerializers
364
383
  hash = ActiveModelSerializers::SerializableResource.new(
365
384
  @nestedpost1,
366
385
  adapter: :json_api,
367
- include: '*').serializable_hash
386
+ include: '*'
387
+ ).serializable_hash
368
388
  expected = [
369
389
  type: 'nested-posts', id: '2',
370
390
  relationships: {
@@ -383,7 +403,8 @@ module ActiveModelSerializers
383
403
  hash = ActiveModelSerializers::SerializableResource.new(
384
404
  [@nestedpost1, @nestedpost2],
385
405
  adapter: :json_api,
386
- include: '*').serializable_hash
406
+ include: '*'
407
+ ).serializable_hash
387
408
  assert_nil(hash[:included])
388
409
  end
389
410
  end
@@ -4,7 +4,7 @@ module ActiveModelSerializers
4
4
  module Adapter
5
5
  class JsonApi
6
6
  class LinksTest < ActiveSupport::TestCase
7
- LinkAuthor = Class.new(::Model)
7
+ class LinkAuthor < ::Model; end
8
8
  class LinkAuthorSerializer < ActiveModel::Serializer
9
9
  link :self do
10
10
  href "http://example.com/link_author/#{object.id}"
@@ -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
- }).serializable_hash
44
+ }
45
+ ).serializable_hash
44
46
  expected = {
45
47
  self: {
46
48
  href: 'http://example.com/posts',
@@ -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
 
@@ -43,7 +43,8 @@ module ActiveModelSerializers
43
43
  end
44
44
 
45
45
  def data
46
- { data: [
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' } },
@@ -75,7 +76,7 @@ module ActiveModelSerializers
75
76
  }
76
77
  end
77
78
 
78
- def expected_response_without_pagination_links
79
+ def expected_response_when_unpaginatable
79
80
  data
80
81
  end
81
82
 
@@ -86,6 +87,12 @@ module ActiveModelSerializers
86
87
  end
87
88
  end
88
89
 
90
+ def expected_response_without_pagination_links
91
+ {}.tap do |hash|
92
+ hash[:data] = data.values.flatten[2..3]
93
+ end
94
+ end
95
+
89
96
  def expected_response_with_pagination_links_and_additional_params
90
97
  new_links = links[:links].each_with_object({}) { |(key, value), hash| hash[key] = "#{value}&test=test" }
91
98
  {}.tap do |hash|
@@ -121,7 +128,7 @@ module ActiveModelSerializers
121
128
  end
122
129
 
123
130
  def test_pagination_links_with_additional_params
124
- adapter = load_adapter(using_will_paginate, mock_request({ test: 'test' }))
131
+ adapter = load_adapter(using_will_paginate, mock_request(test: 'test'))
125
132
 
126
133
  assert_equal expected_response_with_pagination_links_and_additional_params,
127
134
  adapter.serializable_hash
@@ -158,7 +165,27 @@ module ActiveModelSerializers
158
165
  def test_not_showing_pagination_links
159
166
  adapter = load_adapter(@array, mock_request)
160
167
 
168
+ assert_equal expected_response_when_unpaginatable, adapter.serializable_hash
169
+ end
170
+
171
+ def test_raises_descriptive_error_when_serialization_context_unset
172
+ render_options = { adapter: :json_api }
173
+ adapter = serializable(using_kaminari, render_options)
174
+ exception = assert_raises do
175
+ adapter.as_json
176
+ end
177
+ exception_class = ActiveModelSerializers::Adapter::JsonApi::PaginationLinks::MissingSerializationContextError
178
+ assert_equal exception_class, exception.class
179
+ assert_match(/CollectionSerializer#paginated\?/, exception.message)
180
+ end
181
+
182
+ def test_pagination_links_not_present_when_disabled
183
+ ActiveModel::Serializer.config.jsonapi_pagination_links_enabled = false
184
+ adapter = load_adapter(using_kaminari, mock_request)
185
+
161
186
  assert_equal expected_response_without_pagination_links, adapter.serializable_hash
187
+ ensure
188
+ ActiveModel::Serializer.config.jsonapi_pagination_links_enabled = true
162
189
  end
163
190
  end
164
191
  end