active_data 1.1.7 → 1.2.0

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: 5de412d5036c1e3192c87b9c7c7cc553cccaa5d53dc48adb32d992c3cf9fca25
4
- data.tar.gz: 52c67fb161d13a2f7b4791f048c662962b2f0355b77fb8f10d434e6e5279692f
3
+ metadata.gz: 80daeb6d630cc5fc243193c917e0b43f19b2fce35a746200551921f3892e1677
4
+ data.tar.gz: 4fc2d73f4d3a59ce0804fa652ba782ee33997e9be4870b4ee402d67b920a8c45
5
5
  SHA512:
6
- metadata.gz: a804cb81e49839e78dbd9de0bd7c670bfde5b34c46651009f15bc70b890edae3a2148d0fd48251179fe83068769c6ddb950969cb2f8eb06b116e1c184d2724e2
7
- data.tar.gz: 6b8277845088785bb3a4cd95eb2c56882a7ece7c1cb395e04106717a1ec7ace440709b70c7bec9150be2c9b48626cbb458e8c6882ab01ac808067e428f1a55c3
6
+ metadata.gz: 3d8fe25346c0e72ac3600ed8f89266864cf86081d8a0db463e4b856688e7c5cd7a936b76c872f7470a0f942989ecc51bf5e1a0615ea68f74855119910607b139
7
+ data.tar.gz: c0f31ed6be42bbe6e3d06f82e4d546c04b72b7a527cb628019516531b430273a89eae8c727a4c4edc2010aa3cdd80fa8195953f793296e4726b2d5f666b973ec
@@ -0,0 +1,35 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ rspec:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ include:
9
+ - { ruby: '2.3', rails: '4.2' }
10
+ - { ruby: '2.4', rails: '5.0' }
11
+ - { ruby: '2.5', rails: '5.1' }
12
+ - { ruby: '2.6', rails: '5.2' }
13
+ - { ruby: '2.7', rails: '6.0' }
14
+ - { ruby: '3.0', rails: '6.1' }
15
+ - { ruby: '3.0', rails: '7.0' }
16
+ runs-on: ubuntu-latest
17
+ env:
18
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails.${{ matrix.rails }}.gemfile
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true
25
+ - run: bundle exec rspec
26
+
27
+ rubocop:
28
+ runs-on: ubuntu-latest
29
+ steps:
30
+ - uses: actions/checkout@v2
31
+ - uses: ruby/setup-ruby@v1
32
+ with:
33
+ ruby-version: 3.0
34
+ bundler-cache: true
35
+ - run: bundle exec rubocop
data/Appraisals CHANGED
@@ -1,4 +1,4 @@
1
- %w[4.2 5.1 5.2 6.0].each do |version|
1
+ %w[4.2 5.0 5.1 5.2 6.0 6.1 7.0].each do |version|
2
2
  appraise "rails.#{version}" do
3
3
  gem 'activesupport', "~> #{version}.0"
4
4
  gem 'activemodel', "~> #{version}.0"
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # master
2
2
 
3
+ # Version 1.2.0
4
+
5
+ * Rails 6.1 and 7 support (#80). Thanks to @ojab and @rewritten
6
+
3
7
  # Version 1.1.7
4
8
 
5
9
  * Add typecasting from `ActionController::Parameters` to `Hash` (#73)
@@ -0,0 +1,15 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 5.0.0"
6
+ gem "activemodel", "~> 5.0.0"
7
+ gem "activerecord", "~> 5.0.0"
8
+ gem "sqlite3", "~> 1.3.6"
9
+
10
+ group :test do
11
+ gem "guard"
12
+ gem "guard-rspec"
13
+ end
14
+
15
+ gemspec path: "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 6.1.0"
6
+ gem "activemodel", "~> 6.1.0"
7
+ gem "activerecord", "~> 6.1.0"
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec path: "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 7.0.0"
6
+ gem "activemodel", "~> 7.0.0"
7
+ gem "activerecord", "~> 7.0.0"
8
+
9
+ group :test do
10
+ gem "guard"
11
+ gem "guard-rspec"
12
+ end
13
+
14
+ gemspec path: "../"
@@ -1,3 +1,4 @@
1
+ require 'active_model/version'
1
2
  require 'active_data/model/attributes/reflections/represents'
2
3
  require 'active_data/model/attributes/represents'
3
4
 
@@ -67,14 +68,24 @@ module ActiveData
67
68
  #
68
69
  def emerge_represented_attributes_errors!
69
70
  self.class.represented_attributes.each do |attribute|
70
- key = :"#{attribute.reference}.#{attribute.column}"
71
- # Rails 5 pollutes messages with an empty array on key data fetch attempt
72
- messages = errors.messages[key] if errors.messages.key?(key)
73
- if messages.present?
74
- errors[attribute.column].concat(messages)
75
- errors.delete(key)
71
+ move_errors(:"#{attribute.reference}.#{attribute.column}", attribute.column)
72
+ end
73
+ end
74
+
75
+ if ActiveModel.version >= Gem::Version.new('6.1.0')
76
+ def move_errors(from, to)
77
+ errors[from].each do |error_message|
78
+ errors.add(to, error_message)
79
+ errors.delete(from)
76
80
  end
77
81
  end
82
+ else # up to 6.0.x
83
+ def move_errors(from, to)
84
+ return unless errors.messages.key?(from) && errors.messages[from].present?
85
+
86
+ errors[to].concat(errors.messages[from])
87
+ errors.delete(from)
88
+ end
78
89
  end
79
90
  end
80
91
  end
@@ -37,16 +37,44 @@ module ActiveData
37
37
  super || self.class._scope_model.respond_to?(method)
38
38
  end
39
39
 
40
- def method_missing(method, *args, &block)
41
- with_scope do
42
- model = self.class._scope_model
43
- if model.respond_to?(method)
44
- self.class._scope_model.public_send(method, *args, &block)
45
- else
46
- super
40
+ # rubocop:disable Style/MethodMissing
41
+ # rubocop-0.52.1 doesn't understand that `#respond_to_missing?` is defined above
42
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
43
+ def method_missing(method, *args, **kwargs, &block)
44
+ with_scope do
45
+ model = self.class._scope_model
46
+ if model.respond_to?(method)
47
+ result = model.public_send(method, *args, **kwargs, &block)
48
+ result.is_a?(ActiveData::Model::Scopes) ? result : model.scope_class.new(result)
49
+ else
50
+ super
51
+ end
52
+ end
53
+ end
54
+ elsif Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
55
+ def method_missing(method, *args, **kwargs, &block)
56
+ with_scope do
57
+ model = self.class._scope_model
58
+ if model.respond_to?(method)
59
+ model.public_send(method, *args, **kwargs, &block)
60
+ else
61
+ super
62
+ end
63
+ end
64
+ end
65
+ else # up to 2.6.x
66
+ def method_missing(method, *args, &block)
67
+ with_scope do
68
+ model = self.class._scope_model
69
+ if model.respond_to?(method)
70
+ model.public_send(method, *args, &block)
71
+ else
72
+ super
73
+ end
47
74
  end
48
75
  end
49
76
  end
77
+ # rubocop:enable Style/MethodMissing
50
78
 
51
79
  def with_scope
52
80
  previous_scope = self.class._scope_model.current_scope
@@ -6,7 +6,7 @@ module ActiveData
6
6
  invalid_records = Array.wrap(value).reject do |r|
7
7
  r.respond_to?(:valid?) && r.valid?(record.validation_context)
8
8
  end
9
- record.errors.add(attribute, :invalid, options.merge(value: value)) if invalid_records.present?
9
+ record.errors.add(attribute, :invalid, **options.merge(value: value)) if invalid_records.present?
10
10
  end
11
11
  end
12
12
 
@@ -1,3 +1,5 @@
1
+ require 'active_model/version'
2
+
1
3
  module ActiveData
2
4
  module Model
3
5
  module Validations
@@ -5,19 +7,26 @@ module ActiveData
5
7
  def self.validate_nested(record, name, value)
6
8
  if value.is_a?(Enumerable)
7
9
  value.each.with_index do |object, i|
8
- if yield(object)
9
- object.errors.each do |key, message|
10
- key = "#{name}.#{i}.#{key}"
11
- record.errors[key] << message
12
- record.errors[key].uniq!
13
- end
14
- end
10
+ import_errors(object.errors, record.errors, "#{name}.#{i}") if yield object
11
+ end
12
+ elsif value
13
+ import_errors(value.errors, record.errors, name.to_s) if yield value
14
+ end
15
+ end
16
+
17
+ if ActiveModel.version >= Gem::Version.new('6.1.0')
18
+ def self.import_errors(from, to, prefix)
19
+ from.each do |error|
20
+ key = "#{prefix}.#{error.attribute}"
21
+ to.import(error, attribute: key) unless to.added?(key, error.type, error.options)
15
22
  end
16
- elsif value && yield(value)
17
- value.errors.each do |key, message|
18
- key = "#{name}.#{key}"
19
- record.errors[key] << message
20
- record.errors[key].uniq!
23
+ end
24
+ else # up to 6.0.x
25
+ def self.import_errors(from, to, prefix)
26
+ from.each do |key, message|
27
+ key = "#{prefix}.#{key}"
28
+ to[key] << message
29
+ to[key].uniq!
21
30
  end
22
31
  end
23
32
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveData
2
- VERSION = '1.1.7'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
@@ -93,7 +93,7 @@ describe ActiveData::Model::Attributes::Localized do
93
93
  before do
94
94
  require 'i18n/backend/fallbacks'
95
95
  I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
96
- I18n.fallbacks.map(en: :ru)
96
+ I18n.fallbacks[:en] = [:ru]
97
97
  end
98
98
  after { I18n.fallbacks = false }
99
99
  its(:name) { should == 'Привет' }
@@ -66,11 +66,11 @@ describe ActiveData::Model::Attributes do
66
66
 
67
67
  specify { expect(model.new(column: 'hello').column).to be_nil }
68
68
  specify { expect(model.new(column: '123hello').column).to be_nil }
69
- specify { expect(model.new(column: '123').column).to eq(BigDecimal.new('123.0')) }
69
+ specify { expect(model.new(column: '123').column).to eq(BigDecimal('123.0')) }
70
70
  specify { expect(model.new(column: '123.').column).to be_nil }
71
- specify { expect(model.new(column: '123.5').column).to eq(BigDecimal.new('123.5')) }
72
- specify { expect(model.new(column: 123).column).to eq(BigDecimal.new('123.0')) }
73
- specify { expect(model.new(column: 123.5).column).to eq(BigDecimal.new('123.5')) }
71
+ specify { expect(model.new(column: '123.5').column).to eq(BigDecimal('123.5')) }
72
+ specify { expect(model.new(column: 123).column).to eq(BigDecimal('123.0')) }
73
+ specify { expect(model.new(column: 123.5).column).to eq(BigDecimal('123.5')) }
74
74
  specify { expect(model.new(column: nil).column).to be_nil }
75
75
  specify { expect(model.new(column: [123.5]).column).to be_nil }
76
76
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyromaniac
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-20 00:00:00.000000000 Z
11
+ date: 2021-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -200,11 +200,11 @@ extensions: []
200
200
  extra_rdoc_files: []
201
201
  files:
202
202
  - ".codeclimate.yml"
203
+ - ".github/workflows/ci.yml"
203
204
  - ".gitignore"
204
205
  - ".rspec"
205
206
  - ".rubocop.yml"
206
207
  - ".rubocop_todo.yml"
207
- - ".travis.yml"
208
208
  - Appraisals
209
209
  - CHANGELOG.md
210
210
  - Gemfile
@@ -214,9 +214,12 @@ files:
214
214
  - Rakefile
215
215
  - active_data.gemspec
216
216
  - gemfiles/rails.4.2.gemfile
217
+ - gemfiles/rails.5.0.gemfile
217
218
  - gemfiles/rails.5.1.gemfile
218
219
  - gemfiles/rails.5.2.gemfile
219
220
  - gemfiles/rails.6.0.gemfile
221
+ - gemfiles/rails.6.1.gemfile
222
+ - gemfiles/rails.7.0.gemfile
220
223
  - lib/active_data.rb
221
224
  - lib/active_data/active_record/associations.rb
222
225
  - lib/active_data/active_record/nested_attributes.rb
@@ -345,7 +348,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
345
348
  - !ruby/object:Gem::Version
346
349
  version: '0'
347
350
  requirements: []
348
- rubygems_version: 3.1.2
351
+ rubygems_version: 3.1.4
349
352
  signing_key:
350
353
  specification_version: 4
351
354
  summary: Working with hashes in AR style
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- sudo: false
2
-
3
- matrix:
4
- include:
5
- - rvm: 2.3.8
6
- gemfile: gemfiles/rails.4.2.gemfile
7
- - rvm: 2.4.7
8
- gemfile: gemfiles/rails.5.1.gemfile
9
- - rvm: 2.5.6
10
- gemfile: gemfiles/rails.5.2.gemfile
11
- - rvm: 2.6.4
12
- gemfile: gemfiles/rails.6.0.gemfile
13
-
14
- script:
15
- - bundle exec rspec
16
- - bundle exec rubocop