unidom-common-rspec 2.0 → 2.0.1

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: '08978e31550f24686da26c0a790887b6fe033aac165ec7db16bb4dcc5f56b1cb'
4
- data.tar.gz: 78c99b4e6a005aa3313bc7c88ea88e32141ba4bd6d34981e6c90db7c9dd17328
3
+ metadata.gz: e73a57fee4cef81976cb6d387f8ee3b79c7f220533492971eed511233a545629
4
+ data.tar.gz: 9b1612de7e7f00f400326bec3b428fa870d52fd8c3eedd92272350f17236874e
5
5
  SHA512:
6
- metadata.gz: '0902ba335e02cd60910258edbe8a89fc488205a5983b4d2084b4971c935b89c12250cab02baeb6c120d2f132ead3a75d095eda3c8356f02ffd8501da25a130c3'
7
- data.tar.gz: f928fc097ae1207abda9b12f497c425e0f43b6068bf9fab9b450b92f7526050e2eced2efb949bf1657564860e8f46a6831e4149d38bc3dc89d789e4698cfe395
6
+ metadata.gz: 22e69f347d5638e3022e20111643ab5bd3a97d6a6af7749a5b949ffbe7f916c8d9a5956309e746b0bd048e944557c7863e2739804727a3b30312dc5a98d2c740
7
+ data.tar.gz: 6c42f4595da343f446ba97eec954eed80d689cd109ee43d456516b56e2a815426fb42077835612ae2b4efdc74616fe672debdb319fcf60ca20f13bb8bde15da0
data/CHANGELOG.md CHANGED
@@ -82,3 +82,7 @@
82
82
  ## v2.0
83
83
 
84
84
  1. Improved the Scope shared examples for Ruby 3.0
85
+
86
+ ## v2.0.1
87
+
88
+ 1. Improved the compatibility of Validates Numericality shared examples and Each Validator shared examples
data/ROADMAP.md CHANGED
@@ -82,3 +82,7 @@
82
82
  ## v2.0
83
83
 
84
84
  1. Improve the Scope shared examples for Ruby 3.0
85
+
86
+ ## v2.0.1
87
+
88
+ 1. Improve the compatibility of Validates Numericality shared examples and Each Validator shared examples
@@ -1,11 +1,17 @@
1
1
  shared_examples 'ActiveModel::EachValidator' do |valid_values, invalid_values|
2
2
 
3
3
  mock_model_class_name = "#{described_class.name}MockModel"
4
- mock_model_namespace = mock_model_class_name.deconstantize.constantize
5
- mock_model_name = mock_model_class_name.demodulize
6
- validator_name = described_class.to_s.underscore.chomp('_validator').to_sym
4
+ if mock_model_class_name.deconstantize.present?
5
+ mock_model_namespace = mock_model_class_name.deconstantize.constantize
6
+ mock_model_name = mock_model_class_name.demodulize
7
+ else
8
+ mock_model_namespace = Object
9
+ mock_model_name = mock_model_class_name
10
+ end
11
+
7
12
  mock_model_namespace.const_set mock_model_name, Class.new
8
- class_instance = mock_model_namespace.const_get mock_model_name
13
+ class_instance = mock_model_namespace.const_get mock_model_name
14
+ validator_name = described_class.to_s.underscore.chomp('_validator').to_sym
9
15
 
10
16
  class_instance.class_eval do
11
17
  include ActiveModel::Model
@@ -1,8 +1,8 @@
1
1
  shared_examples 'validates numericality' do |model_attributes, attribute_name, options|
2
2
 
3
3
  attribute_name = attribute_name.to_sym
4
- presence_validator = described_class.validators.select { |v| v.is_a?(ActiveRecord::Validations::PresenceValidator)&&v.attributes.include?(attribute_name) }.first
5
- excluded_validators = described_class.validators.select { |v| v.attributes.include?(attribute_name)&&![ ActiveRecord::Validations::PresenceValidator, ActiveModel::Validations::NumericalityValidator ].include?(v.class) }
4
+ presence_validator = described_class.validators.select { |v| (v.is_a?(ActiveModel::Validations::PresenceValidator)||v.is_a?(ActiveRecord::Validations::PresenceValidator))&&v.attributes.include?(attribute_name) }.first
5
+ excluded_validators = described_class.validators.select { |v| v.attributes.include?(attribute_name)&&![ ActiveRecord::Validations::PresenceValidator, ActiveRecord::Validations::NumericalityValidator, ActiveModel::Validations::PresenceValidator, ActiveModel::Validations::NumericalityValidator ].include?(v.class) }
6
6
 
7
7
  if excluded_validators.present?
8
8
  raise ArgumentError.new("The validators on the #{attribute_name.inspect} attribute must be PresenceValidator or NumericalityValidator. The excluded validator#{excluded_validators.size>1 ? 's are' : ' is'}: #{excluded_validators.inspect}.")
@@ -1,7 +1,7 @@
1
1
  module Unidom
2
2
  module Common
3
3
  module RSpec
4
- VERSION = '2.0'
4
+ VERSION = '2.0.1'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-common-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.0'
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-01 00:00:00.000000000 Z
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-rails