active_model_serializers 0.10.12 → 0.10.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c046246492aa51d55bec5b8ce5d2a97d9cd0ff8dba206cdde613f47aca0230e
4
- data.tar.gz: 3621cbc3e965bc80389e08b40483b6de73e4a7c7ba7ac96315e1d6e5ee2995e9
3
+ metadata.gz: 73410f3d582bb13e0defcc9307f99db6ac93aa10fe932e6143fc1de8607f4353
4
+ data.tar.gz: 02fb3af2ac4e0e934d0ed1671f29bf75a31b55c59c1c9b0174110c124ca84945
5
5
  SHA512:
6
- metadata.gz: 6fca5a15965145969a683b4f3466a067812ae6680a6a171e885854b6e8e1a684685cb0b37b6ffd52045c8404a95237ddfdd45628e39c0e33a779512ee5a56f5b
7
- data.tar.gz: c32438302db80117e82bec0964c58177cca8579765e5169d127b423927430ab2cff2c51f8b6858e09ea53044b8cf6205524398d0a2e8560738499e9e80983dfa
6
+ metadata.gz: '088a11c94eec3f4ab853733bd24e23718c775523ad3b39edeb7a7f2b82de75cb8b34c8f5ea5d8f662a17a15ec5358d503233a157123924ce89fd574bcb3719ca'
7
+ data.tar.gz: c762792c1af5084fe4d56172ab216a5bc166765ff4df7e440f855282dbd6003f3738134ed3fae34ac4ca8b05baa10064a0b021f1c0c4013258ceebb71bfb6fe9
data/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## 0.10.x
2
2
 
3
- ### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.12...0-10-stable)
3
+ ### [master (unreleased)](https://github.com/rails-api/active_model_serializers/compare/v0.10.15...0-10-stable)
4
4
 
5
5
  Breaking changes:
6
6
 
@@ -10,6 +10,36 @@ Fixes:
10
10
 
11
11
  Misc:
12
12
 
13
+ ### [v0.10.15 (2024-11-30)](https://github.com/rails-api/active_model_serializers/compare/v0.10.14...v0.10.15)
14
+
15
+ Fixes:
16
+ - [#2482](https://github.com/rails-api/active_model_serializers/pull/2482) Fix cant modify frozen Hash error due to rails changes (@vineelvineel)
17
+ - [#2460](https://github.com/rails-api/active_model_serializers/pull/2460) Don't force ActionController::TestCase to load (@eugeneius)
18
+
19
+ Misc:
20
+ - [#2483](https://github.com/rails-api/active_model_serializers/pull/2483) Support Rails 8 (@pulkit110)
21
+
22
+
23
+ ### [v0.10.14 (2023-10-05)](https://github.com/rails-api/active_model_serializers/compare/v0.10.13...v0.10.14)
24
+
25
+ Breaking changes:
26
+
27
+ Features:
28
+
29
+ Fixes:
30
+ - [#2427](https://github.com/rails-api/active_model_serializers/pull/2427) Fix checking of method defined or not (@y-yagi)
31
+
32
+ Misc:
33
+ - [#2453](https://github.com/rails-api/active_model_serializers/pull/2453) Update gem requirement to allow Rails 7.1 (@schinery, @mediafinger)
34
+ - [#2451](https://github.com/rails-api/active_model_serializers/pull/2451) Upgrade to Ubuntu 22.04 on Github Actions (@wasifhossain)
35
+ - [#2442](https://github.com/rails-api/active_model_serializers/pull/2442) Remove travis settings (@ohbarye)
36
+
37
+ ### [v0.10.13 (2022-10-13)](https://github.com/rails-api/active_model_serializers/compare/v0.10.12...v0.10.13)
38
+
39
+ Fixes:
40
+
41
+ - [#2399](https://github.com/rails-api/active_model_serializers/pull/2399) Handles edge case where requested current_page > total_pages (@f3z0)
42
+
13
43
  ### [v0.10.12 (2020-12-10)](https://github.com/rails-api/active_model_serializers/compare/v0.10.11...v0.10.12)
14
44
 
15
45
  Fixes:
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  <tr>
5
5
  <td>Build Status</td>
6
6
  <td>
7
- <a href="https://travis-ci.org/rails-api/active_model_serializers"><img src="https://api.travis-ci.org/rails-api/active_model_serializers.svg?branch=0-10-stable" alt="Build Status" ></a>
7
+ <a href="https://github.com/rails-api/active_model_serializers/actions"><img src="https://github.com/rails-api/active_model_serializers/actions/workflows/ci.yml/badge.svg?branch=0-10-stable" alt="Build Status" ></a>
8
8
  <a href="https://ci.appveyor.com/project/bf4/active-model-serializers/branch/0-10-stable"><img src="https://ci.appveyor.com/api/projects/status/x6xdjydutm54gvyt/branch/master?svg=true" alt="Build status"></a>
9
9
  </td>
10
10
  </tr>
@@ -13,7 +13,6 @@
13
13
  <td>
14
14
  <a href="https://codeclimate.com/github/rails-api/active_model_serializers"><img src="https://codeclimate.com/github/rails-api/active_model_serializers/badges/gpa.svg" alt="Code Quality"></a>
15
15
  <a href="https://codebeat.co/projects/github-com-rails-api-active_model_serializers"><img src="https://codebeat.co/badges/a9ab35fa-8b5a-4680-9d4e-a81f9a55ebcd" alt="codebeat" ></a>
16
- <a href="https://codeclimate.com/github/rails-api/active_model_serializers/coverage"><img src="https://codeclimate.com/github/rails-api/active_model_serializers/badges/coverage.svg" alt="Test Coverage"></a>
17
16
  </td>
18
17
  </tr>
19
18
  <tr>
@@ -48,8 +48,11 @@ module ActiveModel
48
48
  key ||= object.respond_to?(:name) ? object.name && object.name.underscore : nil
49
49
  # 4. key may be nil for empty collection and no serializer option
50
50
  key &&= key.pluralize
51
- # 5. fail if the key cannot be determined
52
- key || fail(ArgumentError, 'Cannot infer root key from collection type. Please specify the root or each_serializer option, or render a JSON String')
51
+ if raise_cannot_infer_root_key_error?
52
+ # 5. fail if the key cannot be determined
53
+ key || fail(CannotInferRootKeyError, 'Cannot infer root key from collection type. Please specify the root or each_serializer option, or render a JSON String')
54
+ end
55
+ key
53
56
  end
54
57
  # rubocop:enable Metrics/CyclomaticComplexity
55
58
 
@@ -60,12 +63,18 @@ module ActiveModel
60
63
  object.respond_to?(:size)
61
64
  end
62
65
 
66
+ class CannotInferRootKeyError < StandardError; end
67
+
63
68
  protected
64
69
 
65
70
  attr_reader :serializers, :options
66
71
 
67
72
  private
68
73
 
74
+ def raise_cannot_infer_root_key_error?
75
+ ActiveModelSerializers.config.raise_cannot_infer_root_key_error
76
+ end
77
+
69
78
  def serializers_from_resources
70
79
  serializer_context_class = options.fetch(:serializer_context_class, ActiveModel::Serializer)
71
80
  object.map do |resource|
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveModel
4
4
  class Serializer
5
- VERSION = '0.10.12'.freeze
5
+ VERSION = '0.10.15'.freeze
6
6
  end
7
7
  end
@@ -146,6 +146,8 @@ module ActiveModel
146
146
  config.jsonapi_include_toplevel_object = false
147
147
  config.jsonapi_use_foreign_key_on_belongs_to_relationship = false
148
148
  config.include_data_default = true
149
+ # Raise ActiveModel::Serializer::CollectionSerializer::CannotInferRootKeyError when cannot infer root key from collection type
150
+ config.raise_cannot_infer_root_key_error = true
149
151
 
150
152
  # For configuring how serializers are found.
151
153
  # This should be an array of procs.
@@ -9,7 +9,7 @@ module ActiveModelSerializers
9
9
  end
10
10
 
11
11
  def serializable_hash(options = nil)
12
- options = serialization_options(options)
12
+ options = serialization_options(options.dup)
13
13
  options[:fields] ||= instance_options[:fields]
14
14
  serialized_hash = serializer.serializable_hash(instance_options, options, self)
15
15
 
@@ -55,11 +55,15 @@ module ActiveModelSerializers
55
55
 
56
56
  def prev_page_url
57
57
  return nil if collection.current_page == FIRST_PAGE
58
+ if collection.current_page > collection.total_pages
59
+ return url_for_page(collection.total_pages)
60
+ end
58
61
  url_for_page(collection.current_page - FIRST_PAGE)
59
62
  end
60
63
 
61
64
  def next_page_url
62
- return nil if collection.total_pages == 0 || collection.current_page == collection.total_pages
65
+ return nil if collection.total_pages == 0 ||
66
+ collection.current_page >= collection.total_pages
63
67
  url_for_page(collection.next_page)
64
68
  end
65
69
 
@@ -44,9 +44,19 @@ module ActiveModelSerializers
44
44
  end
45
45
  # :nocov:
46
46
 
47
+ def extend_action_controller_test_case(&block)
48
+ if Rails::VERSION::MAJOR >= 6 || Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 2
49
+ ActiveSupport.on_load(:action_controller_test_case, run_once: true, &block)
50
+ else
51
+ ActionController::TestCase.instance_eval(&block)
52
+ end
53
+ end
54
+
47
55
  if Rails.env.test?
48
- ActionController::TestCase.send(:include, ActiveModelSerializers::Test::Schema)
49
- ActionController::TestCase.send(:include, ActiveModelSerializers::Test::Serializer)
56
+ extend_action_controller_test_case do
57
+ include ActiveModelSerializers::Test::Schema
58
+ include ActiveModelSerializers::Test::Serializer
59
+ end
50
60
  end
51
61
  end
52
62
  end
@@ -31,7 +31,12 @@ else
31
31
  ]
32
32
  desc 'Execute rubocop'
33
33
  RuboCop::RakeTask.new(:rubocop) do |task|
34
- task.options = ['--rails', '--display-cop-names', '--display-style-guide']
34
+ task.options = [
35
+ ('--rails' if Gem::Version.new(RuboCop::Version.version) < Gem::Version.new('0.72.0')),
36
+ '--display-cop-names',
37
+ '--display-style-guide',
38
+ ['--config', RUBY_VERSION < '3.0' ? '.rubocop_v0.yml' : '.rubocop_v1.yml']
39
+ ].compact
35
40
  task.formatters = ['progress']
36
41
  task.patterns = patterns
37
42
  task.fail_on_error = true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.12
4
+ version: 0.10.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Klabnik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-10 00:00:00.000000000 Z
11
+ date: 2024-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.1'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '6.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '4.1'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '6.2'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: actionpack
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -37,9 +31,6 @@ dependencies:
37
31
  - - ">="
38
32
  - !ruby/object:Gem::Version
39
33
  version: '4.1'
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '6.2'
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
@@ -47,9 +38,6 @@ dependencies:
47
38
  - - ">="
48
39
  - !ruby/object:Gem::Version
49
40
  version: '4.1'
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '6.2'
53
41
  - !ruby/object:Gem::Dependency
54
42
  name: railties
55
43
  requirement: !ruby/object:Gem::Requirement
@@ -57,9 +45,6 @@ dependencies:
57
45
  - - ">="
58
46
  - !ruby/object:Gem::Version
59
47
  version: '4.1'
60
- - - "<"
61
- - !ruby/object:Gem::Version
62
- version: '6.2'
63
48
  type: :development
64
49
  prerelease: false
65
50
  version_requirements: !ruby/object:Gem::Requirement
@@ -67,9 +52,6 @@ dependencies:
67
52
  - - ">="
68
53
  - !ruby/object:Gem::Version
69
54
  version: '4.1'
70
- - - "<"
71
- - !ruby/object:Gem::Version
72
- version: '6.2'
73
55
  - !ruby/object:Gem::Dependency
74
56
  name: minitest
75
57
  requirement: !ruby/object:Gem::Requirement
@@ -131,9 +113,6 @@ dependencies:
131
113
  - - ">="
132
114
  - !ruby/object:Gem::Version
133
115
  version: '4.1'
134
- - - "<"
135
- - !ruby/object:Gem::Version
136
- version: '6.2'
137
116
  type: :development
138
117
  prerelease: false
139
118
  version_requirements: !ruby/object:Gem::Requirement
@@ -141,9 +120,6 @@ dependencies:
141
120
  - - ">="
142
121
  - !ruby/object:Gem::Version
143
122
  version: '4.1'
144
- - - "<"
145
- - !ruby/object:Gem::Version
146
- version: '6.2'
147
123
  - !ruby/object:Gem::Dependency
148
124
  name: kaminari
149
125
  requirement: !ruby/object:Gem::Requirement
@@ -192,20 +168,6 @@ dependencies:
192
168
  - - ">="
193
169
  - !ruby/object:Gem::Version
194
170
  version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: simplecov
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- version: '0.11'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: '0.11'
209
171
  - !ruby/object:Gem::Dependency
210
172
  name: timecop
211
173
  requirement: !ruby/object:Gem::Requirement
@@ -227,9 +189,6 @@ dependencies:
227
189
  - - ">="
228
190
  - !ruby/object:Gem::Version
229
191
  version: '0.13'
230
- - - "<"
231
- - !ruby/object:Gem::Version
232
- version: 0.19.1
233
192
  type: :development
234
193
  prerelease: false
235
194
  version_requirements: !ruby/object:Gem::Requirement
@@ -237,9 +196,6 @@ dependencies:
237
196
  - - ">="
238
197
  - !ruby/object:Gem::Version
239
198
  version: '0.13'
240
- - - "<"
241
- - !ruby/object:Gem::Version
242
- version: 0.19.1
243
199
  - !ruby/object:Gem::Dependency
244
200
  name: json_schema
245
201
  requirement: !ruby/object:Gem::Requirement
@@ -261,9 +217,6 @@ dependencies:
261
217
  - - ">="
262
218
  - !ruby/object:Gem::Version
263
219
  version: '10.0'
264
- - - "<"
265
- - !ruby/object:Gem::Version
266
- version: '13.0'
267
220
  type: :development
268
221
  prerelease: false
269
222
  version_requirements: !ruby/object:Gem::Requirement
@@ -271,9 +224,6 @@ dependencies:
271
224
  - - ">="
272
225
  - !ruby/object:Gem::Version
273
226
  version: '10.0'
274
- - - "<"
275
- - !ruby/object:Gem::Version
276
- version: '13.0'
277
227
  description: ActiveModel::Serializers allows you to generate your JSON in an object-oriented
278
228
  and convention-driven manner.
279
229
  email:
@@ -334,7 +284,6 @@ files:
334
284
  - lib/active_model_serializers/logging.rb
335
285
  - lib/active_model_serializers/lookup_chain.rb
336
286
  - lib/active_model_serializers/model.rb
337
- - lib/active_model_serializers/model/caching.rb
338
287
  - lib/active_model_serializers/railtie.rb
339
288
  - lib/active_model_serializers/register_jsonapi_renderer.rb
340
289
  - lib/active_model_serializers/serializable_resource.rb
@@ -369,7 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
369
318
  - !ruby/object:Gem::Version
370
319
  version: '0'
371
320
  requirements: []
372
- rubygems_version: 3.1.4
321
+ rubygems_version: 3.3.7
373
322
  signing_key:
374
323
  specification_version: 4
375
324
  summary: Conventions-based JSON generation for Rails.
@@ -1,25 +0,0 @@
1
- module ActiveModelSerializers
2
- class Model
3
- module Caching
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- attr_writer :updated_at
8
- attributes :id
9
- end
10
-
11
- # Defaults to the downcased model name and updated_at
12
- def cache_key
13
- ActiveSupport::Cache.expand_cache_key([
14
- self.class.model_name.name.downcase,
15
- "#{id}-#{updated_at.strftime('%Y%m%d%H%M%S%9N')}"
16
- ].compact)
17
- end
18
-
19
- # Defaults to the time the serializer file was modified.
20
- def updated_at
21
- defined?(@updated_at) ? @updated_at : File.mtime(__FILE__)
22
- end
23
- end
24
- end
25
- end