validates_timeliness 4.1.1 → 6.0.0.beta2
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 +4 -4
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/ci.yml +41 -0
- data/CHANGELOG.rdoc +14 -6
- data/LICENSE +1 -1
- data/README.md +321 -0
- data/Rakefile +0 -10
- data/gemfiles/rails_6_0.gemfile +14 -0
- data/gemfiles/rails_6_1.gemfile +14 -0
- data/gemfiles/rails_edge.gemfile +14 -0
- data/lib/validates_timeliness/attribute_methods.rb +34 -73
- data/lib/validates_timeliness/{conversion.rb → converter.rb} +26 -14
- data/lib/validates_timeliness/extensions/date_time_select.rb +23 -27
- data/lib/validates_timeliness/extensions/multiparameter_handler.rb +47 -66
- data/lib/validates_timeliness/extensions.rb +2 -2
- data/lib/validates_timeliness/orm/active_model.rb +53 -2
- data/lib/validates_timeliness/orm/active_record.rb +2 -84
- data/lib/validates_timeliness/railtie.rb +1 -1
- data/lib/validates_timeliness/validator.rb +21 -18
- data/lib/validates_timeliness/version.rb +1 -1
- data/lib/validates_timeliness.rb +3 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/support/model_helpers.rb +1 -2
- data/spec/support/test_model.rb +6 -4
- data/spec/validates_timeliness/attribute_methods_spec.rb +0 -15
- data/spec/validates_timeliness/{conversion_spec.rb → converter_spec.rb} +64 -49
- data/spec/validates_timeliness/extensions/date_time_select_spec.rb +27 -27
- data/spec/validates_timeliness/extensions/multiparameter_handler_spec.rb +10 -10
- data/spec/validates_timeliness/orm/active_record_spec.rb +72 -136
- data/validates_timeliness.gemspec +4 -3
- metadata +38 -16
- data/.travis.yml +0 -24
- data/README.rdoc +0 -300
- data/gemfiles/rails_4_2.gemfile +0 -14
@@ -1,5 +1,4 @@
|
|
1
1
|
RSpec.describe ValidatesTimeliness, 'ActiveRecord' do
|
2
|
-
|
3
2
|
context "validation methods" do
|
4
3
|
let(:record) { Employee.new }
|
5
4
|
|
@@ -26,6 +25,7 @@ RSpec.describe ValidatesTimeliness, 'ActiveRecord' do
|
|
26
25
|
record.birth_date = 'not a date'
|
27
26
|
|
28
27
|
record.valid?
|
28
|
+
expect(record.birth_date_before_type_cast).to eq 'not a date'
|
29
29
|
expect(record.errors[:birth_date]).not_to be_empty
|
30
30
|
end
|
31
31
|
|
@@ -37,10 +37,6 @@ RSpec.describe ValidatesTimeliness, 'ActiveRecord' do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
it 'should determine type for attribute' do
|
41
|
-
expect(Employee.timeliness_attribute_type(:birth_date)).to eq :date
|
42
|
-
end
|
43
|
-
|
44
40
|
context 'attribute timezone awareness' do
|
45
41
|
let(:klass) {
|
46
42
|
Class.new(ActiveRecord::Base) do
|
@@ -53,22 +49,6 @@ RSpec.describe ValidatesTimeliness, 'ActiveRecord' do
|
|
53
49
|
validates_datetime :some_datetime
|
54
50
|
end
|
55
51
|
}
|
56
|
-
|
57
|
-
context 'for column attribute' do
|
58
|
-
it 'should be detected from column type' do
|
59
|
-
expect(klass.timeliness_attribute_timezone_aware?(:birth_date)).to be_falsey
|
60
|
-
expect(klass.timeliness_attribute_timezone_aware?(:birth_time)).to be_falsey
|
61
|
-
expect(klass.timeliness_attribute_timezone_aware?(:birth_datetime)).to be_truthy
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'for non-column attribute' do
|
66
|
-
it 'should be detected from the validation type' do
|
67
|
-
expect(klass.timeliness_attribute_timezone_aware?(:some_date)).to be_falsey
|
68
|
-
expect(klass.timeliness_attribute_timezone_aware?(:some_time)).to be_falsey
|
69
|
-
expect(klass.timeliness_attribute_timezone_aware?(:some_datetime)).to be_truthy
|
70
|
-
end
|
71
|
-
end
|
72
52
|
end
|
73
53
|
|
74
54
|
context "attribute write method" do
|
@@ -79,34 +59,6 @@ RSpec.describe ValidatesTimeliness, 'ActiveRecord' do
|
|
79
59
|
validates_datetime :birth_datetime, :allow_blank => true
|
80
60
|
end
|
81
61
|
|
82
|
-
context 'value cache' do
|
83
|
-
let(:record) { EmployeeWithCache.new }
|
84
|
-
|
85
|
-
context 'for datetime column' do
|
86
|
-
it 'should store raw value' do
|
87
|
-
record.birth_datetime = datetime_string = '2010-01-01 12:30'
|
88
|
-
|
89
|
-
expect(record.read_timeliness_attribute_before_type_cast('birth_datetime')).to eq datetime_string
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context 'for date column' do
|
94
|
-
it 'should store raw value' do
|
95
|
-
record.birth_date = date_string = '2010-01-01'
|
96
|
-
|
97
|
-
expect(record.read_timeliness_attribute_before_type_cast('birth_date')).to eq date_string
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context 'for time column' do
|
102
|
-
it 'should store raw value' do
|
103
|
-
record.birth_time = time_string = '12:12'
|
104
|
-
|
105
|
-
expect(record.read_timeliness_attribute_before_type_cast('birth_time')).to eq time_string
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
62
|
context "with plugin parser" do
|
111
63
|
with_config(:use_plugin_parser, true)
|
112
64
|
let(:record) { EmployeeWithParser.new }
|
@@ -118,17 +70,23 @@ RSpec.describe ValidatesTimeliness, 'ActiveRecord' do
|
|
118
70
|
validates_datetime :birth_datetime, :allow_blank => true
|
119
71
|
end
|
120
72
|
|
73
|
+
before do
|
74
|
+
allow(Timeliness::Parser).to receive(:parse).and_call_original
|
75
|
+
end
|
76
|
+
|
121
77
|
context "for a date column" do
|
122
78
|
it 'should parse a string value' do
|
123
|
-
expect(Timeliness::Parser).to receive(:parse)
|
124
|
-
|
125
79
|
record.birth_date = '2010-01-01'
|
80
|
+
expect(record.birth_date).to eq(Date.new(2010, 1, 1))
|
81
|
+
|
82
|
+
expect(Timeliness::Parser).to have_received(:parse)
|
126
83
|
end
|
127
84
|
|
128
85
|
it 'should parse a invalid string value as nil' do
|
129
|
-
expect(Timeliness::Parser).to receive(:parse)
|
130
|
-
|
131
86
|
record.birth_date = 'not valid'
|
87
|
+
expect(record.birth_date).to be_nil
|
88
|
+
|
89
|
+
expect(Timeliness::Parser).to have_received(:parse)
|
132
90
|
end
|
133
91
|
|
134
92
|
it 'should store a Date value after parsing string' do
|
@@ -140,45 +98,85 @@ RSpec.describe ValidatesTimeliness, 'ActiveRecord' do
|
|
140
98
|
end
|
141
99
|
|
142
100
|
context "for a time column" do
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
101
|
+
around do |example|
|
102
|
+
time_zone_aware_types = ActiveRecord::Base.time_zone_aware_types.dup
|
103
|
+
example.call
|
104
|
+
ActiveRecord::Base.time_zone_aware_types = time_zone_aware_types
|
147
105
|
end
|
148
106
|
|
149
|
-
|
150
|
-
|
107
|
+
context 'timezone aware' do
|
108
|
+
with_config(:default_timezone, 'Australia/Melbourne')
|
109
|
+
|
110
|
+
before do
|
111
|
+
unless ActiveRecord::Base.time_zone_aware_types.include?(:time)
|
112
|
+
ActiveRecord::Base.time_zone_aware_types.push(:time)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should parse a string value' do
|
117
|
+
record.birth_time = '12:30'
|
118
|
+
|
119
|
+
expect(record.birth_time).to eq('12:30'.in_time_zone)
|
120
|
+
expect(Timeliness::Parser).to have_received(:parse)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should parse a invalid string value as nil' do
|
124
|
+
record.birth_time = 'not valid'
|
151
125
|
|
152
|
-
|
126
|
+
expect(record.birth_time).to be_nil
|
127
|
+
expect(Timeliness::Parser).to have_received(:parse)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should store a Time value after parsing string' do
|
131
|
+
record.birth_time = '12:30'
|
132
|
+
|
133
|
+
expect(record.birth_time).to eq('12:30'.in_time_zone)
|
134
|
+
expect(record.birth_time.utc_offset).to eq '12:30'.in_time_zone.utc_offset
|
135
|
+
end
|
153
136
|
end
|
154
137
|
|
155
|
-
|
156
|
-
|
138
|
+
skip 'not timezone aware' do
|
139
|
+
before do
|
140
|
+
ActiveRecord::Base.time_zone_aware_types.delete(:time)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should parse a string value' do
|
144
|
+
record.birth_time = '12:30'
|
145
|
+
|
146
|
+
expect(record.birth_time).to eq(Time.utc(2000,1,1,12,30))
|
147
|
+
expect(Timeliness::Parser).to have_received(:parse)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should parse a invalid string value as nil' do
|
151
|
+
record.birth_time = 'not valid'
|
157
152
|
|
158
|
-
|
159
|
-
|
153
|
+
expect(record.birth_time).to be_nil
|
154
|
+
expect(Timeliness::Parser).to have_received(:parse)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should store a Time value in utc' do
|
158
|
+
record.birth_time = '12:30'
|
159
|
+
|
160
|
+
expect(record.birth_time.utc_offset).to eq Time.now.utc.utc_offset
|
161
|
+
end
|
160
162
|
end
|
161
163
|
end
|
162
164
|
|
163
165
|
context "for a datetime column" do
|
164
166
|
with_config(:default_timezone, 'Australia/Melbourne')
|
165
167
|
|
166
|
-
it 'should parse a string value' do
|
167
|
-
expect(Timeliness::Parser).to receive(:parse)
|
168
|
-
|
168
|
+
it 'should parse a string value into Time value' do
|
169
169
|
record.birth_datetime = '2010-01-01 12:00'
|
170
|
+
|
171
|
+
expect(record.birth_datetime).to eq Time.zone.local(2010,1,1,12,00)
|
172
|
+
expect(Timeliness::Parser).to have_received(:parse)
|
170
173
|
end
|
171
174
|
|
172
175
|
it 'should parse a invalid string value as nil' do
|
173
|
-
expect(Timeliness::Parser).to receive(:parse)
|
174
|
-
|
175
176
|
record.birth_datetime = 'not valid'
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'should parse string into Time value' do
|
179
|
-
record.birth_datetime = '2010-01-01 12:00'
|
180
177
|
|
181
|
-
expect(record.birth_datetime).to
|
178
|
+
expect(record.birth_datetime).to be_nil
|
179
|
+
expect(Timeliness::Parser).to have_received(:parse)
|
182
180
|
end
|
183
181
|
|
184
182
|
it 'should parse string as current timezone' do
|
@@ -189,66 +187,4 @@ RSpec.describe ValidatesTimeliness, 'ActiveRecord' do
|
|
189
187
|
end
|
190
188
|
end
|
191
189
|
end
|
192
|
-
|
193
|
-
context "reload" do
|
194
|
-
it 'should clear cache value' do
|
195
|
-
record = Employee.create!
|
196
|
-
record.birth_date = '2010-01-01'
|
197
|
-
|
198
|
-
record.reload
|
199
|
-
|
200
|
-
expect(record.read_timeliness_attribute_before_type_cast('birth_date')).to be_nil
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
context "before_type_cast method" do
|
205
|
-
let(:record) { Employee.new }
|
206
|
-
|
207
|
-
it 'should be defined on class if ORM supports it' do
|
208
|
-
expect(record).to respond_to(:birth_datetime_before_type_cast)
|
209
|
-
end
|
210
|
-
|
211
|
-
it 'should return original value' do
|
212
|
-
record.birth_datetime = date_string = '2010-01-01'
|
213
|
-
|
214
|
-
expect(record.birth_datetime_before_type_cast).to eq date_string
|
215
|
-
end
|
216
|
-
|
217
|
-
it 'should return attribute if no attribute assignment has been made' do
|
218
|
-
datetime = Time.zone.local(2010,01,01)
|
219
|
-
Employee.create(:birth_datetime => datetime)
|
220
|
-
|
221
|
-
record = Employee.last
|
222
|
-
expect(record.birth_datetime_before_type_cast).to match(/#{datetime.utc.to_s[0...-4]}/)
|
223
|
-
end
|
224
|
-
|
225
|
-
context "with plugin parser" do
|
226
|
-
with_config(:use_plugin_parser, true)
|
227
|
-
|
228
|
-
it 'should return original value' do
|
229
|
-
record.birth_datetime = date_string = '2010-01-31'
|
230
|
-
|
231
|
-
expect(record.birth_datetime_before_type_cast).to eq date_string
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
end
|
236
|
-
|
237
|
-
context "define_attribute_methods" do
|
238
|
-
it "returns a falsy value if the attribute methods have already been generated" do
|
239
|
-
expect(Employee.define_attribute_methods).to be_falsey
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
context "undefine_attribute_methods" do
|
244
|
-
it "returns remove attribute methods that have already been generated" do
|
245
|
-
Employee.define_attribute_methods
|
246
|
-
|
247
|
-
expect(Employee.instance_methods).to include(:birth_datetime)
|
248
|
-
|
249
|
-
Employee.undefine_attribute_methods
|
250
|
-
|
251
|
-
expect(Employee.instance_methods).to_not include(:birth_datetime)
|
252
|
-
end
|
253
|
-
end
|
254
190
|
end
|
@@ -13,9 +13,10 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.license = "MIT"
|
14
14
|
|
15
15
|
s.require_paths = ["lib"]
|
16
|
-
s.files = `git ls-files`.split("\n") - %w{ .gitignore .rspec Gemfile Gemfile.lock autotest/discover.rb Appraisals
|
16
|
+
s.files = `git ls-files`.split("\n") - %w{ .gitignore .rspec Gemfile Gemfile.lock autotest/discover.rb Appraisals } - Dir['gemsfiles/*']
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
s.extra_rdoc_files = ["README.
|
18
|
+
s.extra_rdoc_files = ["README.md", "CHANGELOG.rdoc", "LICENSE"]
|
19
19
|
|
20
|
-
s.add_runtime_dependency(
|
20
|
+
s.add_runtime_dependency("activemodel", [">= 6.0.0", "< 7"])
|
21
|
+
s.add_runtime_dependency("timeliness", [">= 0.3.10", "< 1"])
|
21
22
|
end
|
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
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.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Meehan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 6.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7'
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: timeliness
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -36,23 +56,26 @@ email: adam.meehan@gmail.com
|
|
36
56
|
executables: []
|
37
57
|
extensions: []
|
38
58
|
extra_rdoc_files:
|
39
|
-
- README.
|
59
|
+
- README.md
|
40
60
|
- CHANGELOG.rdoc
|
41
61
|
- LICENSE
|
42
62
|
files:
|
43
|
-
- ".
|
63
|
+
- ".github/dependabot.yml"
|
64
|
+
- ".github/workflows/ci.yml"
|
44
65
|
- CHANGELOG.rdoc
|
45
66
|
- LICENSE
|
46
|
-
- README.
|
67
|
+
- README.md
|
47
68
|
- Rakefile
|
48
|
-
- gemfiles/
|
69
|
+
- gemfiles/rails_6_0.gemfile
|
70
|
+
- gemfiles/rails_6_1.gemfile
|
71
|
+
- gemfiles/rails_edge.gemfile
|
49
72
|
- init.rb
|
50
73
|
- lib/generators/validates_timeliness/install_generator.rb
|
51
74
|
- lib/generators/validates_timeliness/templates/en.yml
|
52
75
|
- lib/generators/validates_timeliness/templates/validates_timeliness.rb
|
53
76
|
- lib/validates_timeliness.rb
|
54
77
|
- lib/validates_timeliness/attribute_methods.rb
|
55
|
-
- lib/validates_timeliness/
|
78
|
+
- lib/validates_timeliness/converter.rb
|
56
79
|
- lib/validates_timeliness/extensions.rb
|
57
80
|
- lib/validates_timeliness/extensions/date_time_select.rb
|
58
81
|
- lib/validates_timeliness/extensions/multiparameter_handler.rb
|
@@ -68,7 +91,7 @@ files:
|
|
68
91
|
- spec/support/tag_matcher.rb
|
69
92
|
- spec/support/test_model.rb
|
70
93
|
- spec/validates_timeliness/attribute_methods_spec.rb
|
71
|
-
- spec/validates_timeliness/
|
94
|
+
- spec/validates_timeliness/converter_spec.rb
|
72
95
|
- spec/validates_timeliness/extensions/date_time_select_spec.rb
|
73
96
|
- spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
|
74
97
|
- spec/validates_timeliness/helper_methods_spec.rb
|
@@ -86,7 +109,7 @@ homepage: http://github.com/adzap/validates_timeliness
|
|
86
109
|
licenses:
|
87
110
|
- MIT
|
88
111
|
metadata: {}
|
89
|
-
post_install_message:
|
112
|
+
post_install_message:
|
90
113
|
rdoc_options: []
|
91
114
|
require_paths:
|
92
115
|
- lib
|
@@ -97,13 +120,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
120
|
version: '0'
|
98
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
122
|
requirements:
|
100
|
-
- - "
|
123
|
+
- - ">"
|
101
124
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
125
|
+
version: 1.3.1
|
103
126
|
requirements: []
|
104
|
-
|
105
|
-
|
106
|
-
signing_key:
|
127
|
+
rubygems_version: 3.0.3.1
|
128
|
+
signing_key:
|
107
129
|
specification_version: 4
|
108
130
|
summary: Date and time validation plugin for Rails which allows custom formats
|
109
131
|
test_files:
|
@@ -113,7 +135,7 @@ test_files:
|
|
113
135
|
- spec/support/tag_matcher.rb
|
114
136
|
- spec/support/test_model.rb
|
115
137
|
- spec/validates_timeliness/attribute_methods_spec.rb
|
116
|
-
- spec/validates_timeliness/
|
138
|
+
- spec/validates_timeliness/converter_spec.rb
|
117
139
|
- spec/validates_timeliness/extensions/date_time_select_spec.rb
|
118
140
|
- spec/validates_timeliness/extensions/multiparameter_handler_spec.rb
|
119
141
|
- spec/validates_timeliness/helper_methods_spec.rb
|
data/.travis.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
before_install:
|
3
|
-
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
4
|
-
- gem install bundler -v '< 2'
|
5
|
-
before_script:
|
6
|
-
- bundle install
|
7
|
-
cache: bundler
|
8
|
-
bundler_args: --verbose
|
9
|
-
|
10
|
-
matrix:
|
11
|
-
include:
|
12
|
-
- rvm: "2.4.6"
|
13
|
-
gemfile: gemfiles/rails_4_2.gemfile
|
14
|
-
- rvm: "2.5.5"
|
15
|
-
gemfile: gemfiles/rails_4_2.gemfile
|
16
|
-
|
17
|
-
script: 'bundle exec rspec'
|
18
|
-
|
19
|
-
notifications:
|
20
|
-
email:
|
21
|
-
recipients:
|
22
|
-
- adam.meehan@gmail.com
|
23
|
-
on_failure: change
|
24
|
-
on_success: never
|