active_model_serializers 0.9.11 → 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 +11 -1
- data/lib/active_model/serializer/association.rb +1 -3
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model/serializer.rb +15 -20
- data/test/fixtures/poro.rb +4 -3
- data/test/integration/generators/scaffold_controller_generator_test.rb +20 -20
- data/test/test_app.rb +4 -0
- data/test/unit/active_model/array_serializer/serialization_test.rb +1 -1
- data/test/unit/active_model/default_serializer_test.rb +1 -1
- data/test/unit/active_model/serializer/url_helpers_test.rb +1 -0
- metadata +2 -2
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,16 @@
|
|
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)
|
4
14
|
|
5
15
|
### [v0.9.11 (2024-04-09)](https://github.com/rails-api/active_model_serializers/compare/v0.9.10...v0.9.11)
|
6
16
|
|
@@ -9,9 +9,7 @@ module ActiveModel
|
|
9
9
|
class Association
|
10
10
|
def initialize(name, options={})
|
11
11
|
if options.has_key?(:include)
|
12
|
-
ActiveSupport::Deprecation.warn
|
13
|
-
** Notice: include was renamed to embed_in_root. **
|
14
|
-
WARN
|
12
|
+
ActiveSupport::Deprecation.warn("** Notice: include was renamed to embed_in_root. **")
|
15
13
|
end
|
16
14
|
|
17
15
|
@name = name.to_s
|
@@ -62,20 +62,19 @@ end
|
|
62
62
|
if resource.respond_to?(:serializer_class)
|
63
63
|
resource.serializer_class
|
64
64
|
elsif resource.respond_to?(:to_ary)
|
65
|
-
if
|
65
|
+
if defined?(::ArraySerializer)
|
66
66
|
::ArraySerializer
|
67
67
|
else
|
68
68
|
ArraySerializer
|
69
69
|
end
|
70
70
|
else
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
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
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
@@ -124,22 +123,17 @@ end
|
|
124
123
|
attr
|
125
124
|
end
|
126
125
|
|
127
|
-
def
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
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, {})
|
132
130
|
end
|
133
131
|
|
134
132
|
def build_serializer_class(resource, options)
|
135
133
|
klass_name = +""
|
136
134
|
klass_name << "#{options[:namespace]}::" if options[:namespace]
|
137
135
|
klass_name << options[:prefix].to_s.classify if options[:prefix]
|
138
|
-
|
139
|
-
klass_name << "#{resource}Serializer"
|
140
|
-
else
|
141
|
-
klass_name << "#{resource.class.name}Serializer"
|
142
|
-
end
|
136
|
+
klass_name << "#{resource.class.name}Serializer"
|
143
137
|
end
|
144
138
|
|
145
139
|
def associate(klass, *attrs)
|
@@ -169,7 +163,8 @@ end
|
|
169
163
|
@context = options[:context]
|
170
164
|
@namespace = options[:namespace]
|
171
165
|
end
|
172
|
-
attr_accessor :object, :scope, :root, :meta_key, :meta, :
|
166
|
+
attr_accessor :object, :scope, :root, :meta_key, :meta, :context, :polymorphic
|
167
|
+
attr_writer :key_format
|
173
168
|
|
174
169
|
def json_key
|
175
170
|
key = if root == true || root.nil?
|
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)
|
@@ -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
@@ -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
|
|
@@ -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: 2024-04-
|
13
|
+
date: 2024-04-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|