active_model_serializers 0.10.0 → 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -4
- data/.travis.yml +9 -1
- data/CHANGELOG.md +81 -2
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -2
- data/README.md +24 -24
- data/Rakefile +3 -3
- data/active_model_serializers.gemspec +20 -24
- data/docs/ARCHITECTURE.md +6 -7
- data/docs/README.md +2 -0
- data/docs/general/adapters.md +4 -2
- data/docs/general/caching.md +7 -1
- data/docs/general/configuration_options.md +70 -1
- data/docs/general/deserialization.md +1 -1
- data/docs/general/fields.md +31 -0
- data/docs/general/rendering.md +42 -3
- data/docs/general/serializers.md +97 -8
- data/docs/howto/add_pagination_links.md +4 -5
- data/docs/howto/add_relationship_links.md +137 -0
- data/docs/howto/add_root_key.md +4 -0
- data/docs/howto/grape_integration.md +42 -0
- data/docs/howto/outside_controller_use.md +9 -2
- data/docs/howto/passing_arbitrary_options.md +2 -2
- data/docs/howto/test.md +2 -0
- data/docs/howto/upgrade_from_0_8_to_0_10.md +265 -0
- data/docs/integrations/ember-and-json-api.md +64 -32
- data/docs/jsonapi/schema.md +1 -1
- data/lib/action_controller/serialization.rb +13 -3
- data/lib/active_model/serializer/adapter/base.rb +2 -0
- data/lib/active_model/serializer/array_serializer.rb +8 -5
- data/lib/active_model/serializer/association.rb +19 -4
- data/lib/active_model/serializer/belongs_to_reflection.rb +0 -3
- data/lib/active_model/serializer/collection_serializer.rb +35 -12
- data/lib/active_model/serializer/{associations.rb → concerns/associations.rb} +13 -11
- data/lib/active_model/serializer/{attributes.rb → concerns/attributes.rb} +0 -0
- data/lib/active_model/serializer/{caching.rb → concerns/caching.rb} +72 -113
- data/lib/active_model/serializer/{configuration.rb → concerns/configuration.rb} +25 -1
- data/lib/active_model/serializer/{links.rb → concerns/links.rb} +0 -0
- data/lib/active_model/serializer/{meta.rb → concerns/meta.rb} +0 -0
- data/lib/active_model/serializer/{type.rb → concerns/type.rb} +0 -0
- data/lib/active_model/serializer/error_serializer.rb +11 -7
- data/lib/active_model/serializer/errors_serializer.rb +25 -20
- data/lib/active_model/serializer/has_many_reflection.rb +0 -3
- data/lib/active_model/serializer/has_one_reflection.rb +0 -3
- data/lib/active_model/serializer/lint.rb +134 -130
- data/lib/active_model/serializer/reflection.rb +37 -21
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model/serializer.rb +76 -37
- data/lib/active_model_serializers/adapter/attributes.rb +3 -66
- data/lib/active_model_serializers/adapter/base.rb +38 -38
- data/lib/active_model_serializers/adapter/json_api/link.rb +1 -1
- data/lib/active_model_serializers/adapter/json_api/pagination_links.rb +8 -1
- data/lib/active_model_serializers/adapter/json_api/relationship.rb +30 -19
- data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +23 -9
- data/lib/active_model_serializers/adapter/json_api.rb +44 -43
- data/lib/active_model_serializers/adapter.rb +6 -0
- data/lib/active_model_serializers/deprecate.rb +1 -2
- data/lib/active_model_serializers/deserialization.rb +2 -0
- data/lib/active_model_serializers/key_transform.rb +4 -0
- data/lib/active_model_serializers/lookup_chain.rb +80 -0
- data/lib/active_model_serializers/model.rb +4 -2
- data/lib/active_model_serializers/railtie.rb +3 -1
- data/lib/active_model_serializers/register_jsonapi_renderer.rb +44 -31
- data/lib/active_model_serializers/serializable_resource.rb +6 -5
- data/lib/active_model_serializers/serialization_context.rb +10 -3
- data/lib/active_model_serializers.rb +7 -0
- data/lib/generators/rails/serializer_generator.rb +4 -4
- data/lib/grape/active_model_serializers.rb +7 -5
- data/lib/grape/formatters/active_model_serializers.rb +19 -2
- data/lib/grape/helpers/active_model_serializers.rb +1 -0
- data/test/action_controller/adapter_selector_test.rb +4 -4
- data/test/action_controller/explicit_serializer_test.rb +5 -4
- data/test/action_controller/json/include_test.rb +106 -27
- data/test/action_controller/json_api/errors_test.rb +6 -7
- data/test/action_controller/json_api/fields_test.rb +57 -0
- data/test/action_controller/json_api/linked_test.rb +29 -24
- data/test/action_controller/json_api/pagination_test.rb +19 -19
- data/test/action_controller/json_api/transform_test.rb +3 -3
- data/test/action_controller/lookup_proc_test.rb +49 -0
- data/test/action_controller/namespace_lookup_test.rb +226 -0
- data/test/action_controller/serialization_test.rb +10 -7
- data/test/active_model_serializers/json_pointer_test.rb +15 -13
- data/test/active_model_serializers/key_transform_test.rb +286 -252
- data/test/active_model_serializers/model_test.rb +17 -4
- data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +143 -0
- data/test/active_model_serializers/serialization_context_test_isolated.rb +23 -10
- data/test/adapter/attributes_test.rb +43 -0
- data/test/adapter/json/collection_test.rb +14 -0
- data/test/adapter/json/transform_test.rb +15 -15
- data/test/adapter/json_api/collection_test.rb +4 -3
- data/test/adapter/json_api/errors_test.rb +17 -19
- data/test/adapter/json_api/fields_test.rb +4 -3
- data/test/adapter/json_api/has_many_test.rb +39 -18
- data/test/adapter/json_api/include_data_if_sideloaded_test.rb +166 -0
- data/test/adapter/json_api/json_api_test.rb +5 -7
- data/test/adapter/json_api/linked_test.rb +33 -12
- data/test/adapter/json_api/links_test.rb +4 -2
- data/test/adapter/json_api/pagination_links_test.rb +35 -8
- data/test/adapter/json_api/relationship_test.rb +309 -73
- data/test/adapter/json_api/resource_identifier_test.rb +27 -2
- data/test/adapter/json_api/resource_meta_test.rb +3 -3
- data/test/adapter/json_api/transform_test.rb +255 -253
- data/test/adapter/json_api/type_test.rb +1 -1
- data/test/adapter/json_test.rb +8 -7
- data/test/adapter/null_test.rb +1 -2
- data/test/adapter/polymorphic_test.rb +5 -5
- data/test/adapter_test.rb +1 -1
- data/test/benchmark/app.rb +1 -1
- data/test/benchmark/benchmarking_support.rb +1 -1
- data/test/benchmark/bm_active_record.rb +81 -0
- data/test/benchmark/bm_adapter.rb +38 -0
- data/test/benchmark/bm_caching.rb +16 -16
- data/test/benchmark/bm_lookup_chain.rb +83 -0
- data/test/benchmark/bm_transform.rb +16 -5
- data/test/benchmark/controllers.rb +16 -17
- data/test/benchmark/fixtures.rb +72 -72
- data/test/cache_test.rb +143 -49
- data/test/collection_serializer_test.rb +3 -3
- data/test/fixtures/poro.rb +52 -48
- data/test/generators/serializer_generator_test.rb +22 -5
- data/test/grape_test.rb +152 -56
- data/test/lint_test.rb +1 -1
- data/test/logger_test.rb +13 -11
- data/test/serializable_resource_test.rb +18 -22
- data/test/serializers/association_macros_test.rb +3 -2
- data/test/serializers/associations_test.rb +107 -32
- data/test/serializers/attribute_test.rb +2 -2
- data/test/serializers/attributes_test.rb +1 -1
- data/test/serializers/fieldset_test.rb +1 -1
- data/test/serializers/meta_test.rb +12 -6
- data/test/serializers/root_test.rb +1 -1
- data/test/serializers/serializer_for_test.rb +6 -4
- data/test/serializers/serializer_for_with_namespace_test.rb +87 -0
- data/test/support/isolated_unit.rb +5 -2
- data/test/support/rails5_shims.rb +8 -2
- data/test/support/rails_app.rb +0 -9
- data/test/support/serialization_testing.rb +23 -5
- data/test/test_helper.rb +1 -0
- metadata +85 -34
- data/.rubocop_todo.yml +0 -167
- data/lib/active_model/serializer/include_tree.rb +0 -111
- data/test/adapter/json_api/relationships_test.rb +0 -199
- data/test/include_tree/from_include_args_test.rb +0 -26
- data/test/include_tree/from_string_test.rb +0 -94
- data/test/include_tree/include_args_to_hash_test.rb +0 -64
@@ -1,263 +1,297 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
67
77
|
end
|
68
|
-
end
|
69
78
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
133
151
|
end
|
134
|
-
end
|
135
152
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
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
|
195
221
|
end
|
196
|
-
end
|
197
222
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
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
|
261
295
|
end
|
262
296
|
end
|
263
297
|
end
|
@@ -1,9 +1,22 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module ActiveModelSerializers
|
4
|
+
class ModelTest < ActiveSupport::TestCase
|
5
|
+
include ActiveModel::Serializer::Lint::Tests
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
def setup
|
8
|
+
@resource = ActiveModelSerializers::Model.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_initialization_with_string_keys
|
12
|
+
klass = Class.new(ActiveModelSerializers::Model) do
|
13
|
+
attr_accessor :key
|
14
|
+
end
|
15
|
+
value = 'value'
|
16
|
+
|
17
|
+
model_instance = klass.new('key' => value)
|
18
|
+
|
19
|
+
assert_equal model_instance.read_attribute_for_serialization(:key), value
|
20
|
+
end
|
8
21
|
end
|
9
22
|
end
|