validates_timeliness 8.0.0.beta1 → 8.0.0

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: 446d638f58bf6867dcd02c8d3f89e7c339bde180c4eb56aa49be03860722a8d7
4
- data.tar.gz: 33c94183ebfc40ee0d90ab1d05ea6e84a65d8e0912fbdc9a7a6338623f403d6f
3
+ metadata.gz: fddd24dc1daff9d9c90db6d6cb477519ab77abcf5dc8c55c5c69af61504eba46
4
+ data.tar.gz: e16bbad97a83834a912610ff682fe2c93ef7204e0b19f070becd84e4e3ebaf18
5
5
  SHA512:
6
- metadata.gz: 96aba97841df97ade11d86fcf1f28c91c323755f03fc49511fa821383030c3c1eab24d1b88df5e741ab3c2630fb80e86498437c06ded734030044593878c5f66
7
- data.tar.gz: 020b4690d0b73f82ff21bc8c9c974fe925c6df216a4db0634678158705cc346808ffbc09d74c98fc03ded15867a0ace1e14d1b3da153819bf8667e95bada068d
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=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 = '8.0.0.beta1'
2
+ VERSION = '8.0.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: 8.0.0.beta1
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-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
@@ -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: 1.3.1
130
+ version: '0'
134
131
  requirements: []
135
132
  rubygems_version: 3.4.19
136
133
  signing_key:
@@ -1,13 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 7.0.0"
6
- gem "rspec"
7
- gem "rspec-rails", "~> 6.0"
8
- gem "sqlite3", "~> 1.4"
9
- gem "byebug"
10
- gem "appraisal"
11
- gem "nokogiri"
12
-
13
- gemspec path: "../"
@@ -1,13 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 7.1.0"
6
- gem "rspec"
7
- gem "rspec-rails", "~> 6.0"
8
- gem "sqlite3", "~> 1.4"
9
- gem "byebug"
10
- gem "appraisal"
11
- gem "nokogiri"
12
-
13
- gemspec path: "../"
@@ -1,13 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 7.2.0"
6
- gem "rspec"
7
- gem "rspec-rails", "~> 6.0"
8
- gem "sqlite3", "~> 1.4"
9
- gem "byebug"
10
- gem "appraisal"
11
- gem "nokogiri"
12
-
13
- gemspec path: "../"