active_model_serializers 0.9.0 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +113 -0
- data/README.md +112 -19
- data/lib/action_controller/serialization.rb +35 -8
- data/lib/action_controller/serialization_test_case.rb +4 -4
- data/lib/active_model/array_serializer.rb +13 -10
- data/lib/active_model/default_serializer.rb +2 -6
- data/lib/active_model/serializable.rb +30 -11
- data/lib/active_model/serializable/utils.rb +16 -0
- data/lib/active_model/serializer.rb +90 -40
- data/lib/active_model/serializer/{associations.rb → association.rb} +8 -52
- data/lib/active_model/serializer/association/has_many.rb +39 -0
- data/lib/active_model/serializer/association/has_one.rb +25 -0
- data/lib/active_model/serializer/generators/serializer/scaffold_controller_generator.rb +1 -1
- data/lib/active_model/serializer/railtie.rb +12 -0
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model_serializers.rb +1 -1
- data/lib/active_model_serializers/model/caching.rb +25 -0
- data/test/benchmark/app.rb +60 -0
- data/test/benchmark/benchmarking_support.rb +67 -0
- data/test/benchmark/bm_active_record.rb +41 -0
- data/test/benchmark/setup.rb +75 -0
- data/test/benchmark/tmp/miniprofiler/mp_timers_6eqewtfgrhitvq5gqm25 +0 -0
- data/test/benchmark/tmp/miniprofiler/mp_timers_8083sx03hu72pxz1a4d0 +0 -0
- data/test/benchmark/tmp/miniprofiler/mp_timers_fyz2gsml4z0ph9kpoy1c +0 -0
- data/test/benchmark/tmp/miniprofiler/mp_timers_hjry5rc32imd42oxoi48 +0 -0
- data/test/benchmark/tmp/miniprofiler/mp_timers_m8fpoz2cvt3g9agz0bs3 +0 -0
- data/test/benchmark/tmp/miniprofiler/mp_timers_p92m2drnj1i568u3sta0 +0 -0
- data/test/benchmark/tmp/miniprofiler/mp_timers_qg52tpca3uesdfguee9i +0 -0
- data/test/benchmark/tmp/miniprofiler/mp_timers_s15t1a6mvxe0z7vjv790 +0 -0
- data/test/benchmark/tmp/miniprofiler/mp_timers_x8kal3d17nfds6vp4kcj +0 -0
- data/test/benchmark/tmp/miniprofiler/mp_views_127.0.0.1 +0 -0
- data/test/fixtures/active_record.rb +4 -0
- data/test/fixtures/poro.rb +149 -1
- data/test/fixtures/template.html.erb +1 -0
- data/test/integration/action_controller/namespaced_serialization_test.rb +105 -0
- data/test/integration/action_controller/serialization_test.rb +5 -5
- data/test/integration/action_controller/serialization_test_case_test.rb +10 -0
- data/test/integration/active_record/active_record_test.rb +19 -2
- data/test/test_app.rb +3 -0
- data/test/tmp/app/assets/javascripts/accounts.js +2 -0
- data/test/tmp/app/assets/stylesheets/accounts.css +4 -0
- data/test/tmp/app/controllers/accounts_controller.rb +2 -0
- data/test/tmp/app/helpers/accounts_helper.rb +2 -0
- data/test/tmp/app/serializers/account_serializer.rb +3 -0
- data/test/tmp/config/routes.rb +1 -0
- data/test/unit/active_model/array_serializer/options_test.rb +16 -0
- data/test/unit/active_model/array_serializer/serialization_test.rb +18 -1
- data/test/unit/active_model/serializer/associations/build_serializer_test.rb +15 -0
- data/test/unit/active_model/serializer/associations_test.rb +30 -0
- data/test/unit/active_model/serializer/attributes_test.rb +16 -0
- data/test/unit/active_model/serializer/config_test.rb +3 -0
- data/test/unit/active_model/serializer/has_many_polymorphic_test.rb +189 -0
- data/test/unit/active_model/serializer/has_many_test.rb +52 -17
- data/test/unit/active_model/serializer/has_one_and_has_many_test.rb +27 -0
- data/test/unit/active_model/serializer/has_one_polymorphic_test.rb +196 -0
- data/test/unit/active_model/serializer/has_one_test.rb +46 -0
- data/test/unit/active_model/serializer/options_test.rb +27 -0
- data/test/unit/active_model/serializer/url_helpers_test.rb +35 -0
- data/test/unit/active_model/serilizable_test.rb +50 -0
- metadata +98 -25
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
class Serializer
|
5
|
+
class UrlHelpersTest < Minitest::Test
|
6
|
+
include Rails.application.routes.url_helpers
|
7
|
+
|
8
|
+
def setup
|
9
|
+
Object.const_set 'UserController', Class.new(ActionController::Base) do
|
10
|
+
def show
|
11
|
+
render text: 'profile'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Rails.application.routes.draw do
|
16
|
+
get '/profile/:id', as: :profile, controller: :user, action: :show
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_url_helpers_are_available
|
21
|
+
serializer = Class.new(ActiveModel::Serializer) do
|
22
|
+
attributes :url
|
23
|
+
|
24
|
+
def url
|
25
|
+
profile_url(id: object.object_id)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
profile = Profile.new
|
29
|
+
|
30
|
+
assert_equal({ url: profile_url(id: profile.object_id) },
|
31
|
+
serializer.new(profile).as_json)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module ActiveModel
|
4
|
+
class SerializableTest
|
5
|
+
class InstrumentationTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@events = []
|
8
|
+
|
9
|
+
@subscriber = ActiveSupport::Notifications.subscribe('!serialize.active_model_serializers') do |name, start, finish, id, payload|
|
10
|
+
@events << { name: name, serializer: payload[:serializer] }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
ActiveSupport::Notifications.unsubscribe(@subscriber) if defined?(@subscriber)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_instruments_default_serializer
|
19
|
+
DefaultSerializer.new(1).as_json
|
20
|
+
|
21
|
+
assert_equal [{ name: '!serialize.active_model_serializers', serializer: 'ActiveModel::DefaultSerializer' }], @events
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_instruments_serializer
|
25
|
+
profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
26
|
+
serializer = ProfileSerializer.new(profile)
|
27
|
+
|
28
|
+
serializer.as_json
|
29
|
+
|
30
|
+
assert_equal [{ name: '!serialize.active_model_serializers', serializer: 'ProfileSerializer' }], @events
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_instruments_array_serializer
|
34
|
+
profiles = [
|
35
|
+
Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1'),
|
36
|
+
Profile.new(name: 'Name 2', description: 'Description 2', comments: 'Comments 2')
|
37
|
+
]
|
38
|
+
serializer = ArraySerializer.new(profiles)
|
39
|
+
|
40
|
+
serializer.as_json
|
41
|
+
|
42
|
+
assert_equal [
|
43
|
+
{ name: '!serialize.active_model_serializers', serializer: 'ProfileSerializer' },
|
44
|
+
{ name: '!serialize.active_model_serializers', serializer: 'ProfileSerializer' },
|
45
|
+
{ name: '!serialize.active_model_serializers', serializer: 'ActiveModel::ArraySerializer' }
|
46
|
+
], @events
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model_serializers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
8
8
|
- Yehuda Katz
|
9
9
|
- Santiago Pastorino
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-12-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
@@ -26,6 +26,20 @@ dependencies:
|
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '3.2'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: concurrent-ruby
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1.0'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.0'
|
29
43
|
- !ruby/object:Gem::Dependency
|
30
44
|
name: rails
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,8 +73,11 @@ files:
|
|
59
73
|
- lib/active_model/array_serializer.rb
|
60
74
|
- lib/active_model/default_serializer.rb
|
61
75
|
- lib/active_model/serializable.rb
|
76
|
+
- lib/active_model/serializable/utils.rb
|
62
77
|
- lib/active_model/serializer.rb
|
63
|
-
- lib/active_model/serializer/
|
78
|
+
- lib/active_model/serializer/association.rb
|
79
|
+
- lib/active_model/serializer/association/has_many.rb
|
80
|
+
- lib/active_model/serializer/association/has_one.rb
|
64
81
|
- lib/active_model/serializer/config.rb
|
65
82
|
- lib/active_model/serializer/generators/resource_override.rb
|
66
83
|
- lib/active_model/serializer/generators/serializer/USAGE
|
@@ -72,8 +89,25 @@ files:
|
|
72
89
|
- lib/active_model/serializer/version.rb
|
73
90
|
- lib/active_model/serializer_support.rb
|
74
91
|
- lib/active_model_serializers.rb
|
92
|
+
- lib/active_model_serializers/model/caching.rb
|
93
|
+
- test/benchmark/app.rb
|
94
|
+
- test/benchmark/benchmarking_support.rb
|
95
|
+
- test/benchmark/bm_active_record.rb
|
96
|
+
- test/benchmark/setup.rb
|
97
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_6eqewtfgrhitvq5gqm25
|
98
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_8083sx03hu72pxz1a4d0
|
99
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_fyz2gsml4z0ph9kpoy1c
|
100
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_hjry5rc32imd42oxoi48
|
101
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_m8fpoz2cvt3g9agz0bs3
|
102
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_p92m2drnj1i568u3sta0
|
103
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_qg52tpca3uesdfguee9i
|
104
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_s15t1a6mvxe0z7vjv790
|
105
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_x8kal3d17nfds6vp4kcj
|
106
|
+
- test/benchmark/tmp/miniprofiler/mp_views_127.0.0.1
|
75
107
|
- test/fixtures/active_record.rb
|
76
108
|
- test/fixtures/poro.rb
|
109
|
+
- test/fixtures/template.html.erb
|
110
|
+
- test/integration/action_controller/namespaced_serialization_test.rb
|
77
111
|
- test/integration/action_controller/serialization_test.rb
|
78
112
|
- test/integration/action_controller/serialization_test_case_test.rb
|
79
113
|
- test/integration/active_record/active_record_test.rb
|
@@ -82,10 +116,17 @@ files:
|
|
82
116
|
- test/integration/generators/serializer_generator_test.rb
|
83
117
|
- test/test_app.rb
|
84
118
|
- test/test_helper.rb
|
119
|
+
- test/tmp/app/assets/javascripts/accounts.js
|
120
|
+
- test/tmp/app/assets/stylesheets/accounts.css
|
121
|
+
- test/tmp/app/controllers/accounts_controller.rb
|
122
|
+
- test/tmp/app/helpers/accounts_helper.rb
|
123
|
+
- test/tmp/app/serializers/account_serializer.rb
|
124
|
+
- test/tmp/config/routes.rb
|
85
125
|
- test/unit/active_model/array_serializer/except_test.rb
|
86
126
|
- test/unit/active_model/array_serializer/key_format_test.rb
|
87
127
|
- test/unit/active_model/array_serializer/meta_test.rb
|
88
128
|
- test/unit/active_model/array_serializer/only_test.rb
|
129
|
+
- test/unit/active_model/array_serializer/options_test.rb
|
89
130
|
- test/unit/active_model/array_serializer/root_test.rb
|
90
131
|
- test/unit/active_model/array_serializer/scope_test.rb
|
91
132
|
- test/unit/active_model/array_serializer/serialization_test.rb
|
@@ -95,18 +136,23 @@ files:
|
|
95
136
|
- test/unit/active_model/serializer/attributes_test.rb
|
96
137
|
- test/unit/active_model/serializer/config_test.rb
|
97
138
|
- test/unit/active_model/serializer/filter_test.rb
|
139
|
+
- test/unit/active_model/serializer/has_many_polymorphic_test.rb
|
98
140
|
- test/unit/active_model/serializer/has_many_test.rb
|
141
|
+
- test/unit/active_model/serializer/has_one_and_has_many_test.rb
|
142
|
+
- test/unit/active_model/serializer/has_one_polymorphic_test.rb
|
99
143
|
- test/unit/active_model/serializer/has_one_test.rb
|
100
144
|
- test/unit/active_model/serializer/key_format_test.rb
|
101
145
|
- test/unit/active_model/serializer/meta_test.rb
|
102
146
|
- test/unit/active_model/serializer/options_test.rb
|
103
147
|
- test/unit/active_model/serializer/root_test.rb
|
104
148
|
- test/unit/active_model/serializer/scope_test.rb
|
149
|
+
- test/unit/active_model/serializer/url_helpers_test.rb
|
150
|
+
- test/unit/active_model/serilizable_test.rb
|
105
151
|
homepage: https://github.com/rails-api/active_model_serializers
|
106
152
|
licenses:
|
107
153
|
- MIT
|
108
154
|
metadata: {}
|
109
|
-
post_install_message:
|
155
|
+
post_install_message:
|
110
156
|
rdoc_options: []
|
111
157
|
require_paths:
|
112
158
|
- lib
|
@@ -121,40 +167,67 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
167
|
- !ruby/object:Gem::Version
|
122
168
|
version: '0'
|
123
169
|
requirements: []
|
124
|
-
|
125
|
-
|
126
|
-
signing_key:
|
170
|
+
rubygems_version: 3.1.4
|
171
|
+
signing_key:
|
127
172
|
specification_version: 4
|
128
173
|
summary: Bringing consistency and object orientation to model serialization. Works
|
129
174
|
great for client-side MVC frameworks!
|
130
175
|
test_files:
|
131
|
-
- test/
|
176
|
+
- test/benchmark/app.rb
|
177
|
+
- test/benchmark/setup.rb
|
178
|
+
- test/benchmark/bm_active_record.rb
|
179
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_m8fpoz2cvt3g9agz0bs3
|
180
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_s15t1a6mvxe0z7vjv790
|
181
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_hjry5rc32imd42oxoi48
|
182
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_qg52tpca3uesdfguee9i
|
183
|
+
- test/benchmark/tmp/miniprofiler/mp_views_127.0.0.1
|
184
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_fyz2gsml4z0ph9kpoy1c
|
185
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_p92m2drnj1i568u3sta0
|
186
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_6eqewtfgrhitvq5gqm25
|
187
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_x8kal3d17nfds6vp4kcj
|
188
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_8083sx03hu72pxz1a4d0
|
189
|
+
- test/benchmark/benchmarking_support.rb
|
132
190
|
- test/unit/active_model/serializer/config_test.rb
|
191
|
+
- test/unit/active_model/serializer/has_one_test.rb
|
133
192
|
- test/unit/active_model/serializer/associations/build_serializer_test.rb
|
134
|
-
- test/unit/active_model/serializer/
|
135
|
-
- test/unit/active_model/serializer/
|
136
|
-
- test/unit/active_model/serializer/
|
193
|
+
- test/unit/active_model/serializer/key_format_test.rb
|
194
|
+
- test/unit/active_model/serializer/url_helpers_test.rb
|
195
|
+
- test/unit/active_model/serializer/associations_test.rb
|
196
|
+
- test/unit/active_model/serializer/options_test.rb
|
137
197
|
- test/unit/active_model/serializer/attributes_test.rb
|
198
|
+
- test/unit/active_model/serializer/root_test.rb
|
199
|
+
- test/unit/active_model/serializer/meta_test.rb
|
200
|
+
- test/unit/active_model/serializer/has_many_polymorphic_test.rb
|
201
|
+
- test/unit/active_model/serializer/has_one_polymorphic_test.rb
|
138
202
|
- test/unit/active_model/serializer/has_many_test.rb
|
139
|
-
- test/unit/active_model/serializer/
|
203
|
+
- test/unit/active_model/serializer/has_one_and_has_many_test.rb
|
204
|
+
- test/unit/active_model/serializer/filter_test.rb
|
140
205
|
- test/unit/active_model/serializer/scope_test.rb
|
141
|
-
- test/unit/active_model/
|
142
|
-
- test/unit/active_model/
|
143
|
-
- test/unit/active_model/
|
144
|
-
- test/unit/active_model/array_serializer/
|
206
|
+
- test/unit/active_model/default_serializer_test.rb
|
207
|
+
- test/unit/active_model/array_serializer/serialization_test.rb
|
208
|
+
- test/unit/active_model/array_serializer/key_format_test.rb
|
209
|
+
- test/unit/active_model/array_serializer/options_test.rb
|
210
|
+
- test/unit/active_model/array_serializer/only_test.rb
|
145
211
|
- test/unit/active_model/array_serializer/root_test.rb
|
146
212
|
- test/unit/active_model/array_serializer/except_test.rb
|
213
|
+
- test/unit/active_model/array_serializer/meta_test.rb
|
147
214
|
- test/unit/active_model/array_serializer/scope_test.rb
|
148
|
-
- test/unit/active_model/
|
149
|
-
- test/
|
150
|
-
- test/unit/active_model/array_serializer/key_format_test.rb
|
151
|
-
- test/unit/active_model/default_serializer_test.rb
|
152
|
-
- test/integration/active_record/active_record_test.rb
|
153
|
-
- test/integration/action_controller/serialization_test_case_test.rb
|
215
|
+
- test/unit/active_model/serilizable_test.rb
|
216
|
+
- test/test_app.rb
|
154
217
|
- test/integration/action_controller/serialization_test.rb
|
155
|
-
- test/integration/
|
218
|
+
- test/integration/action_controller/serialization_test_case_test.rb
|
219
|
+
- test/integration/action_controller/namespaced_serialization_test.rb
|
220
|
+
- test/integration/active_record/active_record_test.rb
|
156
221
|
- test/integration/generators/scaffold_controller_generator_test.rb
|
222
|
+
- test/integration/generators/resource_generator_test.rb
|
157
223
|
- test/integration/generators/serializer_generator_test.rb
|
158
224
|
- test/fixtures/poro.rb
|
225
|
+
- test/fixtures/template.html.erb
|
159
226
|
- test/fixtures/active_record.rb
|
160
|
-
- test/
|
227
|
+
- test/test_helper.rb
|
228
|
+
- test/tmp/app/serializers/account_serializer.rb
|
229
|
+
- test/tmp/app/controllers/accounts_controller.rb
|
230
|
+
- test/tmp/app/assets/javascripts/accounts.js
|
231
|
+
- test/tmp/app/assets/stylesheets/accounts.css
|
232
|
+
- test/tmp/app/helpers/accounts_helper.rb
|
233
|
+
- test/tmp/config/routes.rb
|