validates_timeliness 5.0.1 → 6.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +21 -4
- data/CHANGELOG.rdoc +3 -5
- data/LICENSE +1 -1
- data/README.rdoc +20 -16
- data/Rakefile +3 -2
- data/gemfiles/{rails_5_0.gemfile → rails_6_0.gemfile} +2 -2
- data/gemfiles/{rails_5_1.gemfile → rails_6_1.gemfile} +2 -2
- data/gemfiles/{rails_5_2.gemfile → rails_edge.gemfile} +2 -2
- data/lib/validates_timeliness/converter.rb +2 -3
- data/lib/validates_timeliness/extensions/date_time_select.rb +1 -1
- data/lib/validates_timeliness/helper_methods.rb +1 -1
- data/lib/validates_timeliness/validator.rb +1 -1
- data/lib/validates_timeliness/version.rb +1 -1
- data/spec/support/test_model.rb +2 -2
- data/spec/validates_timeliness/converter_spec.rb +17 -48
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e153117c69ae4a75bde2e8a9cb1334118fbc083be371ed10d6658bf6a82aa8fb
|
4
|
+
data.tar.gz: cb77f367f614fd8c6fbf754cd5b1d1beed8845a5afe74937e97e38ab7da8ee8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c67105f25b5473d6bd3a4f5b07763382424da6103053f7fa477a50c82a38d5fc3e61638854a1016d51da3c765419fe4a4986cee1105afbaf0255f2bf1bd623df
|
7
|
+
data.tar.gz: f5364e75b90e6bd60836e4858cb6fa2debeb557540de870aa6828a5c462329c550cb5af444d4e9337172653f56db04a1b0ef971d81a7fbace564ab08cf81c18e
|
data/.travis.yml
CHANGED
@@ -1,14 +1,31 @@
|
|
1
|
+
dist: focal
|
2
|
+
os: linux
|
1
3
|
language: ruby
|
2
4
|
before_install: gem install bundler
|
3
5
|
cache: bundler
|
4
6
|
|
5
7
|
gemfile:
|
6
|
-
- gemfiles/
|
7
|
-
- gemfiles/
|
8
|
-
- gemfiles/
|
8
|
+
- gemfiles/rails_6_0.gemfile
|
9
|
+
- gemfiles/rails_6_1.gemfile
|
10
|
+
- gemfiles/rails_edge.gemfile
|
9
11
|
|
10
12
|
rvm:
|
11
|
-
- "2.5.
|
13
|
+
- "2.5.8"
|
14
|
+
- "2.6.6"
|
15
|
+
- "2.7.2"
|
16
|
+
- "3.0.0"
|
17
|
+
- ruby-head
|
18
|
+
|
19
|
+
jobs:
|
20
|
+
allow_failures:
|
21
|
+
- rvm: ruby-head
|
22
|
+
- gemfile: gemfiles/rails_edge.gemfile
|
23
|
+
exclude:
|
24
|
+
- rvm: 2.5.8
|
25
|
+
gemfile: gemfiles/rails_edge.gemfile
|
26
|
+
- rvm: 2.6.6
|
27
|
+
gemfile: gemfiles/rails_edge.gemfile
|
28
|
+
fast_finish: true
|
12
29
|
|
13
30
|
script: 'bundle exec rspec'
|
14
31
|
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
=
|
2
|
-
* Ensure Date value is converted to time in zone for zone aware attributes
|
3
|
-
* Use ActiveSupport #change method to zero out usec
|
4
|
-
|
5
|
-
= 5.0.0 [2021-04-03]
|
1
|
+
= [UNRELEASED]
|
6
2
|
* Fix DateTimeSelect extension support (AquisTech)
|
7
3
|
* Relaxed Timeliness dependency version which allows for >= 0.4.0 with
|
8
4
|
threadsafety fix for use_us_formats and use_euro_formats for hot switching
|
9
5
|
in a request.
|
10
6
|
* Add initializer to ensure Timeliness v0.4+ ambiguous date config is set
|
11
7
|
correctly when using `use_euro_formats` or `remove_use_formats'.
|
8
|
+
* Add Ruby 3 compatibility
|
9
|
+
* Add Rails 6.1 compatibility
|
12
10
|
|
13
11
|
Breaking Changes
|
14
12
|
* Update Multiparameter extension to use ActiveRecord type classes with multiparameter handling
|
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
= ValidatesTimeliness {<img src="https://travis-ci.org/adzap/validates_timeliness.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/adzap/validates_timeliness]
|
2
2
|
|
3
|
-
* Source:
|
4
|
-
* Issues:
|
3
|
+
* Source: https://github.com/adzap/validates_timeliness
|
4
|
+
* Issues: https://github.com/adzap/validates_timeliness/issues
|
5
5
|
|
6
6
|
== Description
|
7
7
|
|
8
|
-
Complete validation of dates, times and datetimes for Rails
|
8
|
+
Complete validation of dates, times and datetimes for Rails 6.x and ActiveModel.
|
9
9
|
|
10
|
-
|
10
|
+
Old Rails versions:
|
11
|
+
|
12
|
+
* Rails 4.x: [https://github.com/adzap/validates_timeliness/tree/4-0-stable]
|
13
|
+
|
14
|
+
* Rails 5.x: [https://github.com/adzap/validates_timeliness/tree/5-0-stable]
|
11
15
|
|
12
16
|
|
13
17
|
== Features
|
@@ -18,7 +22,7 @@ If you a looking for the old version for Rails 4.x go here [https://github.com/a
|
|
18
22
|
|
19
23
|
* Only Rails date/time validation plugin offering complete validation (See ORM/ODM support)
|
20
24
|
|
21
|
-
* Uses extensible date/time parser (Using {timeliness gem}[
|
25
|
+
* Uses extensible date/time parser (Using {timeliness gem}[https://github.com/adzap/timeliness]. See Plugin Parser)
|
22
26
|
|
23
27
|
* Adds extensions to fix Rails date/time select issues (See Extensions)
|
24
28
|
|
@@ -30,13 +34,13 @@ If you a looking for the old version for Rails 4.x go here [https://github.com/a
|
|
30
34
|
== Installation
|
31
35
|
|
32
36
|
# in Gemfile
|
33
|
-
gem 'validates_timeliness', '~>
|
37
|
+
gem 'validates_timeliness', '~> 6.0.0.alpha1'
|
34
38
|
|
35
39
|
# Run bundler
|
36
40
|
$ bundle install
|
37
41
|
|
38
42
|
Then run
|
39
|
-
|
43
|
+
|
40
44
|
$ rails generate validates_timeliness:install
|
41
45
|
|
42
46
|
This creates configuration initializer and locale files. In the initializer, there are a number of config
|
@@ -97,7 +101,7 @@ Temporal options (or restrictions):
|
|
97
101
|
:on_or_before - Attribute must be equal to or before this value to be valid
|
98
102
|
:after - Attribute must be after this value to be valid
|
99
103
|
:on_or_after - Attribute must be equal to or after this value to be valid
|
100
|
-
:between - Attribute must be between the values to be valid. Range or Array of 2 values.
|
104
|
+
:between - Attribute must be between the values to be valid. Range or Array of 2 values.
|
101
105
|
|
102
106
|
Regular validation options:
|
103
107
|
:allow_nil - Allow a nil value to be valid
|
@@ -142,7 +146,7 @@ like so
|
|
142
146
|
|
143
147
|
end
|
144
148
|
|
145
|
-
By default the plugin extends ActiveRecord if loaded. If you wish to extend another ORM then look at the {wiki page}[
|
149
|
+
By default the plugin extends ActiveRecord if loaded. If you wish to extend another ORM then look at the {wiki page}[https://github.com/adzap/validates_timeliness/wiki/ORM-Support] for more information.
|
146
150
|
|
147
151
|
It is not required that you use a shim, but you will not catch errors when the attribute value is invalid and evaluated to nil.
|
148
152
|
|
@@ -184,7 +188,7 @@ It is highly recommended you use the I18n system for error messages.
|
|
184
188
|
|
185
189
|
=== Plugin Parser
|
186
190
|
|
187
|
-
The plugin uses the {timeliness gem}[
|
191
|
+
The plugin uses the {timeliness gem}[https://github.com/adzap/timeliness] as a fast, configurable and extensible date and time parser.
|
188
192
|
You can add or remove valid formats for dates, times, and datetimes. It is also more strict than the
|
189
193
|
Ruby parser, which means it won't accept day of the month if it's not a valid number for the month.
|
190
194
|
|
@@ -194,12 +198,12 @@ By default the parser is disabled. To enable it:
|
|
194
198
|
config.use_plugin_parser = true
|
195
199
|
|
196
200
|
Enabling the parser will mean that strings assigned to attributes validated with the plugin will be parsed
|
197
|
-
using the gem. See the wiki[
|
201
|
+
using the gem. See the wiki[https://github.com/adzap/validates_timeliness/wiki/Plugin-Parser] for more details about the parser configuration.
|
198
202
|
|
199
203
|
|
200
204
|
=== Restriction Shorthand
|
201
205
|
|
202
|
-
It is common to restrict an attribute to being on or before the current time or current day.
|
206
|
+
It is common to restrict an attribute to being on or before the current time or current day.
|
203
207
|
To specify this you need to use a lambda as an option value e.g. <tt>lambda { Time.current }</tt>.
|
204
208
|
This can be tedious noise amongst your validations for something so common. To combat this the
|
205
209
|
plugin allows you to use shorthand symbols for often used relative times or dates.
|
@@ -208,7 +212,7 @@ Just provide the symbol as the option value like so:
|
|
208
212
|
|
209
213
|
validates_date :birth_date, on_or_before: :today
|
210
214
|
|
211
|
-
The :today symbol is evaluated as <tt>lambda { Date.
|
215
|
+
The :today symbol is evaluated as <tt>lambda { Date.current }</tt>. The :now and :today
|
212
216
|
symbols are pre-configured. Configure your own like so:
|
213
217
|
|
214
218
|
# in the setup block
|
@@ -220,7 +224,7 @@ symbols are pre-configured. Configure your own like so:
|
|
220
224
|
=== Default Timezone
|
221
225
|
|
222
226
|
The plugin needs to know the default timezone you are using when parsing or type casting values. If you are using
|
223
|
-
ActiveRecord then the default is automatically set to the same default zone as ActiveRecord. If you are using
|
227
|
+
ActiveRecord then the default is automatically set to the same default zone as ActiveRecord. If you are using
|
224
228
|
another ORM you may need to change this setting.
|
225
229
|
|
226
230
|
# in the setup block
|
@@ -286,12 +290,12 @@ To activate it, uncomment this line in the initializer:
|
|
286
290
|
|
287
291
|
== Contributors
|
288
292
|
|
289
|
-
To see the generous people who have contributed code, take a look at the {contributors list}[
|
293
|
+
To see the generous people who have contributed code, take a look at the {contributors list}[https://github.com/adzap/validates_timeliness/contributors].
|
290
294
|
|
291
295
|
|
292
296
|
== Maintainers
|
293
297
|
|
294
|
-
* {Adam Meehan}[
|
298
|
+
* {Adam Meehan}[https://github.com/adzap]
|
295
299
|
|
296
300
|
|
297
301
|
== License
|
data/Rakefile
CHANGED
@@ -19,10 +19,11 @@ end
|
|
19
19
|
|
20
20
|
desc 'Generate documentation for plugin.'
|
21
21
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
22
|
+
rdoc.main = 'README.rdoc'
|
22
23
|
rdoc.rdoc_dir = 'rdoc'
|
23
24
|
rdoc.title = 'ValidatesTimeliness'
|
24
|
-
rdoc.options << '--line-numbers'
|
25
|
-
rdoc.rdoc_files.include('README')
|
25
|
+
rdoc.options << '--line-numbers'
|
26
|
+
rdoc.rdoc_files.include('README.rdoc')
|
26
27
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
27
28
|
end
|
28
29
|
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
source "http://rubygems.org"
|
4
4
|
|
5
|
-
gem "rails", "~>
|
5
|
+
gem "rails", "~> 6.0.0"
|
6
6
|
gem "rspec"
|
7
7
|
gem "rspec-rails", "~> 3.7"
|
8
|
+
gem "sqlite3"
|
8
9
|
gem "timecop"
|
9
10
|
gem "byebug"
|
10
11
|
gem "appraisal"
|
11
|
-
gem "sqlite3", "~> 1.3.6"
|
12
12
|
gem "nokogiri", "~> 1.8"
|
13
13
|
|
14
14
|
gemspec path: "../"
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
source "http://rubygems.org"
|
4
4
|
|
5
|
-
gem "rails", "~>
|
5
|
+
gem "rails", "~> 6.1.0"
|
6
6
|
gem "rspec"
|
7
7
|
gem "rspec-rails", "~> 3.7"
|
8
|
+
gem "sqlite3"
|
8
9
|
gem "timecop"
|
9
10
|
gem "byebug"
|
10
11
|
gem "appraisal"
|
11
|
-
gem "sqlite3", "~> 1.3.6"
|
12
12
|
gem "nokogiri", "~> 1.8"
|
13
13
|
|
14
14
|
gemspec path: "../"
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
source "http://rubygems.org"
|
4
4
|
|
5
|
-
gem "rails", "
|
5
|
+
gem "rails", git: "https://github.com/rails/rails.git", branch: "main"
|
6
6
|
gem "rspec"
|
7
7
|
gem "rspec-rails", "~> 3.7"
|
8
|
+
gem "sqlite3"
|
8
9
|
gem "timecop"
|
9
10
|
gem "byebug"
|
10
11
|
gem "appraisal"
|
11
|
-
gem "sqlite3", "~> 1.3.6"
|
12
12
|
gem "nokogiri", "~> 1.8"
|
13
13
|
|
14
14
|
gemspec path: "../"
|
@@ -19,13 +19,12 @@ module ValidatesTimeliness
|
|
19
19
|
when :date
|
20
20
|
value.to_date
|
21
21
|
when :datetime
|
22
|
-
value.is_a?(Time) ? value :
|
22
|
+
value.is_a?(Time) ? value : value.to_time
|
23
23
|
else
|
24
24
|
value
|
25
25
|
end
|
26
|
-
|
27
26
|
if ignore_usec && value.is_a?(Time)
|
28
|
-
value.
|
27
|
+
Timeliness::Parser.make_time(Array(value).reverse[4..9], (:current if time_zone_aware?))
|
29
28
|
else
|
30
29
|
value
|
31
30
|
end
|
@@ -86,7 +86,7 @@ module ValidatesTimeliness
|
|
86
86
|
def add_error(record, attr_name, message, value=nil)
|
87
87
|
value = format_error_value(value) if value
|
88
88
|
message_options = { :message => options.fetch(:"#{message}_message", options[:message]), :restriction => value }
|
89
|
-
record.errors.add(attr_name, message, message_options)
|
89
|
+
record.errors.add(attr_name, message, **message_options)
|
90
90
|
end
|
91
91
|
|
92
92
|
def format_error_value(value)
|
data/spec/support/test_model.rb
CHANGED
@@ -15,11 +15,11 @@ module TestModel
|
|
15
15
|
self.model_attributes[name] = type
|
16
16
|
end
|
17
17
|
|
18
|
-
def define_method_attribute=(attr_name)
|
18
|
+
def define_method_attribute=(attr_name, owner: nil)
|
19
19
|
generated_attribute_methods.module_eval("def #{attr_name}=(new_value); @attributes['#{attr_name}']=self.class.type_cast('#{attr_name}', new_value); end", __FILE__, __LINE__)
|
20
20
|
end
|
21
21
|
|
22
|
-
def define_method_attribute(attr_name)
|
22
|
+
def define_method_attribute(attr_name, owner: nil)
|
23
23
|
generated_attribute_methods.module_eval("def #{attr_name}; @attributes['#{attr_name}']; end", __FILE__, __LINE__)
|
24
24
|
end
|
25
25
|
|
@@ -59,61 +59,30 @@ RSpec.describe ValidatesTimeliness::Converter do
|
|
59
59
|
|
60
60
|
describe "for datetime type" do
|
61
61
|
let(:type) { :datetime }
|
62
|
+
let(:time_zone_aware) { true }
|
62
63
|
|
63
|
-
it
|
64
|
-
expect(type_cast_value(
|
64
|
+
it "should return Date as Time value" do
|
65
|
+
expect(type_cast_value(Date.new(2010, 1, 1))).to eq(Time.local(2010, 1, 1, 0, 0, 0))
|
65
66
|
end
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
around { |example|
|
71
|
-
Time.use_zone("Perth", &example)
|
72
|
-
}
|
73
|
-
|
74
|
-
it "should return Date as Time value" do
|
75
|
-
Time.use_zone('London') do
|
76
|
-
result = type_cast_value(Date.new(2010, 1, 1))
|
77
|
-
expected = Time.zone.local(2010, 1, 1, 0, 0, 0)
|
78
|
-
|
79
|
-
expect(result).to eq(expected)
|
80
|
-
expect(result.zone).to eq(expected.zone)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should return same Time value" do
|
85
|
-
value = Time.utc(2010, 1, 1, 12, 34, 56)
|
86
|
-
expect(type_cast_value(value)).to eq(value)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should return as Time with same component values" do
|
90
|
-
expect(type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56))).to eq(Time.utc(2010, 1, 1, 12, 34, 56))
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should return same Time in correct zone if timezone aware" do
|
94
|
-
value = Time.utc(2010, 1, 1, 12, 34, 56)
|
95
|
-
result = type_cast_value(value)
|
96
|
-
|
97
|
-
expect(result).to eq(Time.zone.local(2010, 1, 1, 20, 34, 56))
|
98
|
-
expect(result.zone).to eq('AWST')
|
99
|
-
end
|
68
|
+
it "should return same Time value" do
|
69
|
+
value = Time.utc(2010, 1, 1, 12, 34, 56)
|
70
|
+
expect(type_cast_value(Time.utc(2010, 1, 1, 12, 34, 56))).to eq(value)
|
100
71
|
end
|
101
72
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
it "should return Date as Time value" do
|
106
|
-
expect(type_cast_value(Date.new(2010, 1, 1))).to eq(Time.local(2010, 1, 1, 0, 0, 0))
|
107
|
-
end
|
73
|
+
it "should return as Time with same component values" do
|
74
|
+
expect(type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56))).to eq(Time.utc(2010, 1, 1, 12, 34, 56))
|
75
|
+
end
|
108
76
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
77
|
+
it "should return same Time in correct zone if timezone aware" do
|
78
|
+
value = Time.utc(2010, 1, 1, 12, 34, 56)
|
79
|
+
result = type_cast_value(value)
|
80
|
+
expect(result).to eq(Time.zone.local(2010, 1, 1, 23, 34, 56))
|
81
|
+
expect(result.zone).to eq('AEDT')
|
82
|
+
end
|
113
83
|
|
114
|
-
|
115
|
-
|
116
|
-
end
|
84
|
+
it 'should return nil for invalid value types' do
|
85
|
+
expect(type_cast_value(12)).to eq(nil)
|
117
86
|
end
|
118
87
|
end
|
119
88
|
|
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:
|
4
|
+
version: 6.0.0.alpha1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Meehan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: timeliness
|
@@ -45,9 +45,9 @@ files:
|
|
45
45
|
- LICENSE
|
46
46
|
- README.rdoc
|
47
47
|
- Rakefile
|
48
|
-
- gemfiles/
|
49
|
-
- gemfiles/
|
50
|
-
- gemfiles/
|
48
|
+
- gemfiles/rails_6_0.gemfile
|
49
|
+
- gemfiles/rails_6_1.gemfile
|
50
|
+
- gemfiles/rails_edge.gemfile
|
51
51
|
- init.rb
|
52
52
|
- lib/generators/validates_timeliness/install_generator.rb
|
53
53
|
- lib/generators/validates_timeliness/templates/en.yml
|
@@ -99,11 +99,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - "
|
102
|
+
- - ">"
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
104
|
+
version: 1.3.1
|
105
105
|
requirements: []
|
106
|
-
rubygems_version: 3.
|
106
|
+
rubygems_version: 3.0.3
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: Date and time validation plugin for Rails which allows custom formats
|