active_model_serializers 0.9.9 → 0.9.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -1
- data/lib/action_controller/serialization.rb +10 -1
- data/lib/action_controller/serialization_test_case.rb +3 -0
- data/lib/active_model/array_serializer.rb +2 -0
- data/lib/active_model/default_serializer.rb +2 -0
- data/lib/active_model/serializable/utils.rb +2 -0
- data/lib/active_model/serializable.rb +3 -1
- data/lib/active_model/serializer/association/has_many.rb +2 -0
- data/lib/active_model/serializer/association/has_one.rb +2 -0
- data/lib/active_model/serializer/association.rb +3 -3
- data/lib/active_model/serializer/config.rb +2 -0
- data/lib/active_model/serializer/generators/resource_override.rb +2 -0
- data/lib/active_model/serializer/generators/serializer/scaffold_controller_generator.rb +2 -0
- data/lib/active_model/serializer/generators/serializer/serializer_generator.rb +2 -0
- data/lib/active_model/serializer/railtie.rb +2 -0
- data/lib/active_model/serializer/version.rb +3 -1
- data/lib/active_model/serializer.rb +20 -24
- data/lib/active_model/serializer_support.rb +2 -0
- data/lib/active_model_serializers.rb +14 -2
- data/test/fixtures/poro.rb +4 -3
- data/test/integration/action_controller/serialization_test.rb +13 -13
- data/test/integration/generators/scaffold_controller_generator_test.rb +20 -20
- data/test/test_app.rb +4 -0
- data/test/test_helper.rb +7 -2
- data/test/unit/active_model/array_serializer/serialization_test.rb +3 -3
- data/test/unit/active_model/default_serializer_test.rb +1 -1
- data/test/unit/active_model/serializer/url_helpers_test.rb +1 -0
- metadata +46 -47
- data/lib/active_model_serializers/model/caching.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61778c5b2b91da210dcc01075ef454249315c36600f82bea6996ed3290560003
|
4
|
+
data.tar.gz: 75e07b2aaf633ea4c5b785ea9d95a23bf9a240e8ee232c80a2c2a8bc9bca4666
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd16f19a2585c7fb2fdb4b54990eb71e306def01fc6757d42c19b26820f43d3afb82d28c44efd6c228bffcac7a84324277e9d17facaa22935bf8f3a1cf4ee588
|
7
|
+
data.tar.gz: 06c780dffd320606869b1e377e08fdbc2b83f7ec2726ea100d3004e9ad7098f89d254ffb2b1b62477a08b0e6898b1a40ae0466bf137296559e3736c19ab7a760
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,33 @@
|
|
1
1
|
## 0.09.x
|
2
2
|
|
3
|
-
### [0-9-stable](https://github.com/rails-api/active_model_serializers/compare/v0.9.
|
3
|
+
### [0-9-stable](https://github.com/rails-api/active_model_serializers/compare/v0.9.12...0-9-stable)
|
4
|
+
|
5
|
+
### [v0.9.12 (2024-04-11)](https://github.com/rails-api/active_model_serializers/compare/v0.9.11...v0.9.12)
|
6
|
+
|
7
|
+
- Fix
|
8
|
+
- [#2468](https://github.com/rails-api/active_model_serializers/pull/2468) Fix bug introduced in v0.9.9. Revert "Allow serializer_for to accept String instead of just class objects". (@byroot)
|
9
|
+
- Perf
|
10
|
+
- [#2466](https://github.com/rails-api/active_model_serializers/pull/2466) Prefer `defined?` to `Object.constants.include?` (@byroot)
|
11
|
+
- [#2467](https://github.com/rails-api/active_model_serializers/pull/2467) Lazily compute possible serializer class names (@byroot)
|
12
|
+
- Chore
|
13
|
+
- [#2469](https://github.com/rails-api/active_model_serializers/pull/2469) Fix various warnings in the test suite (@byroot)
|
14
|
+
|
15
|
+
### [v0.9.11 (2024-04-09)](https://github.com/rails-api/active_model_serializers/compare/v0.9.10...v0.9.11)
|
16
|
+
|
17
|
+
v0.9.10 was built with an extra file included and so was yanked.
|
18
|
+
v0.9.11 is the same as v0.9.10 but doesn't have the extra file.
|
19
|
+
|
20
|
+
### [v0.9.10 (2024-04-09)](https://github.com/rails-api/active_model_serializers/compare/v0.9.9...v0.9.10)
|
21
|
+
|
22
|
+
- Fix
|
23
|
+
- [#2464](https://github.com/rails-api/active_model_serializers/pull/2464) Do not load ActionController::TestCase in production (@byroot)
|
24
|
+
- Perf
|
25
|
+
- [#2465](https://github.com/rails-api/active_model_serializers/pull/2465) Make compatible with enable-frozen-string-literal (@byroot)
|
26
|
+
- [#2463](https://github.com/rails-api/active_model_serializers/pull/2463) Shape Friendly ActionController:Serialization (@byroot)
|
27
|
+
- Chore
|
28
|
+
- [#2462](https://github.com/rails-api/active_model_serializers/pull/2462]) Rails 7.1, Ruby 3.3 compat (@byroot)
|
29
|
+
- Test
|
30
|
+
- [#2447](https://github.com/rails-api/active_model_serializers/pull/2447) Configure CI on GitHub actoins (@Physium)
|
4
31
|
|
5
32
|
### [v0.9.9 (2023-05-18)](https://github.com/rails-api/active_model_serializers/compare/v0.9.8...v0.9.8)
|
6
33
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/core_ext/class/attribute'
|
2
4
|
|
3
5
|
module ActionController
|
@@ -45,6 +47,12 @@ module ActionController
|
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
50
|
+
def initialize(*)
|
51
|
+
super
|
52
|
+
@namespace_for_serializer = nil
|
53
|
+
end
|
54
|
+
ruby2_keywords :initialize if respond_to?(:ruby2_keywords, true)
|
55
|
+
|
48
56
|
[:_render_option_json, :_render_with_renderer_json].each do |renderer_method|
|
49
57
|
define_method renderer_method do |resource, options|
|
50
58
|
serializer = build_json_serializer(resource, options)
|
@@ -60,7 +68,8 @@ module ActionController
|
|
60
68
|
private
|
61
69
|
|
62
70
|
def namespace_for_serializer
|
63
|
-
@namespace_for_serializer ||= namespace_for_class(self.class)
|
71
|
+
@namespace_for_serializer ||= namespace_for_class(self.class)
|
72
|
+
@namespace_for_serializer unless @namespace_for_serializer == Object
|
64
73
|
end
|
65
74
|
|
66
75
|
def namespace_for_class(klass)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionController
|
2
4
|
module SerializationAssertions
|
3
5
|
extend ActiveSupport::Concern
|
@@ -24,6 +26,7 @@ module ActionController
|
|
24
26
|
@serializers = Hash.new(0)
|
25
27
|
super
|
26
28
|
end
|
29
|
+
ruby2_keywords :process if respond_to?(:ruby2_keywords, true)
|
27
30
|
|
28
31
|
# Asserts that the request was rendered with the appropriate serializers.
|
29
32
|
#
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_model/serializable/utils'
|
2
4
|
|
3
5
|
module ActiveModel
|
4
6
|
module Serializable
|
5
|
-
INSTRUMENTATION_KEY = '!serialize.active_model_serializers'
|
7
|
+
INSTRUMENTATION_KEY = '!serialize.active_model_serializers'
|
6
8
|
|
7
9
|
def self.included(base)
|
8
10
|
base.extend Utils
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_model/default_serializer'
|
2
4
|
require 'active_model/serializer/association/has_one'
|
3
5
|
require 'active_model/serializer/association/has_many'
|
@@ -7,9 +9,7 @@ module ActiveModel
|
|
7
9
|
class Association
|
8
10
|
def initialize(name, options={})
|
9
11
|
if options.has_key?(:include)
|
10
|
-
ActiveSupport::Deprecation.warn
|
11
|
-
** Notice: include was renamed to embed_in_root. **
|
12
|
-
WARN
|
12
|
+
ActiveSupport::Deprecation.warn("** Notice: include was renamed to embed_in_root. **")
|
13
13
|
end
|
14
14
|
|
15
15
|
@name = name.to_s
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_model/array_serializer'
|
2
4
|
require 'active_model/serializable'
|
3
5
|
require 'active_model/serializer/association'
|
@@ -60,20 +62,19 @@ end
|
|
60
62
|
if resource.respond_to?(:serializer_class)
|
61
63
|
resource.serializer_class
|
62
64
|
elsif resource.respond_to?(:to_ary)
|
63
|
-
if
|
65
|
+
if defined?(::ArraySerializer)
|
64
66
|
::ArraySerializer
|
65
67
|
else
|
66
68
|
ArraySerializer
|
67
69
|
end
|
68
70
|
else
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
result.find { |serializer| !serializer.nil? }
|
71
|
+
each_possible_serializer(resource, options) do |klass_name|
|
72
|
+
serializer = Serializer.serializers_cache.fetch_or_store(klass_name) do
|
73
|
+
_const_get(klass_name)
|
74
|
+
end
|
75
|
+
return serializer unless serializer.nil?
|
76
|
+
end
|
77
|
+
nil
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
@@ -122,23 +123,17 @@ end
|
|
122
123
|
attr
|
123
124
|
end
|
124
125
|
|
125
|
-
def
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
list << build_serializer_class(resource.class.name.demodulize, {})
|
126
|
+
def each_possible_serializer(resource, options)
|
127
|
+
yield build_serializer_class(resource, options)
|
128
|
+
yield build_serializer_class(resource, {})
|
129
|
+
yield build_serializer_class(resource.class.name.demodulize, {})
|
130
130
|
end
|
131
131
|
|
132
132
|
def build_serializer_class(resource, options)
|
133
|
-
""
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
klass_name << "#{resource}Serializer"
|
138
|
-
else
|
139
|
-
klass_name << "#{resource.class.name}Serializer"
|
140
|
-
end
|
141
|
-
end
|
133
|
+
klass_name = +""
|
134
|
+
klass_name << "#{options[:namespace]}::" if options[:namespace]
|
135
|
+
klass_name << options[:prefix].to_s.classify if options[:prefix]
|
136
|
+
klass_name << "#{resource.class.name}Serializer"
|
142
137
|
end
|
143
138
|
|
144
139
|
def associate(klass, *attrs)
|
@@ -168,7 +163,8 @@ end
|
|
168
163
|
@context = options[:context]
|
169
164
|
@namespace = options[:namespace]
|
170
165
|
end
|
171
|
-
attr_accessor :object, :scope, :root, :meta_key, :meta, :
|
166
|
+
attr_accessor :object, :scope, :root, :meta_key, :meta, :context, :polymorphic
|
167
|
+
attr_writer :key_format
|
172
168
|
|
173
169
|
def json_key
|
174
170
|
key = if root == true || root.nil?
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_model'
|
2
4
|
require 'active_model/serializer'
|
3
5
|
require 'active_model/serializer_support'
|
@@ -7,12 +9,22 @@ require 'active_model/serializer/railtie' if defined?(Rails)
|
|
7
9
|
begin
|
8
10
|
require 'action_controller'
|
9
11
|
require 'action_controller/serialization'
|
10
|
-
require 'action_controller/serialization_test_case'
|
11
12
|
|
12
13
|
ActiveSupport.on_load(:action_controller) do
|
13
14
|
if ::ActionController::Serialization.enabled
|
14
15
|
ActionController::Base.send(:include, ::ActionController::Serialization)
|
15
|
-
|
16
|
+
|
17
|
+
# action_controller_test_case load hook was added in Rails 5.1
|
18
|
+
# https://github.com/rails/rails/commit/0510208dd1ff23baa619884c0abcae4d141fae53
|
19
|
+
if ActiveSupport::VERSION::STRING < '5.1'
|
20
|
+
require 'action_controller/serialization_test_case'
|
21
|
+
ActionController::TestCase.send(:include, ::ActionController::SerializationAssertions)
|
22
|
+
else
|
23
|
+
ActiveSupport.on_load(:action_controller_test_case) do
|
24
|
+
require 'action_controller/serialization_test_case'
|
25
|
+
ActionController::TestCase.send(:include, ::ActionController::SerializationAssertions)
|
26
|
+
end
|
27
|
+
end
|
16
28
|
end
|
17
29
|
end
|
18
30
|
rescue LoadError
|
data/test/fixtures/poro.rb
CHANGED
@@ -144,14 +144,14 @@ end
|
|
144
144
|
|
145
145
|
class SelfReferencingUserParentSerializer < ActiveModel::Serializer
|
146
146
|
attributes :name
|
147
|
-
has_one :type, serializer: TypeSerializer, embed: :ids,
|
147
|
+
has_one :type, serializer: TypeSerializer, embed: :ids, embed_in_root: true
|
148
148
|
end
|
149
149
|
|
150
150
|
class SelfReferencingUserSerializer < ActiveModel::Serializer
|
151
151
|
attributes :name
|
152
152
|
|
153
|
-
has_one :type, serializer: TypeSerializer, embed: :ids,
|
154
|
-
has_one :parent, serializer: SelfReferencingUserSerializer, embed: :ids,
|
153
|
+
has_one :type, serializer: TypeSerializer, embed: :ids, embed_in_root: true
|
154
|
+
has_one :parent, serializer: SelfReferencingUserSerializer, embed: :ids, embed_in_root: true
|
155
155
|
end
|
156
156
|
|
157
157
|
class UserInfoSerializer < ActiveModel::Serializer
|
@@ -176,6 +176,7 @@ end
|
|
176
176
|
class PostSerializer < ActiveModel::Serializer
|
177
177
|
attributes :title, :body
|
178
178
|
|
179
|
+
alias_method :title, :title # silence method redefinition warning
|
179
180
|
def title
|
180
181
|
keyword = serialization_options[:highlight_keyword]
|
181
182
|
title = object.read_attribute_for_serialization(:title)
|
@@ -13,7 +13,7 @@ module ActionController
|
|
13
13
|
|
14
14
|
def test_render_using_implicit_serializer
|
15
15
|
get :render_using_implicit_serializer
|
16
|
-
|
16
|
+
assert_includes @response.content_type, 'application/json'
|
17
17
|
assert_equal '{"profile":{"name":"Name 1","description":"Description 1"}}', @response.body
|
18
18
|
end
|
19
19
|
end
|
@@ -35,7 +35,7 @@ module ActionController
|
|
35
35
|
|
36
36
|
def test_render_using_implicit_serializer_and_scope
|
37
37
|
get :render_using_implicit_serializer_and_scope
|
38
|
-
|
38
|
+
assert_includes @response.content_type, 'application/json'
|
39
39
|
assert_equal '{"profile":{"name":"Name 1","description":"Description 1 - current_user"}}', @response.body
|
40
40
|
end
|
41
41
|
end
|
@@ -65,7 +65,7 @@ module ActionController
|
|
65
65
|
|
66
66
|
def test_render_using_scope_set_in_default_serializer_options
|
67
67
|
get :render_using_scope_set_in_default_serializer_options
|
68
|
-
|
68
|
+
assert_includes @response.content_type, 'application/json'
|
69
69
|
assert_equal '{"profile":{"name":"Name 1","description":"Description 1 - current_admin"}}', @response.body
|
70
70
|
end
|
71
71
|
end
|
@@ -91,7 +91,7 @@ module ActionController
|
|
91
91
|
|
92
92
|
def test_render_using_implicit_serializer_and_explicit_scope
|
93
93
|
get :render_using_implicit_serializer_and_explicit_scope
|
94
|
-
|
94
|
+
assert_includes @response.content_type, 'application/json'
|
95
95
|
assert_equal '{"profile":{"name":"Name 1","description":"Description 1 - current_admin"}}', @response.body
|
96
96
|
end
|
97
97
|
end
|
@@ -117,7 +117,7 @@ module ActionController
|
|
117
117
|
|
118
118
|
def test_render_overriding_serialization_scope
|
119
119
|
get :render_overriding_serialization_scope
|
120
|
-
|
120
|
+
assert_includes @response.content_type, 'application/json'
|
121
121
|
assert_equal '{"profile":{"name":"Name 1","description":"Description 1 - current_admin"}}', @response.body
|
122
122
|
end
|
123
123
|
end
|
@@ -141,7 +141,7 @@ module ActionController
|
|
141
141
|
|
142
142
|
def test_render_calling_serialization_scope
|
143
143
|
get :render_calling_serialization_scope
|
144
|
-
|
144
|
+
assert_includes @response.content_type, 'application/json'
|
145
145
|
assert_equal '{"profile":{"name":"Name 1","description":"Description 1 - current_user"}}', @response.body
|
146
146
|
end
|
147
147
|
end
|
@@ -157,7 +157,7 @@ module ActionController
|
|
157
157
|
|
158
158
|
def test_render_using_json_dump
|
159
159
|
get :render_using_json_dump
|
160
|
-
|
160
|
+
assert_includes @response.content_type, 'application/json'
|
161
161
|
assert_equal '{"hello":"world"}', @response.body
|
162
162
|
end
|
163
163
|
end
|
@@ -173,7 +173,7 @@ module ActionController
|
|
173
173
|
|
174
174
|
def test_render_using_rails_behavior
|
175
175
|
get :render_using_rails_behavior
|
176
|
-
|
176
|
+
assert_includes @response.content_type, 'application/json'
|
177
177
|
assert_equal '[{"attributes":{"name":"Name 1","description":"Description 1","comments":"Comments 1"}}]', @response.body
|
178
178
|
end
|
179
179
|
end
|
@@ -189,7 +189,7 @@ module ActionController
|
|
189
189
|
|
190
190
|
def test_render_array
|
191
191
|
get :render_array
|
192
|
-
|
192
|
+
assert_includes @response.content_type, 'application/json'
|
193
193
|
assert_equal '{"my":[{"name":"Name 1","description":"Description 1"}]}', @response.body
|
194
194
|
end
|
195
195
|
end
|
@@ -205,7 +205,7 @@ module ActionController
|
|
205
205
|
|
206
206
|
def test_render_array
|
207
207
|
get :render_array
|
208
|
-
|
208
|
+
assert_includes @response.content_type, 'application/json'
|
209
209
|
assert_equal '{"webLog":[{"name":"Name 1","displayName":"Display Name 1"},{"name":"Name 2","displayName":"Display Name 2"}]}', @response.body
|
210
210
|
end
|
211
211
|
end
|
@@ -223,7 +223,7 @@ module ActionController
|
|
223
223
|
|
224
224
|
def test_render_without_root
|
225
225
|
get :render_without_root
|
226
|
-
|
226
|
+
assert_includes @response.content_type, 'application/json'
|
227
227
|
assert_equal '{"name":"Name 1","displayName":"Display Name 1"}', @response.body
|
228
228
|
end
|
229
229
|
end
|
@@ -242,7 +242,7 @@ module ActionController
|
|
242
242
|
|
243
243
|
def test_render_array_without_root
|
244
244
|
get :render_array_without_root
|
245
|
-
|
245
|
+
assert_includes @response.content_type, 'application/json'
|
246
246
|
assert_equal '[{"name":"Name 1","displayName":"Display Name 1"},{"name":"Name 2","displayName":"Display Name 2"}]', @response.body
|
247
247
|
end
|
248
248
|
end
|
@@ -278,7 +278,7 @@ module ActionController
|
|
278
278
|
@association.embed_in_root = true
|
279
279
|
|
280
280
|
get :render_array_embeding_in_root
|
281
|
-
|
281
|
+
assert_includes @response.content_type, 'application/json'
|
282
282
|
|
283
283
|
assert_equal("{\"my\":[{\"name\":\"Name 1\",\"email\":\"mail@server.com\",\"profile_id\":#{@controller.user.profile.object_id}}],\"profiles\":[{\"name\":\"N1\",\"description\":\"D1\"}]}", @response.body)
|
284
284
|
end
|
@@ -17,44 +17,44 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
|
17
17
|
|
18
18
|
assert_file 'app/controllers/accounts_controller.rb' do |content|
|
19
19
|
assert_instance_method :index, content do |m|
|
20
|
-
assert_match
|
21
|
-
assert_match
|
22
|
-
assert_match
|
20
|
+
assert_match(/@accounts = Account\.all/, m)
|
21
|
+
assert_match(/format.html/, m)
|
22
|
+
assert_match(/format.json \{ render json: @accounts \}/, m)
|
23
23
|
end
|
24
24
|
|
25
25
|
assert_instance_method :show, content do |m|
|
26
|
-
assert_match
|
27
|
-
assert_match
|
26
|
+
assert_match(/format.html/, m)
|
27
|
+
assert_match(/format.json \{ render json: @account \}/, m)
|
28
28
|
end
|
29
29
|
|
30
30
|
assert_instance_method :new, content do |m|
|
31
|
-
assert_match
|
31
|
+
assert_match(/@account = Account\.new/, m)
|
32
32
|
end
|
33
33
|
|
34
34
|
assert_instance_method :edit, content do |m|
|
35
|
-
|
35
|
+
assert_predicate m, :blank?
|
36
36
|
end
|
37
37
|
|
38
38
|
assert_instance_method :create, content do |m|
|
39
|
-
assert_match
|
40
|
-
assert_match
|
41
|
-
assert_match
|
42
|
-
assert_match
|
43
|
-
assert_match
|
44
|
-
assert_match
|
39
|
+
assert_match(/@account = Account\.new\(account_params\)/, m)
|
40
|
+
assert_match(/@account\.save/, m)
|
41
|
+
assert_match(/format\.html \{ redirect_to @account, notice: 'Account was successfully created\.' \}/, m)
|
42
|
+
assert_match(/format\.json \{ render json: @account, status: :created \}/, m)
|
43
|
+
assert_match(/format\.html \{ render action: 'new' \}/, m)
|
44
|
+
assert_match(/format\.json \{ render json: @account\.errors, status: :unprocessable_entity \}/, m)
|
45
45
|
end
|
46
46
|
|
47
47
|
assert_instance_method :update, content do |m|
|
48
|
-
assert_match
|
49
|
-
assert_match
|
50
|
-
assert_match
|
51
|
-
assert_match
|
48
|
+
assert_match(/format\.html \{ redirect_to @account, notice: 'Account was successfully updated\.' \}/, m)
|
49
|
+
assert_match(/format\.json \{ head :no_content \}/, m)
|
50
|
+
assert_match(/format\.html \{ render action: 'edit' \}/, m)
|
51
|
+
assert_match(/format\.json \{ render json: @account.errors, status: :unprocessable_entity \}/, m)
|
52
52
|
end
|
53
53
|
|
54
54
|
assert_instance_method :destroy, content do |m|
|
55
|
-
assert_match
|
56
|
-
assert_match
|
57
|
-
assert_match
|
55
|
+
assert_match(/@account\.destroy/, m)
|
56
|
+
assert_match(/format\.html { redirect_to accounts_url \}/, m)
|
57
|
+
assert_match(/format\.json \{ head :no_content \}/, m)
|
58
58
|
end
|
59
59
|
|
60
60
|
assert_match(/def account_params/, content)
|
data/test/test_app.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -2,8 +2,13 @@ require 'bundler/setup'
|
|
2
2
|
require 'minitest/autorun'
|
3
3
|
require 'active_model_serializers'
|
4
4
|
require 'fixtures/poro'
|
5
|
-
|
6
|
-
|
5
|
+
begin
|
6
|
+
require 'rails-controller-testing'
|
7
|
+
Rails::Controller::Testing.install
|
8
|
+
rescue LoadError
|
9
|
+
false # Rails 5 < backward compatibility
|
10
|
+
end
|
11
|
+
|
7
12
|
|
8
13
|
# Ensure backward compatibility with Minitest 4
|
9
14
|
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
|
@@ -49,7 +49,7 @@ module ActiveModel
|
|
49
49
|
def object.serializer_class; CustomSerializer; end
|
50
50
|
|
51
51
|
assert_equal CustomSerializer, Serializer.serializer_for(object)
|
52
|
-
|
52
|
+
assert_nil Serializer.serializer_for('Custom')
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -66,8 +66,8 @@ module ActiveModel
|
|
66
66
|
serializer = ArraySerializer.new(array)
|
67
67
|
|
68
68
|
expected = [
|
69
|
-
{ name: 'Test 1', email: 'test1@test.com', sub_test: { name: 'Name 1', description: 'Description 1' }},
|
70
|
-
{ name: 'Test
|
69
|
+
{ name: 'Test 1', email: 'test1@test.com', sub_test: { name: 'Name 1', description: 'Description 1' } },
|
70
|
+
{ name: 'Test 2', email: 'test2@test.com', sub_test: { name: 'Name 2', description: 'Description 2' } }
|
71
71
|
]
|
72
72
|
|
73
73
|
assert_equal expected, serializer.serializable_array
|
@@ -4,7 +4,7 @@ module ActiveModel
|
|
4
4
|
class DefaultSerializer
|
5
5
|
class Test < Minitest::Test
|
6
6
|
def test_serialize_objects
|
7
|
-
|
7
|
+
assert_nil(DefaultSerializer.new(nil).serializable_object)
|
8
8
|
assert_equal(1, DefaultSerializer.new(1).serializable_object)
|
9
9
|
assert_equal('hi', DefaultSerializer.new('hi').serializable_object)
|
10
10
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2024-04-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
@@ -89,7 +89,6 @@ files:
|
|
89
89
|
- lib/active_model/serializer/version.rb
|
90
90
|
- lib/active_model/serializer_support.rb
|
91
91
|
- lib/active_model_serializers.rb
|
92
|
-
- lib/active_model_serializers/model/caching.rb
|
93
92
|
- test/benchmark/app.rb
|
94
93
|
- test/benchmark/benchmarking_support.rb
|
95
94
|
- test/benchmark/bm_active_record.rb
|
@@ -167,67 +166,67 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
166
|
- !ruby/object:Gem::Version
|
168
167
|
version: '0'
|
169
168
|
requirements: []
|
170
|
-
rubygems_version: 3.
|
169
|
+
rubygems_version: 3.3.7
|
171
170
|
signing_key:
|
172
171
|
specification_version: 4
|
173
172
|
summary: Bringing consistency and object orientation to model serialization. Works
|
174
173
|
great for client-side MVC frameworks!
|
175
174
|
test_files:
|
176
175
|
- test/benchmark/app.rb
|
177
|
-
- test/benchmark/
|
176
|
+
- test/benchmark/benchmarking_support.rb
|
178
177
|
- test/benchmark/bm_active_record.rb
|
179
|
-
- test/benchmark/
|
180
|
-
- test/benchmark/tmp/miniprofiler/
|
181
|
-
- test/benchmark/tmp/miniprofiler/
|
182
|
-
- test/benchmark/tmp/miniprofiler/mp_timers_qg52tpca3uesdfguee9i
|
183
|
-
- test/benchmark/tmp/miniprofiler/mp_views_127.0.0.1
|
178
|
+
- test/benchmark/setup.rb
|
179
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_6eqewtfgrhitvq5gqm25
|
180
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_8083sx03hu72pxz1a4d0
|
184
181
|
- test/benchmark/tmp/miniprofiler/mp_timers_fyz2gsml4z0ph9kpoy1c
|
182
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_hjry5rc32imd42oxoi48
|
183
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_m8fpoz2cvt3g9agz0bs3
|
185
184
|
- test/benchmark/tmp/miniprofiler/mp_timers_p92m2drnj1i568u3sta0
|
186
|
-
- test/benchmark/tmp/miniprofiler/
|
185
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_qg52tpca3uesdfguee9i
|
186
|
+
- test/benchmark/tmp/miniprofiler/mp_timers_s15t1a6mvxe0z7vjv790
|
187
187
|
- test/benchmark/tmp/miniprofiler/mp_timers_x8kal3d17nfds6vp4kcj
|
188
|
-
- test/benchmark/tmp/miniprofiler/
|
189
|
-
- test/
|
190
|
-
- test/
|
191
|
-
- test/
|
192
|
-
- test/
|
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
|
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
|
202
|
-
- test/unit/active_model/serializer/has_many_test.rb
|
203
|
-
- test/unit/active_model/serializer/has_one_and_has_many_test.rb
|
204
|
-
- test/unit/active_model/serializer/filter_test.rb
|
205
|
-
- test/unit/active_model/serializer/scope_test.rb
|
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
|
211
|
-
- test/unit/active_model/array_serializer/root_test.rb
|
212
|
-
- test/unit/active_model/array_serializer/except_test.rb
|
213
|
-
- test/unit/active_model/array_serializer/meta_test.rb
|
214
|
-
- test/unit/active_model/array_serializer/scope_test.rb
|
215
|
-
- test/unit/active_model/serilizable_test.rb
|
216
|
-
- test/test_app.rb
|
188
|
+
- test/benchmark/tmp/miniprofiler/mp_views_127.0.0.1
|
189
|
+
- test/fixtures/active_record.rb
|
190
|
+
- test/fixtures/poro.rb
|
191
|
+
- test/fixtures/template.html.erb
|
192
|
+
- test/integration/action_controller/namespaced_serialization_test.rb
|
217
193
|
- test/integration/action_controller/serialization_test.rb
|
218
194
|
- test/integration/action_controller/serialization_test_case_test.rb
|
219
|
-
- test/integration/action_controller/namespaced_serialization_test.rb
|
220
195
|
- test/integration/active_record/active_record_test.rb
|
221
|
-
- test/integration/generators/scaffold_controller_generator_test.rb
|
222
196
|
- test/integration/generators/resource_generator_test.rb
|
197
|
+
- test/integration/generators/scaffold_controller_generator_test.rb
|
223
198
|
- test/integration/generators/serializer_generator_test.rb
|
224
|
-
- test/
|
225
|
-
- test/fixtures/template.html.erb
|
226
|
-
- test/fixtures/active_record.rb
|
199
|
+
- test/test_app.rb
|
227
200
|
- test/test_helper.rb
|
228
|
-
- test/tmp/app/serializers/account_serializer.rb
|
229
|
-
- test/tmp/app/controllers/accounts_controller.rb
|
230
201
|
- test/tmp/app/assets/javascripts/accounts.js
|
231
202
|
- test/tmp/app/assets/stylesheets/accounts.css
|
203
|
+
- test/tmp/app/controllers/accounts_controller.rb
|
232
204
|
- test/tmp/app/helpers/accounts_helper.rb
|
205
|
+
- test/tmp/app/serializers/account_serializer.rb
|
233
206
|
- test/tmp/config/routes.rb
|
207
|
+
- test/unit/active_model/array_serializer/except_test.rb
|
208
|
+
- test/unit/active_model/array_serializer/key_format_test.rb
|
209
|
+
- test/unit/active_model/array_serializer/meta_test.rb
|
210
|
+
- test/unit/active_model/array_serializer/only_test.rb
|
211
|
+
- test/unit/active_model/array_serializer/options_test.rb
|
212
|
+
- test/unit/active_model/array_serializer/root_test.rb
|
213
|
+
- test/unit/active_model/array_serializer/scope_test.rb
|
214
|
+
- test/unit/active_model/array_serializer/serialization_test.rb
|
215
|
+
- test/unit/active_model/default_serializer_test.rb
|
216
|
+
- test/unit/active_model/serializer/associations/build_serializer_test.rb
|
217
|
+
- test/unit/active_model/serializer/associations_test.rb
|
218
|
+
- test/unit/active_model/serializer/attributes_test.rb
|
219
|
+
- test/unit/active_model/serializer/config_test.rb
|
220
|
+
- test/unit/active_model/serializer/filter_test.rb
|
221
|
+
- test/unit/active_model/serializer/has_many_polymorphic_test.rb
|
222
|
+
- test/unit/active_model/serializer/has_many_test.rb
|
223
|
+
- test/unit/active_model/serializer/has_one_and_has_many_test.rb
|
224
|
+
- test/unit/active_model/serializer/has_one_polymorphic_test.rb
|
225
|
+
- test/unit/active_model/serializer/has_one_test.rb
|
226
|
+
- test/unit/active_model/serializer/key_format_test.rb
|
227
|
+
- test/unit/active_model/serializer/meta_test.rb
|
228
|
+
- test/unit/active_model/serializer/options_test.rb
|
229
|
+
- test/unit/active_model/serializer/root_test.rb
|
230
|
+
- test/unit/active_model/serializer/scope_test.rb
|
231
|
+
- test/unit/active_model/serializer/url_helpers_test.rb
|
232
|
+
- test/unit/active_model/serilizable_test.rb
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module ActiveModelSerializers
|
3
|
-
class Model
|
4
|
-
module Caching
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
attr_writer :updated_at
|
9
|
-
attributes :id
|
10
|
-
end
|
11
|
-
|
12
|
-
# Defaults to the downcased model name and updated_at
|
13
|
-
def cache_key
|
14
|
-
ActiveSupport::Cache.expand_cache_key([
|
15
|
-
self.class.model_name.name.downcase,
|
16
|
-
"#{id}-#{updated_at.strftime('%Y%m%d%H%M%S%9N')}"
|
17
|
-
].compact)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Defaults to the time the serializer file was modified.
|
21
|
-
def updated_at
|
22
|
-
defined?(@updated_at) ? @updated_at : File.mtime(__FILE__)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|