active_model_serializers 0.9.8 → 0.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/active_model/serializer/version.rb +1 -1
- data/lib/active_model/serializer.rb +20 -5
- data/lib/active_model_serializers/model/caching.rb +1 -0
- data/test/fixtures/poro.rb +31 -0
- data/test/integration/action_controller/serialization_test_case_test.rb +1 -1
- data/test/test_helper.rb +2 -0
- data/test/tmp/app/controllers/accounts_controller.rb +1 -0
- data/test/tmp/app/helpers/accounts_helper.rb +1 -0
- data/test/tmp/app/serializers/account_serializer.rb +1 -0
- data/test/tmp/config/routes.rb +2 -1
- data/test/unit/active_model/array_serializer/serialization_test.rb +23 -0
- data/test/unit/active_model/serializer/has_many_polymorphic_test.rb +1 -1
- data/test/unit/active_model/serializer/has_one_polymorphic_test.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52331f8ebc5267f272b9823aca4573af1f8a3493ff31ab42255a62003ec21c7e
|
4
|
+
data.tar.gz: c050584bb445c216b604b33ea421c5705e0a7a35842d609edf2b2ce87f0facf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f1799ea050b2e12bc6ea3ca43b121801a0b33858ad3ad2e3b503d940a0439ceb83ab596d53e9cb46bc85dc25e92af8350d0f54db6eea51cb867a8bb475766dc
|
7
|
+
data.tar.gz: 6c0d80acada0ae9f37638fe5ca5a95a23c43faaafba1f6474a6f337f2faadca92b587f5c83dbbe1b6ecbd38169e334940ed685dfcd88cf9c44bd7d9887667e04
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
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.9...0-9-stable)
|
4
|
+
|
5
|
+
### [v0.9.9 (2023-05-18)](https://github.com/rails-api/active_model_serializers/compare/v0.9.8...v0.9.8)
|
6
|
+
|
7
|
+
- [#2446](https://github.com/rails-api/active_model_serializers/pull/2446) Fix Ruby > 2.5 constant lookup. (@Physium)
|
4
8
|
|
5
9
|
### [v0.9.8 (2020-12-10)](https://github.com/rails-api/active_model_serializers/compare/v0.9.7...v0.9.8)
|
6
10
|
|
@@ -66,10 +66,14 @@ end
|
|
66
66
|
ArraySerializer
|
67
67
|
end
|
68
68
|
else
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
search_list = build_serializer_class_list(resource, options)
|
70
|
+
result = search_list.map do |klass_name|
|
71
|
+
Serializer.serializers_cache.fetch_or_store(klass_name) do
|
72
|
+
_const_get(klass_name)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
result.find { |serializer| !serializer.nil? }
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
@@ -118,11 +122,22 @@ end
|
|
118
122
|
attr
|
119
123
|
end
|
120
124
|
|
125
|
+
def build_serializer_class_list(resource, options)
|
126
|
+
list = []
|
127
|
+
list << build_serializer_class(resource, options)
|
128
|
+
list << build_serializer_class(resource, {})
|
129
|
+
list << build_serializer_class(resource.class.name.demodulize, {})
|
130
|
+
end
|
131
|
+
|
121
132
|
def build_serializer_class(resource, options)
|
122
133
|
"".tap do |klass_name|
|
123
134
|
klass_name << "#{options[:namespace]}::" if options[:namespace]
|
124
135
|
klass_name << options[:prefix].to_s.classify if options[:prefix]
|
125
|
-
|
136
|
+
if resource.is_a?(String)
|
137
|
+
klass_name << "#{resource}Serializer"
|
138
|
+
else
|
139
|
+
klass_name << "#{resource.class.name}Serializer"
|
140
|
+
end
|
126
141
|
end
|
127
142
|
end
|
128
143
|
|
data/test/fixtures/poro.rb
CHANGED
@@ -18,6 +18,19 @@ end
|
|
18
18
|
###
|
19
19
|
## Models
|
20
20
|
###
|
21
|
+
|
22
|
+
module TestNamespace2
|
23
|
+
class Test < Model
|
24
|
+
attr_writer :sub_test
|
25
|
+
|
26
|
+
def sub_test
|
27
|
+
@sub_test ||= TestNamespace2::SubTest.new(name: 'N1', description: 'D1')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class SubTest < Model; end
|
32
|
+
end
|
33
|
+
|
21
34
|
class User < Model
|
22
35
|
def profile
|
23
36
|
@profile ||= Profile.new(name: 'N1', description: 'D1')
|
@@ -101,6 +114,24 @@ end
|
|
101
114
|
###
|
102
115
|
## Serializers
|
103
116
|
###
|
117
|
+
|
118
|
+
module TestNamespace2
|
119
|
+
class TestSerializer < ActiveModel::Serializer
|
120
|
+
attributes :name, :email
|
121
|
+
|
122
|
+
has_one :sub_test
|
123
|
+
end
|
124
|
+
|
125
|
+
class SubTestSerializer < ActiveModel::Serializer
|
126
|
+
def description
|
127
|
+
description = object.read_attribute_for_serialization(:description)
|
128
|
+
scope ? "#{description} - #{scope}" : description
|
129
|
+
end
|
130
|
+
|
131
|
+
attributes :name, :description
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
104
135
|
class UserSerializer < ActiveModel::Serializer
|
105
136
|
attributes :name, :email
|
106
137
|
|
data/test/test_helper.rb
CHANGED
@@ -2,6 +2,8 @@ require 'bundler/setup'
|
|
2
2
|
require 'minitest/autorun'
|
3
3
|
require 'active_model_serializers'
|
4
4
|
require 'fixtures/poro'
|
5
|
+
require 'rails-controller-testing'
|
6
|
+
Rails::Controller::Testing.install
|
5
7
|
|
6
8
|
# Ensure backward compatibility with Minitest 4
|
7
9
|
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
|
data/test/tmp/config/routes.rb
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
Rails.application.routes.draw {}
|
@@ -49,6 +49,29 @@ 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')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class ModelSerializationNamespaceTest < Minitest::Test
|
57
|
+
def test_namespace
|
58
|
+
test1 = TestNamespace2::Test.new(name: 'Test 1', email: 'test1@test.com', gender: 'M')
|
59
|
+
test2 = TestNamespace2::Test.new(name: 'Test 2', email: 'test2@test.com', gender: 'M')
|
60
|
+
sub_test1 = TestNamespace2::SubTest.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
|
61
|
+
sub_test2 = TestNamespace2::SubTest.new(name: 'Name 2', description: 'Description 2', comments: 'Comments 2')
|
62
|
+
test1.sub_test = sub_test1
|
63
|
+
test2.sub_test = sub_test2
|
64
|
+
|
65
|
+
array = [test1, test2]
|
66
|
+
serializer = ArraySerializer.new(array)
|
67
|
+
|
68
|
+
expected = [
|
69
|
+
{ name: 'Test 1', email: 'test1@test.com', sub_test: { name: 'Name 1', description: 'Description 1' }},
|
70
|
+
{ name: 'Test 1', email: 'test2@test.com', sub_test: { name: 'Name 2', description: 'Description 2' }}
|
71
|
+
]
|
72
|
+
|
73
|
+
assert_equal expected, serializer.serializable_array
|
74
|
+
assert_equal expected, serializer.as_json
|
52
75
|
end
|
53
76
|
end
|
54
77
|
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module ActiveModel
|
4
4
|
class Serializer
|
5
|
-
class HasManyPolymorphicTest <
|
5
|
+
class HasManyPolymorphicTest < Minitest::Test
|
6
6
|
def setup
|
7
7
|
@association = MailSerializer._associations[:attachments]
|
8
8
|
@old_association = @association.dup
|
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module ActiveModel
|
4
4
|
class Serializer
|
5
|
-
class HasOnePolymorphicTest <
|
5
|
+
class HasOnePolymorphicTest < Minitest::Test
|
6
6
|
def setup
|
7
7
|
@association = InterviewSerializer._associations[:attachment]
|
8
8
|
@old_association = @association.dup
|
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.9
|
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: 2023-05-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
|
-
rubygems_version: 3.1.
|
170
|
+
rubygems_version: 3.1.6
|
171
171
|
signing_key:
|
172
172
|
specification_version: 4
|
173
173
|
summary: Bringing consistency and object orientation to model serialization. Works
|