active_model_serializers 0.10.3 → 0.10.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +154 -2
- data/README.md +153 -15
- data/lib/action_controller/serialization.rb +11 -1
- data/lib/active_model/serializable_resource.rb +2 -0
- data/lib/active_model/serializer.rb +275 -81
- data/lib/active_model/serializer/adapter.rb +2 -0
- data/lib/active_model/serializer/adapter/attributes.rb +2 -0
- data/lib/active_model/serializer/adapter/base.rb +2 -0
- data/lib/active_model/serializer/adapter/json.rb +2 -0
- data/lib/active_model/serializer/adapter/json_api.rb +2 -0
- data/lib/active_model/serializer/adapter/null.rb +2 -0
- data/lib/active_model/serializer/array_serializer.rb +2 -0
- data/lib/active_model/serializer/association.rb +53 -14
- data/lib/active_model/serializer/attribute.rb +2 -0
- data/lib/active_model/serializer/belongs_to_reflection.rb +7 -1
- data/lib/active_model/serializer/collection_serializer.rb +8 -5
- data/lib/active_model/serializer/concerns/caching.rb +36 -23
- data/lib/active_model/serializer/error_serializer.rb +2 -0
- data/lib/active_model/serializer/errors_serializer.rb +2 -0
- data/lib/active_model/serializer/field.rb +2 -0
- data/lib/active_model/serializer/fieldset.rb +3 -1
- data/lib/active_model/serializer/has_many_reflection.rb +6 -1
- data/lib/active_model/serializer/has_one_reflection.rb +3 -1
- data/lib/active_model/serializer/lazy_association.rb +99 -0
- data/lib/active_model/serializer/link.rb +23 -0
- data/lib/active_model/serializer/lint.rb +2 -0
- data/lib/active_model/serializer/null.rb +2 -0
- data/lib/active_model/serializer/reflection.rb +122 -73
- data/lib/active_model/serializer/version.rb +3 -1
- data/lib/active_model_serializers.rb +29 -11
- data/lib/active_model_serializers/adapter.rb +3 -1
- data/lib/active_model_serializers/adapter/attributes.rb +23 -0
- data/lib/active_model_serializers/adapter/base.rb +4 -2
- data/lib/active_model_serializers/adapter/json.rb +2 -0
- data/lib/active_model_serializers/adapter/json_api.rb +44 -26
- data/lib/active_model_serializers/adapter/json_api/deserialization.rb +4 -2
- data/lib/active_model_serializers/adapter/json_api/error.rb +2 -0
- data/lib/active_model_serializers/adapter/json_api/jsonapi.rb +2 -0
- data/lib/active_model_serializers/adapter/json_api/link.rb +2 -0
- data/lib/active_model_serializers/adapter/json_api/meta.rb +2 -0
- data/lib/active_model_serializers/adapter/json_api/pagination_links.rb +42 -21
- data/lib/active_model_serializers/adapter/json_api/relationship.rb +52 -9
- data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +35 -18
- data/lib/active_model_serializers/adapter/null.rb +2 -0
- data/lib/active_model_serializers/callbacks.rb +2 -0
- data/lib/active_model_serializers/deprecate.rb +2 -0
- data/lib/active_model_serializers/deserialization.rb +2 -0
- data/lib/active_model_serializers/json_pointer.rb +2 -0
- data/lib/active_model_serializers/logging.rb +2 -0
- data/lib/active_model_serializers/lookup_chain.rb +2 -0
- data/lib/active_model_serializers/model.rb +111 -30
- data/lib/active_model_serializers/model/caching.rb +25 -0
- data/lib/active_model_serializers/railtie.rb +4 -0
- data/lib/active_model_serializers/register_jsonapi_renderer.rb +2 -0
- data/lib/active_model_serializers/serializable_resource.rb +4 -2
- data/lib/active_model_serializers/serialization_context.rb +2 -0
- data/lib/active_model_serializers/test.rb +2 -0
- data/lib/active_model_serializers/test/schema.rb +4 -2
- data/lib/active_model_serializers/test/serializer.rb +2 -0
- data/lib/generators/rails/resource_override.rb +3 -1
- data/lib/generators/rails/serializer_generator.rb +2 -0
- data/lib/grape/active_model_serializers.rb +2 -0
- data/lib/grape/formatters/active_model_serializers.rb +2 -0
- data/lib/grape/helpers/active_model_serializers.rb +2 -0
- data/lib/tasks/rubocop.rake +55 -0
- metadata +74 -291
- data/.github/ISSUE_TEMPLATE.md +0 -29
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -15
- data/.gitignore +0 -35
- data/.rubocop.yml +0 -102
- data/.simplecov +0 -110
- data/.travis.yml +0 -51
- data/CODE_OF_CONDUCT.md +0 -74
- data/CONTRIBUTING.md +0 -105
- data/Gemfile +0 -56
- data/Rakefile +0 -103
- data/active_model_serializers.gemspec +0 -62
- data/appveyor.yml +0 -24
- data/bin/bench +0 -171
- data/bin/bench_regression +0 -316
- data/bin/serve_benchmark +0 -39
- data/docs/ARCHITECTURE.md +0 -125
- data/docs/README.md +0 -42
- data/docs/STYLE.md +0 -58
- data/docs/general/adapters.md +0 -247
- data/docs/general/caching.md +0 -58
- data/docs/general/configuration_options.md +0 -169
- data/docs/general/deserialization.md +0 -100
- data/docs/general/fields.md +0 -31
- data/docs/general/getting_started.md +0 -133
- data/docs/general/instrumentation.md +0 -40
- data/docs/general/key_transforms.md +0 -40
- data/docs/general/logging.md +0 -14
- data/docs/general/rendering.md +0 -294
- data/docs/general/serializers.md +0 -461
- data/docs/how-open-source-maintained.jpg +0 -0
- data/docs/howto/add_pagination_links.md +0 -138
- data/docs/howto/add_relationship_links.md +0 -137
- data/docs/howto/add_root_key.md +0 -55
- data/docs/howto/grape_integration.md +0 -42
- data/docs/howto/outside_controller_use.md +0 -65
- data/docs/howto/passing_arbitrary_options.md +0 -27
- data/docs/howto/serialize_poro.md +0 -32
- data/docs/howto/test.md +0 -154
- data/docs/howto/upgrade_from_0_8_to_0_10.md +0 -265
- data/docs/integrations/ember-and-json-api.md +0 -144
- data/docs/integrations/grape.md +0 -19
- data/docs/jsonapi/errors.md +0 -56
- data/docs/jsonapi/schema.md +0 -151
- data/docs/jsonapi/schema/schema.json +0 -366
- data/docs/rfcs/0000-namespace.md +0 -106
- data/docs/rfcs/template.md +0 -15
- data/lib/active_model/serializer/collection_reflection.rb +0 -7
- data/lib/active_model/serializer/concerns/associations.rb +0 -102
- data/lib/active_model/serializer/concerns/attributes.rb +0 -82
- data/lib/active_model/serializer/concerns/configuration.rb +0 -59
- data/lib/active_model/serializer/concerns/links.rb +0 -35
- data/lib/active_model/serializer/concerns/meta.rb +0 -29
- data/lib/active_model/serializer/concerns/type.rb +0 -25
- data/lib/active_model/serializer/singular_reflection.rb +0 -7
- data/lib/active_model_serializers/key_transform.rb +0 -74
- data/test/action_controller/adapter_selector_test.rb +0 -53
- data/test/action_controller/explicit_serializer_test.rb +0 -135
- data/test/action_controller/json/include_test.rb +0 -246
- data/test/action_controller/json_api/deserialization_test.rb +0 -112
- data/test/action_controller/json_api/errors_test.rb +0 -40
- data/test/action_controller/json_api/fields_test.rb +0 -57
- data/test/action_controller/json_api/linked_test.rb +0 -202
- data/test/action_controller/json_api/pagination_test.rb +0 -116
- data/test/action_controller/json_api/transform_test.rb +0 -181
- data/test/action_controller/lookup_proc_test.rb +0 -49
- data/test/action_controller/namespace_lookup_test.rb +0 -226
- data/test/action_controller/serialization_scope_name_test.rb +0 -229
- data/test/action_controller/serialization_test.rb +0 -472
- data/test/active_model_serializers/adapter_for_test.rb +0 -208
- data/test/active_model_serializers/json_pointer_test.rb +0 -22
- data/test/active_model_serializers/key_transform_test.rb +0 -297
- data/test/active_model_serializers/logging_test.rb +0 -77
- data/test/active_model_serializers/model_test.rb +0 -22
- data/test/active_model_serializers/railtie_test_isolated.rb +0 -63
- data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +0 -143
- data/test/active_model_serializers/serialization_context_test_isolated.rb +0 -71
- data/test/active_model_serializers/test/schema_test.rb +0 -130
- data/test/active_model_serializers/test/serializer_test.rb +0 -62
- data/test/active_record_test.rb +0 -9
- data/test/adapter/attributes_test.rb +0 -43
- data/test/adapter/deprecation_test.rb +0 -100
- data/test/adapter/json/belongs_to_test.rb +0 -45
- data/test/adapter/json/collection_test.rb +0 -104
- data/test/adapter/json/has_many_test.rb +0 -45
- data/test/adapter/json/transform_test.rb +0 -93
- data/test/adapter/json_api/belongs_to_test.rb +0 -155
- data/test/adapter/json_api/collection_test.rb +0 -96
- data/test/adapter/json_api/errors_test.rb +0 -76
- data/test/adapter/json_api/fields_test.rb +0 -88
- data/test/adapter/json_api/has_many_embed_ids_test.rb +0 -43
- data/test/adapter/json_api/has_many_explicit_serializer_test.rb +0 -96
- data/test/adapter/json_api/has_many_test.rb +0 -165
- data/test/adapter/json_api/has_one_test.rb +0 -80
- data/test/adapter/json_api/include_data_if_sideloaded_test.rb +0 -166
- data/test/adapter/json_api/json_api_test.rb +0 -33
- data/test/adapter/json_api/linked_test.rb +0 -413
- data/test/adapter/json_api/links_test.rb +0 -95
- data/test/adapter/json_api/pagination_links_test.rb +0 -193
- data/test/adapter/json_api/parse_test.rb +0 -137
- data/test/adapter/json_api/relationship_test.rb +0 -397
- data/test/adapter/json_api/resource_identifier_test.rb +0 -110
- data/test/adapter/json_api/resource_meta_test.rb +0 -100
- data/test/adapter/json_api/toplevel_jsonapi_test.rb +0 -82
- data/test/adapter/json_api/transform_test.rb +0 -504
- data/test/adapter/json_api/type_test.rb +0 -61
- data/test/adapter/json_test.rb +0 -46
- data/test/adapter/null_test.rb +0 -22
- data/test/adapter/polymorphic_test.rb +0 -171
- data/test/adapter_test.rb +0 -67
- data/test/array_serializer_test.rb +0 -22
- data/test/benchmark/app.rb +0 -65
- data/test/benchmark/benchmarking_support.rb +0 -67
- data/test/benchmark/bm_active_record.rb +0 -81
- data/test/benchmark/bm_adapter.rb +0 -38
- data/test/benchmark/bm_caching.rb +0 -119
- data/test/benchmark/bm_lookup_chain.rb +0 -83
- data/test/benchmark/bm_transform.rb +0 -45
- data/test/benchmark/config.ru +0 -3
- data/test/benchmark/controllers.rb +0 -83
- data/test/benchmark/fixtures.rb +0 -219
- data/test/cache_test.rb +0 -579
- data/test/collection_serializer_test.rb +0 -110
- data/test/fixtures/active_record.rb +0 -78
- data/test/fixtures/poro.rb +0 -286
- data/test/generators/scaffold_controller_generator_test.rb +0 -24
- data/test/generators/serializer_generator_test.rb +0 -74
- data/test/grape_test.rb +0 -178
- data/test/lint_test.rb +0 -49
- data/test/logger_test.rb +0 -20
- data/test/poro_test.rb +0 -9
- data/test/serializable_resource_test.rb +0 -79
- data/test/serializers/association_macros_test.rb +0 -37
- data/test/serializers/associations_test.rb +0 -370
- data/test/serializers/attribute_test.rb +0 -151
- data/test/serializers/attributes_test.rb +0 -52
- data/test/serializers/caching_configuration_test_isolated.rb +0 -170
- data/test/serializers/configuration_test.rb +0 -32
- data/test/serializers/fieldset_test.rb +0 -14
- data/test/serializers/meta_test.rb +0 -202
- data/test/serializers/options_test.rb +0 -21
- data/test/serializers/read_attribute_for_serialization_test.rb +0 -79
- data/test/serializers/root_test.rb +0 -21
- data/test/serializers/serialization_test.rb +0 -55
- data/test/serializers/serializer_for_test.rb +0 -136
- data/test/serializers/serializer_for_with_namespace_test.rb +0 -87
- data/test/support/custom_schemas/active_model_serializers/test/schema_test/my/index.json +0 -6
- data/test/support/isolated_unit.rb +0 -82
- data/test/support/rails5_shims.rb +0 -53
- data/test/support/rails_app.rb +0 -36
- data/test/support/schemas/active_model_serializers/test/schema_test/my/index.json +0 -6
- data/test/support/schemas/active_model_serializers/test/schema_test/my/show.json +0 -6
- data/test/support/schemas/custom/show.json +0 -7
- data/test/support/schemas/hyper_schema.json +0 -93
- data/test/support/schemas/render_using_json_api.json +0 -43
- data/test/support/schemas/simple_json_pointers.json +0 -10
- data/test/support/serialization_testing.rb +0 -71
- data/test/test_helper.rb +0 -58
@@ -1,208 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module ActiveModelSerializers
|
4
|
-
class AdapterForTest < ::ActiveSupport::TestCase
|
5
|
-
UnknownAdapterError = ::ActiveModelSerializers::Adapter::UnknownAdapterError
|
6
|
-
|
7
|
-
def test_serializer_adapter_returns_configured_adapter
|
8
|
-
assert_output(nil, /ActiveModelSerializers::Adapter.configured_adapter/) do
|
9
|
-
assert_equal ActiveModelSerializers::Adapter.configured_adapter, ActiveModel::Serializer.adapter
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_returns_default_adapter
|
14
|
-
with_adapter_config_setup do
|
15
|
-
adapter = ActiveModelSerializers::Adapter.configured_adapter
|
16
|
-
assert_equal ActiveModelSerializers::Adapter::Attributes, adapter
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_overwrite_adapter_with_symbol
|
21
|
-
with_adapter_config_setup do
|
22
|
-
ActiveModelSerializers.config.adapter = :null
|
23
|
-
|
24
|
-
adapter = ActiveModelSerializers::Adapter.configured_adapter
|
25
|
-
assert_equal ActiveModelSerializers::Adapter::Null, adapter
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_overwrite_adapter_with_camelcased_symbol
|
30
|
-
with_adapter_config_setup do
|
31
|
-
ActiveModelSerializers.config.adapter = :JsonApi
|
32
|
-
|
33
|
-
adapter = ActiveModelSerializers::Adapter.configured_adapter
|
34
|
-
assert_equal ActiveModelSerializers::Adapter::JsonApi, adapter
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_overwrite_adapter_with_string
|
39
|
-
with_adapter_config_setup do
|
40
|
-
ActiveModelSerializers.config.adapter = 'json_api'
|
41
|
-
|
42
|
-
adapter = ActiveModelSerializers::Adapter.configured_adapter
|
43
|
-
assert_equal ActiveModelSerializers::Adapter::JsonApi, adapter
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_overwrite_adapter_with_a_camelcased_string
|
48
|
-
with_adapter_config_setup do
|
49
|
-
ActiveModelSerializers.config.adapter = 'JsonApi'
|
50
|
-
|
51
|
-
adapter = ActiveModelSerializers::Adapter.configured_adapter
|
52
|
-
assert_equal ActiveModelSerializers::Adapter::JsonApi, adapter
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_overwrite_adapter_with_class
|
57
|
-
with_adapter_config_setup do
|
58
|
-
ActiveModelSerializers.config.adapter = ActiveModelSerializers::Adapter::Null
|
59
|
-
|
60
|
-
adapter = ActiveModelSerializers::Adapter.configured_adapter
|
61
|
-
assert_equal ActiveModelSerializers::Adapter::Null, adapter
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_raises_exception_if_invalid_symbol_given
|
66
|
-
with_adapter_config_setup do
|
67
|
-
ActiveModelSerializers.config.adapter = :unknown
|
68
|
-
|
69
|
-
assert_raises UnknownAdapterError do
|
70
|
-
ActiveModelSerializers::Adapter.configured_adapter
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_raises_exception_if_it_does_not_know_hot_to_infer_adapter
|
76
|
-
with_adapter_config_setup do
|
77
|
-
ActiveModelSerializers.config.adapter = 42
|
78
|
-
|
79
|
-
assert_raises UnknownAdapterError do
|
80
|
-
ActiveModelSerializers::Adapter.configured_adapter
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_adapter_class_for_known_adapter
|
86
|
-
klass = ActiveModelSerializers::Adapter.adapter_class(:json_api)
|
87
|
-
assert_equal ActiveModelSerializers::Adapter::JsonApi, klass
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_adapter_class_for_unknown_adapter
|
91
|
-
assert_raises UnknownAdapterError do
|
92
|
-
ActiveModelSerializers::Adapter.adapter_class(:json_simple)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_adapter_map
|
97
|
-
expected_adapter_map = {
|
98
|
-
'null'.freeze => ActiveModelSerializers::Adapter::Null,
|
99
|
-
'json'.freeze => ActiveModelSerializers::Adapter::Json,
|
100
|
-
'attributes'.freeze => ActiveModelSerializers::Adapter::Attributes,
|
101
|
-
'json_api'.freeze => ActiveModelSerializers::Adapter::JsonApi
|
102
|
-
}
|
103
|
-
actual = ActiveModelSerializers::Adapter.adapter_map
|
104
|
-
assert_equal actual, expected_adapter_map
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_adapters
|
108
|
-
assert_equal ActiveModelSerializers::Adapter.adapters.sort, [
|
109
|
-
'attributes'.freeze,
|
110
|
-
'json'.freeze,
|
111
|
-
'json_api'.freeze,
|
112
|
-
'null'.freeze
|
113
|
-
]
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_lookup_adapter_by_string_name
|
117
|
-
assert_equal ActiveModelSerializers::Adapter.lookup('json'.freeze), ActiveModelSerializers::Adapter::Json
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_lookup_adapter_by_symbol_name
|
121
|
-
assert_equal ActiveModelSerializers::Adapter.lookup(:json), ActiveModelSerializers::Adapter::Json
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_lookup_adapter_by_class
|
125
|
-
klass = ActiveModelSerializers::Adapter::Json
|
126
|
-
assert_equal ActiveModelSerializers::Adapter.lookup(klass), klass
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_lookup_adapter_from_environment_registers_adapter
|
130
|
-
ActiveModelSerializers::Adapter.const_set(:AdapterFromEnvironment, Class.new)
|
131
|
-
klass = ::ActiveModelSerializers::Adapter::AdapterFromEnvironment
|
132
|
-
name = 'adapter_from_environment'.freeze
|
133
|
-
assert_equal ActiveModelSerializers::Adapter.lookup(name), klass
|
134
|
-
assert ActiveModelSerializers::Adapter.adapters.include?(name)
|
135
|
-
ensure
|
136
|
-
ActiveModelSerializers::Adapter.adapter_map.delete(name)
|
137
|
-
ActiveModelSerializers::Adapter.send(:remove_const, :AdapterFromEnvironment)
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_lookup_adapter_for_unknown_name
|
141
|
-
assert_raises UnknownAdapterError do
|
142
|
-
ActiveModelSerializers::Adapter.lookup(:json_simple)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_adapter
|
147
|
-
assert_equal ActiveModelSerializers.config.adapter, :attributes
|
148
|
-
assert_equal ActiveModelSerializers::Adapter.configured_adapter, ActiveModelSerializers::Adapter::Attributes
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_register_adapter
|
152
|
-
new_adapter_name = :foo
|
153
|
-
new_adapter_klass = Class.new
|
154
|
-
ActiveModelSerializers::Adapter.register(new_adapter_name, new_adapter_klass)
|
155
|
-
assert ActiveModelSerializers::Adapter.adapters.include?('foo'.freeze)
|
156
|
-
assert ActiveModelSerializers::Adapter.lookup(:foo), new_adapter_klass
|
157
|
-
ensure
|
158
|
-
ActiveModelSerializers::Adapter.adapter_map.delete(new_adapter_name.to_s)
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_inherited_adapter_hooks_register_adapter
|
162
|
-
Object.const_set(:MyAdapter, Class.new)
|
163
|
-
my_adapter = MyAdapter
|
164
|
-
ActiveModelSerializers::Adapter::Base.inherited(my_adapter)
|
165
|
-
assert_equal ActiveModelSerializers::Adapter.lookup(:my_adapter), my_adapter
|
166
|
-
ensure
|
167
|
-
ActiveModelSerializers::Adapter.adapter_map.delete('my_adapter'.freeze)
|
168
|
-
Object.send(:remove_const, :MyAdapter)
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_inherited_adapter_hooks_register_namespaced_adapter
|
172
|
-
Object.const_set(:MyNamespace, Module.new)
|
173
|
-
MyNamespace.const_set(:MyAdapter, Class.new)
|
174
|
-
my_adapter = MyNamespace::MyAdapter
|
175
|
-
ActiveModelSerializers::Adapter::Base.inherited(my_adapter)
|
176
|
-
assert_equal ActiveModelSerializers::Adapter.lookup(:'my_namespace/my_adapter'), my_adapter
|
177
|
-
ensure
|
178
|
-
ActiveModelSerializers::Adapter.adapter_map.delete('my_namespace/my_adapter'.freeze)
|
179
|
-
MyNamespace.send(:remove_const, :MyAdapter)
|
180
|
-
Object.send(:remove_const, :MyNamespace)
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_inherited_adapter_hooks_register_subclass_of_registered_adapter
|
184
|
-
Object.const_set(:MyAdapter, Class.new)
|
185
|
-
my_adapter = MyAdapter
|
186
|
-
Object.const_set(:MySubclassedAdapter, Class.new(MyAdapter))
|
187
|
-
my_subclassed_adapter = MySubclassedAdapter
|
188
|
-
ActiveModelSerializers::Adapter::Base.inherited(my_adapter)
|
189
|
-
ActiveModelSerializers::Adapter::Base.inherited(my_subclassed_adapter)
|
190
|
-
assert_equal ActiveModelSerializers::Adapter.lookup(:my_adapter), my_adapter
|
191
|
-
assert_equal ActiveModelSerializers::Adapter.lookup(:my_subclassed_adapter), my_subclassed_adapter
|
192
|
-
ensure
|
193
|
-
ActiveModelSerializers::Adapter.adapter_map.delete('my_adapter'.freeze)
|
194
|
-
ActiveModelSerializers::Adapter.adapter_map.delete('my_subclassed_adapter'.freeze)
|
195
|
-
Object.send(:remove_const, :MyAdapter)
|
196
|
-
Object.send(:remove_const, :MySubclassedAdapter)
|
197
|
-
end
|
198
|
-
|
199
|
-
private
|
200
|
-
|
201
|
-
def with_adapter_config_setup
|
202
|
-
previous_adapter = ActiveModelSerializers.config.adapter
|
203
|
-
yield
|
204
|
-
ensure
|
205
|
-
ActiveModelSerializers.config.adapter = previous_adapter
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module ActiveModelSerializers
|
4
|
-
class JsonPointerTest < ActiveSupport::TestCase
|
5
|
-
def test_attribute_pointer
|
6
|
-
attribute_name = 'title'
|
7
|
-
pointer = ActiveModelSerializers::JsonPointer.new(:attribute, attribute_name)
|
8
|
-
assert_equal '/data/attributes/title', pointer
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_primary_data_pointer
|
12
|
-
pointer = ActiveModelSerializers::JsonPointer.new(:primary_data)
|
13
|
-
assert_equal '/data', pointer
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_unkown_data_pointer
|
17
|
-
assert_raises(TypeError) do
|
18
|
-
ActiveModelSerializers::JsonPointer.new(:unknown)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,297 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module ActiveModelSerializers
|
4
|
-
class KeyTransformTest < ActiveSupport::TestCase
|
5
|
-
def test_camel
|
6
|
-
obj = Object.new
|
7
|
-
scenarios = [
|
8
|
-
{
|
9
|
-
value: { :"some-key" => 'value' },
|
10
|
-
expected: { SomeKey: 'value' }
|
11
|
-
},
|
12
|
-
{
|
13
|
-
value: { someKey: 'value' },
|
14
|
-
expected: { SomeKey: 'value' }
|
15
|
-
},
|
16
|
-
{
|
17
|
-
value: { some_key: 'value' },
|
18
|
-
expected: { SomeKey: 'value' }
|
19
|
-
},
|
20
|
-
{
|
21
|
-
value: { 'some-key' => 'value' },
|
22
|
-
expected: { 'SomeKey' => 'value' }
|
23
|
-
},
|
24
|
-
{
|
25
|
-
value: { 'someKey' => 'value' },
|
26
|
-
expected: { 'SomeKey' => 'value' }
|
27
|
-
},
|
28
|
-
{
|
29
|
-
value: { 'some_key' => 'value' },
|
30
|
-
expected: { 'SomeKey' => 'value' }
|
31
|
-
},
|
32
|
-
{
|
33
|
-
value: :"some-value",
|
34
|
-
expected: :SomeValue
|
35
|
-
},
|
36
|
-
{
|
37
|
-
value: :some_value,
|
38
|
-
expected: :SomeValue
|
39
|
-
},
|
40
|
-
{
|
41
|
-
value: :someValue,
|
42
|
-
expected: :SomeValue
|
43
|
-
},
|
44
|
-
{
|
45
|
-
value: 'some-value',
|
46
|
-
expected: 'SomeValue'
|
47
|
-
},
|
48
|
-
{
|
49
|
-
value: 'someValue',
|
50
|
-
expected: 'SomeValue'
|
51
|
-
},
|
52
|
-
{
|
53
|
-
value: 'some_value',
|
54
|
-
expected: 'SomeValue'
|
55
|
-
},
|
56
|
-
{
|
57
|
-
value: obj,
|
58
|
-
expected: obj
|
59
|
-
},
|
60
|
-
{
|
61
|
-
value: nil,
|
62
|
-
expected: nil
|
63
|
-
},
|
64
|
-
{
|
65
|
-
value: [
|
66
|
-
{ some_value: 'value' }
|
67
|
-
],
|
68
|
-
expected: [
|
69
|
-
{ SomeValue: 'value' }
|
70
|
-
]
|
71
|
-
}
|
72
|
-
]
|
73
|
-
scenarios.each do |s|
|
74
|
-
result = ActiveModelSerializers::KeyTransform.camel(s[:value])
|
75
|
-
assert_equal s[:expected], result
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_camel_lower
|
80
|
-
obj = Object.new
|
81
|
-
scenarios = [
|
82
|
-
{
|
83
|
-
value: { :"some-key" => 'value' },
|
84
|
-
expected: { someKey: 'value' }
|
85
|
-
},
|
86
|
-
{
|
87
|
-
value: { SomeKey: 'value' },
|
88
|
-
expected: { someKey: 'value' }
|
89
|
-
},
|
90
|
-
{
|
91
|
-
value: { some_key: 'value' },
|
92
|
-
expected: { someKey: 'value' }
|
93
|
-
},
|
94
|
-
{
|
95
|
-
value: { 'some-key' => 'value' },
|
96
|
-
expected: { 'someKey' => 'value' }
|
97
|
-
},
|
98
|
-
{
|
99
|
-
value: { 'SomeKey' => 'value' },
|
100
|
-
expected: { 'someKey' => 'value' }
|
101
|
-
},
|
102
|
-
{
|
103
|
-
value: { 'some_key' => 'value' },
|
104
|
-
expected: { 'someKey' => 'value' }
|
105
|
-
},
|
106
|
-
{
|
107
|
-
value: :"some-value",
|
108
|
-
expected: :someValue
|
109
|
-
},
|
110
|
-
{
|
111
|
-
value: :SomeValue,
|
112
|
-
expected: :someValue
|
113
|
-
},
|
114
|
-
{
|
115
|
-
value: :some_value,
|
116
|
-
expected: :someValue
|
117
|
-
},
|
118
|
-
{
|
119
|
-
value: 'some-value',
|
120
|
-
expected: 'someValue'
|
121
|
-
},
|
122
|
-
{
|
123
|
-
value: 'SomeValue',
|
124
|
-
expected: 'someValue'
|
125
|
-
},
|
126
|
-
{
|
127
|
-
value: 'some_value',
|
128
|
-
expected: 'someValue'
|
129
|
-
},
|
130
|
-
{
|
131
|
-
value: obj,
|
132
|
-
expected: obj
|
133
|
-
},
|
134
|
-
{
|
135
|
-
value: nil,
|
136
|
-
expected: nil
|
137
|
-
},
|
138
|
-
{
|
139
|
-
value: [
|
140
|
-
{ some_value: 'value' }
|
141
|
-
],
|
142
|
-
expected: [
|
143
|
-
{ someValue: 'value' }
|
144
|
-
]
|
145
|
-
}
|
146
|
-
]
|
147
|
-
scenarios.each do |s|
|
148
|
-
result = ActiveModelSerializers::KeyTransform.camel_lower(s[:value])
|
149
|
-
assert_equal s[:expected], result
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_dash
|
154
|
-
obj = Object.new
|
155
|
-
scenarios = [
|
156
|
-
{
|
157
|
-
value: { some_key: 'value' },
|
158
|
-
expected: { :"some-key" => 'value' }
|
159
|
-
},
|
160
|
-
{
|
161
|
-
value: { 'some_key' => 'value' },
|
162
|
-
expected: { 'some-key' => 'value' }
|
163
|
-
},
|
164
|
-
{
|
165
|
-
value: { SomeKey: 'value' },
|
166
|
-
expected: { :"some-key" => 'value' }
|
167
|
-
},
|
168
|
-
{
|
169
|
-
value: { 'SomeKey' => 'value' },
|
170
|
-
expected: { 'some-key' => 'value' }
|
171
|
-
},
|
172
|
-
{
|
173
|
-
value: { someKey: 'value' },
|
174
|
-
expected: { :"some-key" => 'value' }
|
175
|
-
},
|
176
|
-
{
|
177
|
-
value: { 'someKey' => 'value' },
|
178
|
-
expected: { 'some-key' => 'value' }
|
179
|
-
},
|
180
|
-
{
|
181
|
-
value: :some_value,
|
182
|
-
expected: :"some-value"
|
183
|
-
},
|
184
|
-
{
|
185
|
-
value: :SomeValue,
|
186
|
-
expected: :"some-value"
|
187
|
-
},
|
188
|
-
{
|
189
|
-
value: 'SomeValue',
|
190
|
-
expected: 'some-value'
|
191
|
-
},
|
192
|
-
{
|
193
|
-
value: :someValue,
|
194
|
-
expected: :"some-value"
|
195
|
-
},
|
196
|
-
{
|
197
|
-
value: 'someValue',
|
198
|
-
expected: 'some-value'
|
199
|
-
},
|
200
|
-
{
|
201
|
-
value: obj,
|
202
|
-
expected: obj
|
203
|
-
},
|
204
|
-
{
|
205
|
-
value: nil,
|
206
|
-
expected: nil
|
207
|
-
},
|
208
|
-
{
|
209
|
-
value: [
|
210
|
-
{ 'some_value' => 'value' }
|
211
|
-
],
|
212
|
-
expected: [
|
213
|
-
{ 'some-value' => 'value' }
|
214
|
-
]
|
215
|
-
}
|
216
|
-
]
|
217
|
-
scenarios.each do |s|
|
218
|
-
result = ActiveModelSerializers::KeyTransform.dash(s[:value])
|
219
|
-
assert_equal s[:expected], result
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
def test_underscore
|
224
|
-
obj = Object.new
|
225
|
-
scenarios = [
|
226
|
-
{
|
227
|
-
value: { :"some-key" => 'value' },
|
228
|
-
expected: { some_key: 'value' }
|
229
|
-
},
|
230
|
-
{
|
231
|
-
value: { 'some-key' => 'value' },
|
232
|
-
expected: { 'some_key' => 'value' }
|
233
|
-
},
|
234
|
-
{
|
235
|
-
value: { SomeKey: 'value' },
|
236
|
-
expected: { some_key: 'value' }
|
237
|
-
},
|
238
|
-
{
|
239
|
-
value: { 'SomeKey' => 'value' },
|
240
|
-
expected: { 'some_key' => 'value' }
|
241
|
-
},
|
242
|
-
{
|
243
|
-
value: { someKey: 'value' },
|
244
|
-
expected: { some_key: 'value' }
|
245
|
-
},
|
246
|
-
{
|
247
|
-
value: { 'someKey' => 'value' },
|
248
|
-
expected: { 'some_key' => 'value' }
|
249
|
-
},
|
250
|
-
{
|
251
|
-
value: :"some-value",
|
252
|
-
expected: :some_value
|
253
|
-
},
|
254
|
-
{
|
255
|
-
value: :SomeValue,
|
256
|
-
expected: :some_value
|
257
|
-
},
|
258
|
-
{
|
259
|
-
value: :someValue,
|
260
|
-
expected: :some_value
|
261
|
-
},
|
262
|
-
{
|
263
|
-
value: 'some-value',
|
264
|
-
expected: 'some_value'
|
265
|
-
},
|
266
|
-
{
|
267
|
-
value: 'SomeValue',
|
268
|
-
expected: 'some_value'
|
269
|
-
},
|
270
|
-
{
|
271
|
-
value: 'someValue',
|
272
|
-
expected: 'some_value'
|
273
|
-
},
|
274
|
-
{
|
275
|
-
value: obj,
|
276
|
-
expected: obj
|
277
|
-
},
|
278
|
-
{
|
279
|
-
value: nil,
|
280
|
-
expected: nil
|
281
|
-
},
|
282
|
-
{
|
283
|
-
value: [
|
284
|
-
{ 'some-value' => 'value' }
|
285
|
-
],
|
286
|
-
expected: [
|
287
|
-
{ 'some_value' => 'value' }
|
288
|
-
]
|
289
|
-
}
|
290
|
-
]
|
291
|
-
scenarios.each do |s|
|
292
|
-
result = ActiveModelSerializers::KeyTransform.underscore(s[:value])
|
293
|
-
assert_equal s[:expected], result
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|