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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1c2dbb7d1b6d7673364e690d624e5a8dffa5fddf2f9ee9d6838ac399ab14a96
4
- data.tar.gz: 5fcef7df6ec5deb692b68ffd8198e438b8bf2bafe812d12ace97087f9eb9c3f8
3
+ metadata.gz: 61778c5b2b91da210dcc01075ef454249315c36600f82bea6996ed3290560003
4
+ data.tar.gz: 75e07b2aaf633ea4c5b785ea9d95a23bf9a240e8ee232c80a2c2a8bc9bca4666
5
5
  SHA512:
6
- metadata.gz: 281b4a64ab65e4f2aff6b45a393e684e1d69a5fe203c450268cfc001deb20fce6e1269c9aafd1bf54e847bc5a282cfd28f630cb45096ec750bb531363cd93cbd
7
- data.tar.gz: 13cd7cfa482532515a8629c35c4e5c0847b1dd791494025f4d6177e05f45f5845641b8bc04cfb543a503b8767afcb8505fd1c433afc0cd73c5bcd0d9a8066119
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.11...0-9-stable)
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 <<-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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveModel
4
4
  class Serializer
5
- VERSION = '0.9.11'
5
+ VERSION = '0.9.12'
6
6
  end
7
7
  end
@@ -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 Object.constants.include?(:ArraySerializer)
65
+ if defined?(::ArraySerializer)
66
66
  ::ArraySerializer
67
67
  else
68
68
  ArraySerializer
69
69
  end
70
70
  else
71
- search_list = build_serializer_class_list(resource, options)
72
- result = search_list.map do |klass_name|
73
- Serializer.serializers_cache.fetch_or_store(klass_name) do
74
- _const_get(klass_name)
75
- end
76
- end
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 build_serializer_class_list(resource, options)
128
- list = []
129
- list << build_serializer_class(resource, options)
130
- list << build_serializer_class(resource, {})
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
- if resource.is_a?(String)
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, :key_format, :context, :polymorphic
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?
@@ -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, include: true
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, include: true
154
- has_one :parent, serializer: SelfReferencingUserSerializer, embed: :ids, include: true
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 /@accounts = Account\.all/, m
21
- assert_match /format.html/, m
22
- assert_match /format.json \{ render json: @accounts \}/, m
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 /format.html/, m
27
- assert_match /format.json \{ render json: @account \}/, m
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 /@account = Account\.new/, m
31
+ assert_match(/@account = Account\.new/, m)
32
32
  end
33
33
 
34
34
  assert_instance_method :edit, content do |m|
35
- assert m.blank?
35
+ assert_predicate m, :blank?
36
36
  end
37
37
 
38
38
  assert_instance_method :create, content do |m|
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
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 /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
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 /@account\.destroy/, m
56
- assert_match /format\.html { redirect_to accounts_url \}/, m
57
- assert_match /format\.json \{ head :no_content \}/, m
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
@@ -1,4 +1,8 @@
1
1
  class TestApp < Rails::Application
2
+ if config.respond_to?(:load_defaults)
3
+ config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}")
4
+ end
5
+
2
6
  if Rails.version.to_s.first >= '4'
3
7
  config.eager_load = false
4
8
  config.secret_key_base = 'abc123'
@@ -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
- assert_equal CustomSerializer, Serializer.serializer_for('Custom')
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
- assert_equal(nil, DefaultSerializer.new(nil).serializable_object)
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
@@ -21,6 +21,7 @@ module ActiveModel
21
21
  serializer = Class.new(ActiveModel::Serializer) do
22
22
  attributes :url
23
23
 
24
+ alias_method :url, :url # silence redefinition warning
24
25
  def url
25
26
  profile_url(id: object.object_id)
26
27
  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.11
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-09 00:00:00.000000000 Z
13
+ date: 2024-04-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel