validates_timeliness 8.0.0.beta1 → 8.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/validates_timeliness/validator.rb +14 -5
- data/lib/validates_timeliness/version.rb +1 -1
- data/spec/validates_timeliness/validator_spec.rb +20 -0
- metadata +4 -7
- data/gemfiles/rails_7_0.gemfile +0 -13
- data/gemfiles/rails_7_1.gemfile +0 -13
- data/gemfiles/rails_7_2.gemfile +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fddd24dc1daff9d9c90db6d6cb477519ab77abcf5dc8c55c5c69af61504eba46
|
4
|
+
data.tar.gz: e16bbad97a83834a912610ff682fe2c93ef7204e0b19f070becd84e4e3ebaf18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 443d66dd2feb66c01e77294236fbf7b197e358246dbd40b9014c5b888e23810219851d89dd320db9e0a256bc62a6402fdbcc326684941566dbdc331285faefce
|
7
|
+
data.tar.gz: 0d1f13688d2a26ffaa940b409c9f6139cd780b21ffffb1ef02470718bd63d3d1e86bf2bcf4e411b15de4cb7badb215cdd7df8088f59ff63f044f924fcbdf570d
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
+
# 8.0.0 [2024-12-31]
|
2
|
+
* Support Rails v8.x
|
3
|
+
* Support passing non-reserved validation options to errors
|
4
|
+
|
1
5
|
# 7.0.0 [2024-11-30]
|
6
|
+
* Support Rails v7.x
|
2
7
|
* Removed all method overrides in ActiveModel now that the datetime type correctly stores before_type_cast values.
|
3
8
|
|
4
9
|
# 6.0.1 [2023-01-12]
|
@@ -21,6 +21,8 @@ module ValidatesTimeliness
|
|
21
21
|
|
22
22
|
RESTRICTION_ERROR_MESSAGE = "Error occurred validating %s for %s restriction:\n%s"
|
23
23
|
|
24
|
+
RESERVED_OPTIONS = (RESTRICTIONS.keys + RESTRICTIONS.keys.map { |option| :"#{option}_message" }).freeze
|
25
|
+
|
24
26
|
def self.kind
|
25
27
|
:timeliness
|
26
28
|
end
|
@@ -72,7 +74,7 @@ module ValidatesTimeliness
|
|
72
74
|
begin
|
73
75
|
restriction_value = @converter.type_cast_value(@converter.evaluate(options[restriction], record))
|
74
76
|
unless value.send(RESTRICTIONS[restriction], restriction_value)
|
75
|
-
add_error(record, attr_name, restriction, restriction_value) and break
|
77
|
+
add_error(record, attr_name, restriction, value: value, restriction_value: restriction_value) and break
|
76
78
|
end
|
77
79
|
rescue => e
|
78
80
|
unless ValidatesTimeliness.ignore_restriction_errors
|
@@ -83,13 +85,20 @@ module ValidatesTimeliness
|
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
86
|
-
def add_error(record, attr_name, message, value
|
87
|
-
|
88
|
-
|
89
|
-
|
88
|
+
def add_error(record, attr_name, message, restriction_value: nil, value: nil)
|
89
|
+
error_options = options.except(*RESERVED_OPTIONS).merge!(
|
90
|
+
restriction: format_error_value(restriction_value),
|
91
|
+
value: value
|
92
|
+
)
|
93
|
+
|
94
|
+
message_text = options[:"#{message}_message"]
|
95
|
+
error_options[:message] = message_text if message_text.present?
|
96
|
+
|
97
|
+
record.errors.add(attr_name, message, **error_options)
|
90
98
|
end
|
91
99
|
|
92
100
|
def format_error_value(value)
|
101
|
+
return unless value
|
93
102
|
format = I18n.t(@type, default: DEFAULT_ERROR_VALUE_FORMATS[@type], scope: 'validates_timeliness.error_value_formats')
|
94
103
|
value.strftime(format)
|
95
104
|
end
|
@@ -185,6 +185,26 @@ RSpec.describe ValidatesTimeliness::Validator do
|
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
188
|
+
describe "custom option" do
|
189
|
+
it "should pass custom options to the error" do
|
190
|
+
Person.validates_datetime :birth_datetime, :on_or_before => Time.utc(2010,1,2,3,4,5), :custom => 'option'
|
191
|
+
|
192
|
+
with_each_model_value(:birth_datetime, Time.utc(2010,1,2,3,4,5,10000), Person) do |record, value|
|
193
|
+
expect(record).to_not be_valid
|
194
|
+
expect(record.errors.where(:birth_datetime).first.options).to include(custom: 'option')
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should not pass config options to the error" do
|
199
|
+
Person.validates_datetime :birth_datetime, :on_or_before => Time.utc(2010,1,2,3,4,5), :custom => 'option'
|
200
|
+
|
201
|
+
with_each_model_value(:birth_datetime, Time.utc(2010,1,2,3,4,5,10000), Person) do |record, value|
|
202
|
+
expect(record).to_not be_valid
|
203
|
+
expect(record.errors.where(:birth_datetime).first.options.keys).to_not include(:on_or_before)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
188
208
|
describe "restriction value errors" do
|
189
209
|
let(:person) { Person.new(:birth_date => Date.today) }
|
190
210
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_timeliness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.0.0
|
4
|
+
version: 8.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Meehan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -66,9 +66,6 @@ files:
|
|
66
66
|
- LICENSE
|
67
67
|
- README.md
|
68
68
|
- Rakefile
|
69
|
-
- gemfiles/rails_7_0.gemfile
|
70
|
-
- gemfiles/rails_7_1.gemfile
|
71
|
-
- gemfiles/rails_7_2.gemfile
|
72
69
|
- gemfiles/rails_8_0.gemfile
|
73
70
|
- init.rb
|
74
71
|
- lib/generators/validates_timeliness/install_generator.rb
|
@@ -128,9 +125,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
125
|
version: '0'
|
129
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
127
|
requirements:
|
131
|
-
- - "
|
128
|
+
- - ">="
|
132
129
|
- !ruby/object:Gem::Version
|
133
|
-
version:
|
130
|
+
version: '0'
|
134
131
|
requirements: []
|
135
132
|
rubygems_version: 3.4.19
|
136
133
|
signing_key:
|
data/gemfiles/rails_7_0.gemfile
DELETED
data/gemfiles/rails_7_1.gemfile
DELETED
data/gemfiles/rails_7_2.gemfile
DELETED