validates_timeliness 7.0.0 → 7.1.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: 506a3b1b6bf8487da01734e154c8bbd8c4afd5ab308dc11b4928b26c30d1a658
4
- data.tar.gz: 3c380ad2708dc2946a274c473451bb1db6c1d71d0e5da462b658dad735cc9560
3
+ metadata.gz: d882843a354b86918dd2709809168d5dcbaf024319eeb424b1e0ff56f7731512
4
+ data.tar.gz: 0d5c06701e489c7332b59032055a25bcd4c2887f68c95b49a2d4192ecf313d71
5
5
  SHA512:
6
- metadata.gz: 2ef5523111dee8a055989d0fa7c751d6dc34e959e2442ef99b0b46050097a31983a350ab4d6a1d3bc00ac4ebc4d00320622c9cc7aaad799535bd6dcb2084849f
7
- data.tar.gz: b15a9e6cd84b59830b45a3bce59d9cc664b2a0a5504423a355cea340614ae2a136a41ee37fc180f00b70398cd50deb67d20a1459165945fccc28eb2d79ee73e2
6
+ metadata.gz: dc46ee39a4f707078094de96dd795c75f6287343c3a020be49a8455c76a07aad0cd4d26d46b143ca4149c81a8d54c273a32575ef7f0bc23fa63317ccaffc1851
7
+ data.tar.gz: 68a0b32a966d7c1a3df5d33c7642eac1c92efa276059b543b8240e73535fa5538e51c580be3362c4011b8f1838bc03817e7b7cc07d7219e68a18b2299cacf6a3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # 7.1.0 [2024-12-31]
2
+ * Support passing non-reserved validation options to errors
3
+
4
+ # 7.0.0 [2024-11-30]
5
+ * Support Rails v7.x
6
+ * Removed all method overrides in ActiveModel now that the datetime type correctly stores before_type_cast values.
7
+
8
+ # 6.0.1 [2023-01-12]
9
+ * TODO need to complete this
10
+
11
+ # 6.0.0 [2022-10-20]
12
+ * TODO need to complete this
13
+
1
14
  # 5.0.0 [2021-04-03]
2
15
  * Fix DateTimeSelect extension support (AquisTech)
3
16
  * Relaxed Timeliness dependency version which allows for >= 0.4.0 with
@@ -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" }
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=nil)
87
- value = format_error_value(value) if value
88
- message_options = { message: options.fetch(:"#{message}_message", options[:message]), restriction: value }
89
- record.errors.add(attr_name, message, **message_options)
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
@@ -1,3 +1,3 @@
1
1
  module ValidatesTimeliness
2
- VERSION = '7.0.0'
2
+ VERSION = '7.1.0'
3
3
  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: 7.0.0
4
+ version: 7.1.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-30 00:00:00.000000000 Z
11
+ date: 2024-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
133
  requirements: []
134
- rubygems_version: 3.3.27
134
+ rubygems_version: 3.4.19
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: Date and time validation plugin for Rails which allows custom formats