active_model_serializers 0.9.8 → 0.9.9

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: e9f526564b9458ceea3d9391ddbf81cf996ff713dbb217bcec1c22931b4cd028
4
- data.tar.gz: ac5641428e5b17ffa605bc7337f8f77000354a2a47f1a5ed7244ab50cdca84b2
3
+ metadata.gz: 52331f8ebc5267f272b9823aca4573af1f8a3493ff31ab42255a62003ec21c7e
4
+ data.tar.gz: c050584bb445c216b604b33ea421c5705e0a7a35842d609edf2b2ce87f0facf5
5
5
  SHA512:
6
- metadata.gz: af47a8298fbc563716f0c7b4a9e0d92b85243ead1b0ccac561703d17f09574a3e65f280adedbb24ee7d65c0634c4ca343c58aa665628ff75d7e220b89025e91d
7
- data.tar.gz: 6974a26799a967fbb8b172092be014deb775909a52cf10cf4e7dc88b5c05c96f6b6acbb3d245f9ad9032c743c2048c1afd8335d3a899c3111f2d6b48015800f7
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.8...0-9-stable)
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
 
@@ -1,5 +1,5 @@
1
1
  module ActiveModel
2
2
  class Serializer
3
- VERSION = '0.9.8'.freeze
3
+ VERSION = '0.9.9'.freeze
4
4
  end
5
5
  end
@@ -66,10 +66,14 @@ end
66
66
  ArraySerializer
67
67
  end
68
68
  else
69
- klass_name = build_serializer_class(resource, options)
70
- Serializer.serializers_cache.fetch_or_store(klass_name) do
71
- _const_get(klass_name)
72
- end
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
- klass_name << "#{resource.class.name}Serializer"
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
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveModelSerializers
2
3
  class Model
3
4
  module Caching
@@ -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
 
@@ -9,7 +9,7 @@ module ActionController
9
9
  end
10
10
 
11
11
  def render_text
12
- render text: 'ok'
12
+ render plain: 'ok'
13
13
  end
14
14
 
15
15
  def render_template
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)
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  class AccountsController < ApplicationController
2
3
  end
@@ -1,2 +1,3 @@
1
+ # frozen_string_literal: true
1
2
  module AccountsHelper
2
3
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class AccountSerializer < ActiveModel::Serializer
2
3
  attributes :id
3
4
  end
@@ -1 +1,2 @@
1
- Rails.application.routes.draw { }
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 < ActiveModel::TestCase
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 < ActiveModel::TestCase
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.8
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: 2020-12-10 00:00:00.000000000 Z
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.4
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