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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c7247761bf59a4add26640ddb732b6bdf816312be3083e972976062d4a43459
4
- data.tar.gz: ab777d06c23790afbbc56a6a5a173fb8ea98034f52e9903d996c77a20e415574
3
+ metadata.gz: e153117c69ae4a75bde2e8a9cb1334118fbc083be371ed10d6658bf6a82aa8fb
4
+ data.tar.gz: cb77f367f614fd8c6fbf754cd5b1d1beed8845a5afe74937e97e38ab7da8ee8b
5
5
  SHA512:
6
- metadata.gz: fde85a854481b993e1353a092a5340a62c2c299e2a8f75c8802f334203673e05a64e5323d8af6b1cd3e9c8bd2c8a0b8c6c78dd160aa6630eda7bfb06e10f4166
7
- data.tar.gz: 5d202ab44a0397c7fbacac804c0bd2e52fdb37c8db672d22340681d01ce70a95a735d6e85e65f0d7ac72c0b6cbbcd159cf3fb715c566dff544e93436b40d103a
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/rails_5_0.gemfile
7
- - gemfiles/rails_5_1.gemfile
8
- - gemfiles/rails_5_2.gemfile
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.3"
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
- = 5.0.1 [2023-01-12]
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008-2010 Adam Meehan
1
+ Copyright (c) 2008-2021 Adam Meehan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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: http://github.com/adzap/validates_timeliness
4
- * Issues: http://github.com/adzap/validates_timeliness/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 5.x and ActiveModel.
8
+ Complete validation of dates, times and datetimes for Rails 6.x and ActiveModel.
9
9
 
10
- If you a looking for the old version for Rails 4.x go here [https://github.com/adzap/validates_timeliness/tree/4-0-stable].
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}[http://github.com/adzap/timeliness]. See Plugin Parser)
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', '~> 5.0.0.beta1'
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}[http://github.com/adzap/validates_timeliness/wiki/ORM-Support] for more information.
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}[http://github.com/adzap/timeliness] as a fast, configurable and extensible date and time parser.
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[http://github.com/adzap/validates_timeliness/wiki/Plugin-Parser] for more details about the parser configuration.
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.today }</tt>. The :now and :today
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}[http://github.com/adzap/validates_timeliness/contributors].
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}[http://github.com/adzap]
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' << '--inline-source'
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.0.0"
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.1.0"
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.2.0"
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 : (time_zone_aware? ? value.in_time_zone : value.to_time)
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.change(usec: 0)
27
+ Timeliness::Parser.make_time(Array(value).reverse[4..9], (:current if time_zone_aware?))
29
28
  else
30
29
  value
31
30
  end
@@ -43,7 +43,7 @@ module ValidatesTimeliness
43
43
  values[POSITION.key(position.to_i)] = value.to_i
44
44
  end
45
45
 
46
- DateTimeValue.new(values)
46
+ DateTimeValue.new(**values)
47
47
  end
48
48
  end
49
49
  end
@@ -20,7 +20,7 @@ module ActiveModel
20
20
 
21
21
  def timeliness_validation_for(attr_names, type=nil)
22
22
  options = _merge_attributes(attr_names)
23
- options.update(type: type) if type
23
+ options.update(:type => type) if type
24
24
  validates_with TimelinessValidator, options
25
25
  end
26
26
  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)
@@ -1,3 +1,3 @@
1
1
  module ValidatesTimeliness
2
- VERSION = '5.0.1'
2
+ VERSION = '6.0.0.alpha1'
3
3
  end
@@ -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 'should return nil for invalid value types' do
64
- expect(type_cast_value(12)).to eq(nil)
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
- context "time zone aware" do
68
- let(:time_zone_aware) { true }
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
- context "not time zone aware" do
103
- let(:time_zone_aware) { false }
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
- it "should return same Time value" do
110
- value = Time.utc(2010, 1, 1, 12, 34, 56)
111
- expect(type_cast_value(Time.utc(2010, 1, 1, 12, 34, 56))).to eq(value)
112
- end
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
- it "should return as Time with same component values" do
115
- 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))
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: 5.0.1
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: 2023-01-12 00:00:00.000000000 Z
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/rails_5_0.gemfile
49
- - gemfiles/rails_5_1.gemfile
50
- - gemfiles/rails_5_2.gemfile
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: '0'
104
+ version: 1.3.1
105
105
  requirements: []
106
- rubygems_version: 3.1.6
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