active_model_serializers 0.10.9 → 0.10.13

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 (161) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -2
  3. data/README.md +18 -19
  4. data/lib/action_controller/serialization.rb +9 -1
  5. data/lib/active_model/serializer/collection_serializer.rb +11 -2
  6. data/lib/active_model/serializer/concerns/caching.rb +2 -1
  7. data/lib/active_model/serializer/fieldset.rb +1 -1
  8. data/lib/active_model/serializer/reflection.rb +4 -4
  9. data/lib/active_model/serializer/version.rb +1 -1
  10. data/lib/active_model/serializer.rb +13 -4
  11. data/lib/active_model_serializers/adapter/attributes.rb +21 -0
  12. data/lib/active_model_serializers/adapter/json_api/pagination_links.rb +5 -1
  13. data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +1 -1
  14. data/lib/active_model_serializers/model/caching.rb +26 -0
  15. metadata +20 -292
  16. data/.github/ISSUE_TEMPLATE.md +0 -29
  17. data/.github/PULL_REQUEST_TEMPLATE.md +0 -15
  18. data/.gitignore +0 -35
  19. data/.rubocop.yml +0 -109
  20. data/.simplecov +0 -110
  21. data/.travis.yml +0 -63
  22. data/CODE_OF_CONDUCT.md +0 -74
  23. data/CONTRIBUTING.md +0 -105
  24. data/Gemfile +0 -74
  25. data/Rakefile +0 -76
  26. data/active_model_serializers.gemspec +0 -64
  27. data/appveyor.yml +0 -28
  28. data/bin/bench +0 -171
  29. data/bin/bench_regression +0 -316
  30. data/bin/rubocop +0 -38
  31. data/bin/serve_benchmark +0 -39
  32. data/docs/README.md +0 -41
  33. data/docs/STYLE.md +0 -58
  34. data/docs/general/adapters.md +0 -269
  35. data/docs/general/caching.md +0 -58
  36. data/docs/general/configuration_options.md +0 -185
  37. data/docs/general/deserialization.md +0 -100
  38. data/docs/general/fields.md +0 -31
  39. data/docs/general/getting_started.md +0 -133
  40. data/docs/general/instrumentation.md +0 -40
  41. data/docs/general/key_transforms.md +0 -40
  42. data/docs/general/logging.md +0 -21
  43. data/docs/general/rendering.md +0 -293
  44. data/docs/general/serializers.md +0 -495
  45. data/docs/how-open-source-maintained.jpg +0 -0
  46. data/docs/howto/add_pagination_links.md +0 -138
  47. data/docs/howto/add_relationship_links.md +0 -140
  48. data/docs/howto/add_root_key.md +0 -62
  49. data/docs/howto/grape_integration.md +0 -42
  50. data/docs/howto/outside_controller_use.md +0 -66
  51. data/docs/howto/passing_arbitrary_options.md +0 -27
  52. data/docs/howto/serialize_poro.md +0 -73
  53. data/docs/howto/test.md +0 -154
  54. data/docs/howto/upgrade_from_0_8_to_0_10.md +0 -265
  55. data/docs/integrations/ember-and-json-api.md +0 -147
  56. data/docs/integrations/grape.md +0 -19
  57. data/docs/jsonapi/errors.md +0 -56
  58. data/docs/jsonapi/schema/schema.json +0 -366
  59. data/docs/jsonapi/schema.md +0 -151
  60. data/docs/rfcs/0000-namespace.md +0 -106
  61. data/docs/rfcs/template.md +0 -15
  62. data/test/action_controller/adapter_selector_test.rb +0 -64
  63. data/test/action_controller/explicit_serializer_test.rb +0 -137
  64. data/test/action_controller/json/include_test.rb +0 -248
  65. data/test/action_controller/json_api/deserialization_test.rb +0 -114
  66. data/test/action_controller/json_api/errors_test.rb +0 -42
  67. data/test/action_controller/json_api/fields_test.rb +0 -68
  68. data/test/action_controller/json_api/linked_test.rb +0 -204
  69. data/test/action_controller/json_api/pagination_test.rb +0 -126
  70. data/test/action_controller/json_api/transform_test.rb +0 -191
  71. data/test/action_controller/lookup_proc_test.rb +0 -51
  72. data/test/action_controller/namespace_lookup_test.rb +0 -234
  73. data/test/action_controller/serialization_scope_name_test.rb +0 -237
  74. data/test/action_controller/serialization_test.rb +0 -480
  75. data/test/active_model_serializers/adapter_for_test.rb +0 -210
  76. data/test/active_model_serializers/json_pointer_test.rb +0 -24
  77. data/test/active_model_serializers/logging_test.rb +0 -79
  78. data/test/active_model_serializers/model_test.rb +0 -144
  79. data/test/active_model_serializers/railtie_test_isolated.rb +0 -70
  80. data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +0 -163
  81. data/test/active_model_serializers/serialization_context_test_isolated.rb +0 -73
  82. data/test/active_model_serializers/test/schema_test.rb +0 -133
  83. data/test/active_model_serializers/test/serializer_test.rb +0 -64
  84. data/test/active_record_test.rb +0 -11
  85. data/test/adapter/attributes_test.rb +0 -42
  86. data/test/adapter/deprecation_test.rb +0 -102
  87. data/test/adapter/json/belongs_to_test.rb +0 -47
  88. data/test/adapter/json/collection_test.rb +0 -106
  89. data/test/adapter/json/has_many_test.rb +0 -55
  90. data/test/adapter/json/transform_test.rb +0 -95
  91. data/test/adapter/json_api/belongs_to_test.rb +0 -157
  92. data/test/adapter/json_api/collection_test.rb +0 -98
  93. data/test/adapter/json_api/errors_test.rb +0 -78
  94. data/test/adapter/json_api/fields_test.rb +0 -98
  95. data/test/adapter/json_api/has_many_explicit_serializer_test.rb +0 -98
  96. data/test/adapter/json_api/has_many_test.rb +0 -175
  97. data/test/adapter/json_api/has_one_test.rb +0 -82
  98. data/test/adapter/json_api/include_data_if_sideloaded_test.rb +0 -215
  99. data/test/adapter/json_api/json_api_test.rb +0 -35
  100. data/test/adapter/json_api/linked_test.rb +0 -415
  101. data/test/adapter/json_api/links_test.rb +0 -112
  102. data/test/adapter/json_api/pagination_links_test.rb +0 -208
  103. data/test/adapter/json_api/parse_test.rb +0 -139
  104. data/test/adapter/json_api/relationship_test.rb +0 -399
  105. data/test/adapter/json_api/resource_meta_test.rb +0 -102
  106. data/test/adapter/json_api/toplevel_jsonapi_test.rb +0 -84
  107. data/test/adapter/json_api/transform_test.rb +0 -514
  108. data/test/adapter/json_api/type_test.rb +0 -195
  109. data/test/adapter/json_test.rb +0 -48
  110. data/test/adapter/null_test.rb +0 -24
  111. data/test/adapter/polymorphic_test.rb +0 -220
  112. data/test/adapter_test.rb +0 -69
  113. data/test/array_serializer_test.rb +0 -24
  114. data/test/benchmark/app.rb +0 -67
  115. data/test/benchmark/benchmarking_support.rb +0 -69
  116. data/test/benchmark/bm_active_record.rb +0 -83
  117. data/test/benchmark/bm_adapter.rb +0 -40
  118. data/test/benchmark/bm_caching.rb +0 -121
  119. data/test/benchmark/bm_lookup_chain.rb +0 -85
  120. data/test/benchmark/bm_transform.rb +0 -47
  121. data/test/benchmark/config.ru +0 -3
  122. data/test/benchmark/controllers.rb +0 -85
  123. data/test/benchmark/fixtures.rb +0 -221
  124. data/test/cache_test.rb +0 -717
  125. data/test/collection_serializer_test.rb +0 -129
  126. data/test/fixtures/active_record.rb +0 -115
  127. data/test/fixtures/poro.rb +0 -227
  128. data/test/generators/scaffold_controller_generator_test.rb +0 -26
  129. data/test/generators/serializer_generator_test.rb +0 -77
  130. data/test/grape_test.rb +0 -198
  131. data/test/lint_test.rb +0 -51
  132. data/test/logger_test.rb +0 -22
  133. data/test/poro_test.rb +0 -11
  134. data/test/serializable_resource_test.rb +0 -81
  135. data/test/serializers/association_macros_test.rb +0 -39
  136. data/test/serializers/associations_test.rb +0 -520
  137. data/test/serializers/attribute_test.rb +0 -155
  138. data/test/serializers/attributes_test.rb +0 -54
  139. data/test/serializers/caching_configuration_test_isolated.rb +0 -172
  140. data/test/serializers/configuration_test.rb +0 -34
  141. data/test/serializers/fieldset_test.rb +0 -16
  142. data/test/serializers/meta_test.rb +0 -204
  143. data/test/serializers/options_test.rb +0 -34
  144. data/test/serializers/read_attribute_for_serialization_test.rb +0 -81
  145. data/test/serializers/reflection_test.rb +0 -481
  146. data/test/serializers/root_test.rb +0 -23
  147. data/test/serializers/serialization_test.rb +0 -57
  148. data/test/serializers/serializer_for_test.rb +0 -138
  149. data/test/serializers/serializer_for_with_namespace_test.rb +0 -90
  150. data/test/support/custom_schemas/active_model_serializers/test/schema_test/my/index.json +0 -6
  151. data/test/support/isolated_unit.rb +0 -86
  152. data/test/support/rails5_shims.rb +0 -55
  153. data/test/support/rails_app.rb +0 -40
  154. data/test/support/schemas/active_model_serializers/test/schema_test/my/index.json +0 -6
  155. data/test/support/schemas/active_model_serializers/test/schema_test/my/show.json +0 -6
  156. data/test/support/schemas/custom/show.json +0 -7
  157. data/test/support/schemas/hyper_schema.json +0 -93
  158. data/test/support/schemas/render_using_json_api.json +0 -43
  159. data/test/support/schemas/simple_json_pointers.json +0 -10
  160. data/test/support/serialization_testing.rb +0 -81
  161. data/test/test_helper.rb +0 -72
@@ -1,195 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- module ActiveModelSerializers
6
- module Adapter
7
- class JsonApi
8
- class TypeTest < ActiveSupport::TestCase
9
- class StringTypeSerializer < ActiveModel::Serializer
10
- attribute :name
11
- type 'profile'
12
- end
13
-
14
- class SymbolTypeSerializer < ActiveModel::Serializer
15
- attribute :name
16
- type :profile
17
- end
18
-
19
- setup do
20
- @author = Author.new(id: 1, name: 'Steve K.')
21
- end
22
-
23
- def test_config_plural
24
- with_jsonapi_inflection :plural do
25
- assert_type(@author, 'authors')
26
- end
27
- end
28
-
29
- def test_config_singular
30
- with_jsonapi_inflection :singular do
31
- assert_type(@author, 'author')
32
- end
33
- end
34
-
35
- def test_explicit_string_type_value
36
- assert_type(@author, 'profile', serializer: StringTypeSerializer)
37
- end
38
-
39
- def test_explicit_symbol_type_value
40
- assert_type(@author, 'profile', serializer: SymbolTypeSerializer)
41
- end
42
-
43
- private
44
-
45
- def assert_type(resource, expected_type, opts = {})
46
- opts = opts.reverse_merge(adapter: :json_api)
47
- hash = serializable(resource, opts).serializable_hash
48
- assert_equal(expected_type, hash.fetch(:data).fetch(:type))
49
- end
50
- end
51
- class ResourceIdentifierTest < ActiveSupport::TestCase
52
- class WithDefinedTypeSerializer < ActiveModel::Serializer
53
- type 'with_defined_types'
54
- end
55
-
56
- class WithDefinedIdSerializer < ActiveModel::Serializer
57
- def id
58
- 'special_id'
59
- end
60
- end
61
-
62
- class FragmentedSerializer < ActiveModel::Serializer
63
- cache only: :id
64
-
65
- def id
66
- 'special_id'
67
- end
68
- end
69
-
70
- setup do
71
- @model = Author.new(id: 1, name: 'Steve K.')
72
- ActionController::Base.cache_store.clear
73
- end
74
-
75
- def test_defined_type
76
- actual = with_jsonapi_inflection :plural do
77
- actual_resource_identifier_object(WithDefinedTypeSerializer, @model)
78
- end
79
- expected = { id: expected_model_id(@model), type: 'with-defined-types' }
80
- assert_equal actual, expected
81
- end
82
-
83
- def test_defined_type_not_inflected
84
- actual = with_jsonapi_inflection :singular do
85
- actual_resource_identifier_object(WithDefinedTypeSerializer, @model)
86
- end
87
- expected = { id: expected_model_id(@model), type: 'with-defined-types' }
88
- assert_equal actual, expected
89
- end
90
-
91
- def test_singular_type
92
- actual = with_jsonapi_inflection :singular do
93
- actual_resource_identifier_object(AuthorSerializer, @model)
94
- end
95
- expected = { id: expected_model_id(@model), type: 'author' }
96
- assert_equal actual, expected
97
- end
98
-
99
- def test_plural_type
100
- actual = with_jsonapi_inflection :plural do
101
- actual_resource_identifier_object(AuthorSerializer, @model)
102
- end
103
- expected = { id: expected_model_id(@model), type: 'authors' }
104
- assert_equal actual, expected
105
- end
106
-
107
- def test_type_with_namespace
108
- Object.const_set(:Admin, Module.new)
109
- model = Class.new(::Model)
110
- Admin.const_set(:PowerUser, model)
111
- serializer = Class.new(ActiveModel::Serializer)
112
- Admin.const_set(:PowerUserSerializer, serializer)
113
- with_namespace_separator '--' do
114
- admin_user = Admin::PowerUser.new
115
- serializer = Admin::PowerUserSerializer.new(admin_user)
116
- expected = {
117
- id: admin_user.id,
118
- type: 'admin--power-users'
119
- }
120
-
121
- identifier = ResourceIdentifier.new(serializer, {})
122
- actual = identifier.as_json
123
- assert_equal(expected, actual)
124
- end
125
- end
126
-
127
- def test_id_defined_on_object
128
- actual = actual_resource_identifier_object(AuthorSerializer, @model)
129
- expected = { id: @model.id.to_s, type: expected_model_type(@model) }
130
- assert_equal actual, expected
131
- end
132
-
133
- def test_blank_id
134
- model = Author.new(id: nil, name: 'Steve K.')
135
- actual = actual_resource_identifier_object(AuthorSerializer, model)
136
- expected = { type: expected_model_type(model) }
137
- assert_equal actual, expected
138
- end
139
-
140
- def test_for_type_with_id
141
- id = 1
142
- actual = ResourceIdentifier.for_type_with_id('admin_user', id, {})
143
- expected = { id: '1', type: 'admin-users' }
144
- assert_equal actual, expected
145
- end
146
-
147
- def test_for_type_with_id_given_blank_id
148
- id = ''
149
- actual = ResourceIdentifier.for_type_with_id('admin_user', id, {})
150
- expected = { type: 'admin-users' }
151
- assert_equal actual, expected
152
- end
153
-
154
- def test_for_type_with_id_inflected
155
- id = 2
156
- actual = with_jsonapi_inflection :singular do
157
- ResourceIdentifier.for_type_with_id('admin_users', id, {})
158
- end
159
- expected = { id: '2', type: 'admin-user' }
160
- assert_equal actual, expected
161
- end
162
-
163
- def test_id_defined_on_serializer
164
- actual = actual_resource_identifier_object(WithDefinedIdSerializer, @model)
165
- expected = { id: 'special_id', type: expected_model_type(@model) }
166
- assert_equal actual, expected
167
- end
168
-
169
- def test_id_defined_on_fragmented
170
- actual = actual_resource_identifier_object(FragmentedSerializer, @model)
171
- expected = { id: 'special_id', type: expected_model_type(@model) }
172
- assert_equal actual, expected
173
- end
174
-
175
- private
176
-
177
- def actual_resource_identifier_object(serializer_class, model)
178
- serializer = serializer_class.new(model)
179
- resource_identifier = ResourceIdentifier.new(serializer, nil)
180
- resource_identifier.as_json
181
- end
182
-
183
- def expected_model_type(model, inflection = ActiveModelSerializers.config.jsonapi_resource_type)
184
- with_jsonapi_inflection inflection do
185
- model.class.model_name.send(inflection)
186
- end
187
- end
188
-
189
- def expected_model_id(model)
190
- model.id.to_s
191
- end
192
- end
193
- end
194
- end
195
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- module ActiveModelSerializers
6
- module Adapter
7
- class JsonTest < ActiveSupport::TestCase
8
- def setup
9
- ActionController::Base.cache_store.clear
10
- @author = Author.new(id: 1, name: 'Steve K.')
11
- @post = Post.new(id: 1, title: 'New Post', body: 'Body')
12
- @first_comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
13
- @second_comment = Comment.new(id: 2, body: 'ZOMG ANOTHER COMMENT')
14
- @post.comments = [@first_comment, @second_comment]
15
- @first_comment.post = @post
16
- @second_comment.post = @post
17
- @post.author = @author
18
- @blog = Blog.new(id: 1, name: 'My Blog!!')
19
- @post.blog = @blog
20
-
21
- @serializer = PostSerializer.new(@post)
22
- @adapter = ActiveModelSerializers::Adapter::Json.new(@serializer)
23
- end
24
-
25
- def test_has_many
26
- assert_equal([
27
- { id: 1, body: 'ZOMG A COMMENT' },
28
- { id: 2, body: 'ZOMG ANOTHER COMMENT' }
29
- ], @adapter.serializable_hash[:post][:comments])
30
- end
31
-
32
- def test_custom_keys
33
- serializer = PostWithCustomKeysSerializer.new(@post)
34
- adapter = ActiveModelSerializers::Adapter::Json.new(serializer)
35
-
36
- assert_equal({
37
- id: 1,
38
- reviews: [
39
- { id: 1, body: 'ZOMG A COMMENT' },
40
- { id: 2, body: 'ZOMG ANOTHER COMMENT' }
41
- ],
42
- writer: { id: 1, name: 'Steve K.' },
43
- site: { id: 1, name: 'My Blog!!' }
44
- }, adapter.serializable_hash[:post])
45
- end
46
- end
47
- end
48
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- module ActiveModelSerializers
6
- module Adapter
7
- class NullTest < ActiveSupport::TestCase
8
- def setup
9
- profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
10
- serializer = ProfileSerializer.new(profile)
11
-
12
- @adapter = Null.new(serializer)
13
- end
14
-
15
- def test_serializable_hash
16
- assert_equal({}, @adapter.serializable_hash)
17
- end
18
-
19
- def test_it_returns_empty_json
20
- assert_equal('{}', @adapter.to_json)
21
- end
22
- end
23
- end
24
- end
@@ -1,220 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- module ActiveModel
6
- class Serializer
7
- module Adapter
8
- class PolymorphicTest < ActiveSupport::TestCase
9
- setup do
10
- @employee = Employee.new(id: 42, name: 'Zoop Zoopler', email: 'zoop@example.com')
11
- @picture = @employee.pictures.new(id: 1, title: 'headshot-1.jpg')
12
- @picture.imageable = @employee
13
- end
14
-
15
- def serialization(resource, adapter = :attributes)
16
- serializable(resource, adapter: adapter, serializer: PolymorphicBelongsToSerializer).as_json
17
- end
18
-
19
- def tag_serialization(adapter = :attributes)
20
- tag = PolyTag.new(id: 1, phrase: 'foo')
21
- tag.object_tags << ObjectTag.new(id: 1, poly_tag_id: 1, taggable: @employee)
22
- tag.object_tags << ObjectTag.new(id: 5, poly_tag_id: 1, taggable: @picture)
23
- serializable(tag, adapter: adapter, serializer: PolymorphicTagSerializer, include: '*.*').as_json
24
- end
25
-
26
- def test_attributes_serialization
27
- expected =
28
- {
29
- id: 1,
30
- title: 'headshot-1.jpg',
31
- imageable: {
32
- type: 'employee',
33
- employee: {
34
- id: 42,
35
- name: 'Zoop Zoopler'
36
- }
37
- }
38
- }
39
-
40
- assert_equal(expected, serialization(@picture))
41
- end
42
-
43
- def test_attributes_serialization_without_polymorphic_association
44
- expected =
45
- {
46
- id: 2,
47
- title: 'headshot-2.jpg',
48
- imageable: nil
49
- }
50
-
51
- simple_picture = Picture.new(id: 2, title: 'headshot-2.jpg')
52
- assert_equal(expected, serialization(simple_picture))
53
- end
54
-
55
- def test_attributes_serialization_with_polymorphic_has_many
56
- expected =
57
- {
58
- id: 1,
59
- phrase: 'foo',
60
- object_tags: [
61
- {
62
- id: 1,
63
- taggable: {
64
- type: 'employee',
65
- employee: {
66
- id: 42
67
- }
68
- }
69
- },
70
- {
71
- id: 5,
72
- taggable: {
73
- type: 'picture',
74
- picture: {
75
- id: 1
76
- }
77
- }
78
- }
79
- ]
80
- }
81
- assert_equal(expected, tag_serialization)
82
- end
83
-
84
- def test_json_serialization
85
- expected =
86
- {
87
- picture: {
88
- id: 1,
89
- title: 'headshot-1.jpg',
90
- imageable: {
91
- type: 'employee',
92
- employee: {
93
- id: 42,
94
- name: 'Zoop Zoopler'
95
- }
96
- }
97
- }
98
- }
99
-
100
- assert_equal(expected, serialization(@picture, :json))
101
- end
102
-
103
- def test_json_serialization_without_polymorphic_association
104
- expected =
105
- {
106
- picture: {
107
- id: 2,
108
- title: 'headshot-2.jpg',
109
- imageable: nil
110
- }
111
- }
112
-
113
- simple_picture = Picture.new(id: 2, title: 'headshot-2.jpg')
114
- assert_equal(expected, serialization(simple_picture, :json))
115
- end
116
-
117
- def test_json_serialization_with_polymorphic_has_many
118
- expected =
119
- {
120
- poly_tag: {
121
- id: 1,
122
- phrase: 'foo',
123
- object_tags: [
124
- {
125
- id: 1,
126
- taggable: {
127
- type: 'employee',
128
- employee: {
129
- id: 42
130
- }
131
- }
132
- },
133
- {
134
- id: 5,
135
- taggable: {
136
- type: 'picture',
137
- picture: {
138
- id: 1
139
- }
140
- }
141
- }
142
- ]
143
- }
144
- }
145
- assert_equal(expected, tag_serialization(:json))
146
- end
147
-
148
- def test_json_api_serialization
149
- expected =
150
- {
151
- data: {
152
- id: '1',
153
- type: 'pictures',
154
- attributes: {
155
- title: 'headshot-1.jpg'
156
- },
157
- relationships: {
158
- imageable: {
159
- data: {
160
- id: '42',
161
- type: 'employees'
162
- }
163
- }
164
- }
165
- }
166
- }
167
-
168
- assert_equal(expected, serialization(@picture, :json_api))
169
- end
170
-
171
- def test_json_api_serialization_with_polymorphic_belongs_to
172
- expected = {
173
- data: {
174
- id: '1',
175
- type: 'poly-tags',
176
- attributes: { phrase: 'foo' },
177
- relationships: {
178
- :"object-tags" => {
179
- data: [
180
- { id: '1', type: 'object-tags' },
181
- { id: '5', type: 'object-tags' }
182
- ]
183
- }
184
- }
185
- },
186
- included: [
187
- {
188
- id: '1',
189
- type: 'object-tags',
190
- relationships: {
191
- taggable: {
192
- data: { id: '42', type: 'employees' }
193
- }
194
- }
195
- },
196
- {
197
- id: '42',
198
- type: 'employees'
199
- },
200
- {
201
- id: '5',
202
- type: 'object-tags',
203
- relationships: {
204
- taggable: {
205
- data: { id: '1', type: 'pictures' }
206
- }
207
- }
208
- },
209
- {
210
- id: '1',
211
- type: 'pictures'
212
- }
213
- ]
214
- }
215
- assert_equal(expected, tag_serialization(:json_api))
216
- end
217
- end
218
- end
219
- end
220
- end
data/test/adapter_test.rb DELETED
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- module ActiveModelSerializers
6
- class AdapterTest < ActiveSupport::TestCase
7
- def setup
8
- profile = Profile.new
9
- @serializer = ProfileSerializer.new(profile)
10
- @adapter = ActiveModelSerializers::Adapter::Base.new(@serializer)
11
- end
12
-
13
- def test_serializable_hash_is_abstract_method
14
- assert_raises(NotImplementedError) do
15
- @adapter.serializable_hash(only: [:name])
16
- end
17
- end
18
-
19
- def test_serialization_options_ensures_option_is_a_hash
20
- adapter = Class.new(ActiveModelSerializers::Adapter::Base) do
21
- def serializable_hash(options = nil)
22
- serialization_options(options)
23
- end
24
- end.new(@serializer)
25
- assert_equal({}, adapter.serializable_hash(nil))
26
- assert_equal({}, adapter.serializable_hash({}))
27
- ensure
28
- ActiveModelSerializers::Adapter.adapter_map.delete_if { |k, _| k =~ /class/ }
29
- end
30
-
31
- def test_serialization_options_ensures_option_is_one_of_valid_options
32
- adapter = Class.new(ActiveModelSerializers::Adapter::Base) do
33
- def serializable_hash(options = nil)
34
- serialization_options(options)
35
- end
36
- end.new(@serializer)
37
- filtered_options = { now: :see_me, then: :not }
38
- valid_options = ActiveModel::Serializer::SERIALIZABLE_HASH_VALID_KEYS.each_with_object({}) do |option, result|
39
- result[option] = option
40
- end
41
- assert_equal(valid_options, adapter.serializable_hash(filtered_options.merge(valid_options)))
42
- ensure
43
- ActiveModelSerializers::Adapter.adapter_map.delete_if { |k, _| k =~ /class/ }
44
- end
45
-
46
- def test_serializer
47
- assert_equal @serializer, @adapter.serializer
48
- end
49
-
50
- def test_create_adapter
51
- adapter = ActiveModelSerializers::Adapter.create(@serializer)
52
- assert_equal ActiveModelSerializers::Adapter::Attributes, adapter.class
53
- end
54
-
55
- def test_create_adapter_with_override
56
- adapter = ActiveModelSerializers::Adapter.create(@serializer, adapter: :json_api)
57
- assert_equal ActiveModelSerializers::Adapter::JsonApi, adapter.class
58
- end
59
-
60
- def test_inflected_adapter_class_for_known_adapter
61
- ActiveSupport::Inflector.inflections(:en) { |inflect| inflect.acronym 'API' }
62
- klass = ActiveModelSerializers::Adapter.adapter_class(:json_api)
63
-
64
- ActiveSupport::Inflector.inflections.acronyms.clear
65
-
66
- assert_equal ActiveModelSerializers::Adapter::JsonApi, klass
67
- end
68
- end
69
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require_relative 'collection_serializer_test'
5
-
6
- module ActiveModel
7
- class Serializer
8
- class ArraySerializerTest < CollectionSerializerTest
9
- extend Minitest::Assertions
10
- def self.run_one_method(*)
11
- _, stderr = capture_io do
12
- super
13
- end
14
- if stderr !~ /NOTE: ActiveModel::Serializer::ArraySerializer.new is deprecated/
15
- fail Minitest::Assertion, stderr
16
- end
17
- end
18
-
19
- def collection_serializer
20
- ArraySerializer
21
- end
22
- end
23
- end
24
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # https://github.com/rails-api/active_model_serializers/pull/872
4
- # approx ref 792fb8a9053f8db3c562dae4f40907a582dd1720 to test against
5
- require 'bundler/setup'
6
-
7
- require 'rails'
8
- require 'active_model'
9
- require 'active_support'
10
- require 'active_support/json'
11
- require 'action_controller'
12
- require 'action_controller/test_case'
13
- require 'action_controller/railtie'
14
- abort "Rails application already defined: #{Rails.application.class}" if Rails.application
15
-
16
- class NullLogger < Logger
17
- def initialize(*_args)
18
- end
19
-
20
- def add(*_args, &_block)
21
- end
22
- end
23
- class BenchmarkLogger < ActiveSupport::Logger
24
- def initialize
25
- @file = StringIO.new
26
- super(@file)
27
- end
28
-
29
- def messages
30
- @file.rewind
31
- @file.read
32
- end
33
- end
34
- # ref: https://gist.github.com/bf4/8744473
35
- class BenchmarkApp < Rails::Application
36
- # Set up production configuration
37
- config.eager_load = true
38
- config.cache_classes = true
39
- # CONFIG: CACHE_ON={on,off}
40
- config.action_controller.perform_caching = ENV['CACHE_ON'] != 'off'
41
- config.action_controller.cache_store = ActiveSupport::Cache.lookup_store(:memory_store)
42
-
43
- config.active_support.test_order = :random
44
- config.secret_token = 'S' * 30
45
- config.secret_key_base = 'abc123'
46
- config.consider_all_requests_local = false
47
-
48
- # otherwise deadlock occurred
49
- config.middleware.delete 'Rack::Lock'
50
-
51
- # to disable log files
52
- config.logger = NullLogger.new
53
- config.active_support.deprecation = :log
54
- config.log_level = :info
55
- end
56
-
57
- require 'active_model_serializers'
58
-
59
- # Initialize app before any serializers are defined, for running across revisions.
60
- # ref: https://github.com/rails-api/active_model_serializers/pull/1478
61
- Rails.application.initialize!
62
- # HACK: Serializer::cache depends on the ActionController-dependent configs being set.
63
- ActiveSupport.on_load(:action_controller) do
64
- require_relative 'fixtures'
65
- end
66
-
67
- require_relative 'controllers'