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,94 +1,109 @@
|
|
1
|
-
RSpec.describe ValidatesTimeliness::
|
2
|
-
|
1
|
+
RSpec.describe ValidatesTimeliness::Converter do
|
2
|
+
subject(:converter) { described_class.new(type: type, time_zone_aware: time_zone_aware, ignore_usec: ignore_usec) }
|
3
3
|
|
4
4
|
let(:options) { Hash.new }
|
5
|
+
let(:type) { :date }
|
6
|
+
let(:time_zone_aware) { false }
|
7
|
+
let(:ignore_usec) { false }
|
5
8
|
|
6
9
|
before do
|
7
10
|
Timecop.freeze(Time.mktime(2010, 1, 1, 0, 0, 0))
|
8
11
|
end
|
9
12
|
|
13
|
+
delegate :type_cast_value, :evaluate, :parse, :dummy_time, to: :converter
|
14
|
+
|
10
15
|
describe "#type_cast_value" do
|
11
16
|
describe "for date type" do
|
17
|
+
let(:type) { :date }
|
18
|
+
|
12
19
|
it "should return same value for date value" do
|
13
|
-
expect(type_cast_value(Date.new(2010, 1, 1)
|
20
|
+
expect(type_cast_value(Date.new(2010, 1, 1))).to eq(Date.new(2010, 1, 1))
|
14
21
|
end
|
15
22
|
|
16
23
|
it "should return date part of time value" do
|
17
|
-
expect(type_cast_value(Time.mktime(2010, 1, 1, 0, 0, 0)
|
24
|
+
expect(type_cast_value(Time.mktime(2010, 1, 1, 0, 0, 0))).to eq(Date.new(2010, 1, 1))
|
18
25
|
end
|
19
26
|
|
20
27
|
it "should return date part of datetime value" do
|
21
|
-
expect(type_cast_value(DateTime.new(2010, 1, 1, 0, 0, 0)
|
28
|
+
expect(type_cast_value(DateTime.new(2010, 1, 1, 0, 0, 0))).to eq(Date.new(2010, 1, 1))
|
22
29
|
end
|
23
30
|
|
24
31
|
it 'should return nil for invalid value types' do
|
25
|
-
expect(type_cast_value(12
|
32
|
+
expect(type_cast_value(12)).to eq(nil)
|
26
33
|
end
|
27
34
|
end
|
28
35
|
|
29
36
|
describe "for time type" do
|
37
|
+
let(:type) { :time }
|
38
|
+
|
30
39
|
it "should return same value for time value matching dummy date part" do
|
31
|
-
expect(type_cast_value(Time.utc(2000, 1, 1, 0, 0, 0)
|
40
|
+
expect(type_cast_value(Time.utc(2000, 1, 1, 0, 0, 0))).to eq(Time.utc(2000, 1, 1, 0, 0, 0))
|
32
41
|
end
|
33
42
|
|
34
43
|
it "should return dummy time value with same time part for time value with different date" do
|
35
|
-
expect(type_cast_value(Time.utc(2010, 1, 1, 0, 0, 0)
|
44
|
+
expect(type_cast_value(Time.utc(2010, 1, 1, 0, 0, 0))).to eq(Time.utc(2000, 1, 1, 0, 0, 0))
|
36
45
|
end
|
37
46
|
|
38
47
|
it "should return dummy time only for date value" do
|
39
|
-
expect(type_cast_value(Date.new(2010, 1, 1)
|
48
|
+
expect(type_cast_value(Date.new(2010, 1, 1))).to eq(Time.utc(2000, 1, 1, 0, 0, 0))
|
40
49
|
end
|
41
50
|
|
42
51
|
it "should return dummy date with time part for datetime value" do
|
43
|
-
expect(type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56)
|
52
|
+
expect(type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56))).to eq(Time.utc(2000, 1, 1, 12, 34, 56))
|
44
53
|
end
|
45
54
|
|
46
55
|
it 'should return nil for invalid value types' do
|
47
|
-
expect(type_cast_value(12
|
56
|
+
expect(type_cast_value(12)).to eq(nil)
|
48
57
|
end
|
49
58
|
end
|
50
59
|
|
51
60
|
describe "for datetime type" do
|
61
|
+
let(:type) { :datetime }
|
62
|
+
let(:time_zone_aware) { true }
|
63
|
+
|
52
64
|
it "should return Date as Time value" do
|
53
|
-
expect(type_cast_value(Date.new(2010, 1, 1)
|
65
|
+
expect(type_cast_value(Date.new(2010, 1, 1))).to eq(Time.local(2010, 1, 1, 0, 0, 0))
|
54
66
|
end
|
55
67
|
|
56
68
|
it "should return same Time value" do
|
57
69
|
value = Time.utc(2010, 1, 1, 12, 34, 56)
|
58
|
-
expect(type_cast_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)
|
59
71
|
end
|
60
72
|
|
61
73
|
it "should return as Time with same component values" do
|
62
|
-
expect(type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56)
|
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))
|
63
75
|
end
|
64
76
|
|
65
77
|
it "should return same Time in correct zone if timezone aware" do
|
66
|
-
@timezone_aware = true
|
67
78
|
value = Time.utc(2010, 1, 1, 12, 34, 56)
|
68
|
-
result = type_cast_value(value
|
79
|
+
result = type_cast_value(value)
|
69
80
|
expect(result).to eq(Time.zone.local(2010, 1, 1, 23, 34, 56))
|
70
81
|
expect(result.zone).to eq('AEDT')
|
71
82
|
end
|
72
83
|
|
73
84
|
it 'should return nil for invalid value types' do
|
74
|
-
expect(type_cast_value(12
|
85
|
+
expect(type_cast_value(12)).to eq(nil)
|
75
86
|
end
|
76
87
|
end
|
77
88
|
|
78
89
|
describe "ignore_usec option" do
|
79
|
-
let(:
|
90
|
+
let(:type) { :datetime }
|
91
|
+
let(:ignore_usec) { true }
|
80
92
|
|
81
93
|
it "should ignore usec on time values when evaluated" do
|
82
94
|
value = Time.utc(2010, 1, 1, 12, 34, 56, 10000)
|
83
|
-
expect(type_cast_value(value
|
95
|
+
expect(type_cast_value(value)).to eq(Time.utc(2010, 1, 1, 12, 34, 56))
|
84
96
|
end
|
85
97
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
98
|
+
context do
|
99
|
+
let(:time_zone_aware) { true }
|
100
|
+
|
101
|
+
it "should ignore usec and return time in correct zone if timezone aware" do
|
102
|
+
value = Time.utc(2010, 1, 1, 12, 34, 56, 10000)
|
103
|
+
result = type_cast_value(value)
|
104
|
+
expect(result).to eq(Time.zone.local(2010, 1, 1, 23, 34, 56))
|
105
|
+
expect(result.zone).to eq('AEDT')
|
106
|
+
end
|
92
107
|
end
|
93
108
|
end
|
94
109
|
end
|
@@ -103,7 +118,6 @@ RSpec.describe ValidatesTimeliness::Conversion do
|
|
103
118
|
end
|
104
119
|
|
105
120
|
it 'should return time component values shifted to current zone if timezone aware' do
|
106
|
-
@timezone_aware = true
|
107
121
|
expect(dummy_time(Time.utc(2000, 1, 1, 12, 34, 56))).to eq(Time.zone.local(2000, 1, 1, 23, 34, 56))
|
108
122
|
end
|
109
123
|
|
@@ -120,61 +134,64 @@ RSpec.describe ValidatesTimeliness::Conversion do
|
|
120
134
|
end
|
121
135
|
end
|
122
136
|
|
123
|
-
describe "#
|
137
|
+
describe "#evaluate" do
|
124
138
|
let(:person) { Person.new }
|
125
139
|
|
126
140
|
it 'should return Date object as is' do
|
127
141
|
value = Date.new(2010,1,1)
|
128
|
-
expect(
|
142
|
+
expect(evaluate(value, person)).to eq(value)
|
129
143
|
end
|
130
144
|
|
131
145
|
it 'should return Time object as is' do
|
132
146
|
value = Time.mktime(2010,1,1)
|
133
|
-
expect(
|
147
|
+
expect(evaluate(value, person)).to eq(value)
|
134
148
|
end
|
135
149
|
|
136
150
|
it 'should return DateTime object as is' do
|
137
151
|
value = DateTime.new(2010,1,1,0,0,0)
|
138
|
-
expect(
|
152
|
+
expect(evaluate(value, person)).to eq(value)
|
139
153
|
end
|
140
154
|
|
141
155
|
it 'should return Time value returned from proc with 0 arity' do
|
142
156
|
value = Time.mktime(2010,1,1)
|
143
|
-
expect(
|
157
|
+
expect(evaluate(lambda { value }, person)).to eq(value)
|
144
158
|
end
|
145
159
|
|
146
160
|
it 'should return Time value returned by record attribute call in proc arity of 1' do
|
147
161
|
value = Time.mktime(2010,1,1)
|
148
162
|
person.birth_time = value
|
149
|
-
expect(
|
163
|
+
expect(evaluate(lambda {|r| r.birth_time }, person)).to eq(value)
|
150
164
|
end
|
151
165
|
|
152
166
|
it 'should return Time value for attribute method symbol which returns Time' do
|
153
167
|
value = Time.mktime(2010,1,1)
|
154
|
-
person.
|
155
|
-
expect(
|
168
|
+
person.birth_datetime = value
|
169
|
+
expect(evaluate(:birth_datetime, person)).to eq(value)
|
156
170
|
end
|
157
171
|
|
158
172
|
it 'should return Time value is default zone from string time value' do
|
159
173
|
value = '2010-01-01 12:00:00'
|
160
|
-
expect(
|
174
|
+
expect(evaluate(value, person)).to eq(Time.utc(2010,1,1,12,0,0))
|
161
175
|
end
|
162
176
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
177
|
+
context do
|
178
|
+
let(:converter) { described_class.new(type: :date, time_zone_aware: true) }
|
179
|
+
|
180
|
+
it 'should return Time value is current zone from string time value if timezone aware' do
|
181
|
+
value = '2010-01-01 12:00:00'
|
182
|
+
expect(evaluate(value, person)).to eq(Time.zone.local(2010,1,1,12,0,0))
|
183
|
+
end
|
167
184
|
end
|
168
185
|
|
169
186
|
it 'should return Time value in default zone from proc which returns string time' do
|
170
|
-
value = '2010-
|
171
|
-
expect(
|
187
|
+
value = '2010-11-12 13:00:00'
|
188
|
+
expect(evaluate(lambda { value }, person)).to eq(Time.utc(2010,11,12,13,0,0))
|
172
189
|
end
|
173
190
|
|
174
191
|
it 'should return Time value for attribute method symbol which returns string time value' do
|
175
|
-
value = '
|
192
|
+
value = '13:00:00'
|
176
193
|
person.birth_time = value
|
177
|
-
expect(
|
194
|
+
expect(evaluate(:birth_time, person)).to eq(Time.utc(2000,1,1,13,0,0))
|
178
195
|
end
|
179
196
|
|
180
197
|
context "restriction shorthand" do
|
@@ -183,17 +200,17 @@ RSpec.describe ValidatesTimeliness::Conversion do
|
|
183
200
|
end
|
184
201
|
|
185
202
|
it 'should evaluate :now as current time' do
|
186
|
-
expect(
|
203
|
+
expect(evaluate(:now, person)).to eq(Time.now)
|
187
204
|
end
|
188
205
|
|
189
206
|
it 'should evaluate :today as current time' do
|
190
|
-
expect(
|
207
|
+
expect(evaluate(:today, person)).to eq(Date.today)
|
191
208
|
end
|
192
209
|
|
193
210
|
it 'should not use shorthand if symbol if is record method' do
|
194
211
|
time = 1.day.from_now
|
195
212
|
allow(person).to receive(:now).and_return(time)
|
196
|
-
expect(
|
213
|
+
expect(evaluate(:now, person)).to eq(time)
|
197
214
|
end
|
198
215
|
end
|
199
216
|
end
|
@@ -212,13 +229,11 @@ RSpec.describe ValidatesTimeliness::Conversion do
|
|
212
229
|
with_config(:use_plugin_parser, false)
|
213
230
|
|
214
231
|
it 'should use Time.zone.parse attribute is timezone aware' do
|
215
|
-
|
216
|
-
expect(Time.zone).to receive(:parse)
|
232
|
+
expect(Timeliness::Parser).to_not receive(:parse)
|
217
233
|
parse('2000-01-01')
|
218
234
|
end
|
219
235
|
|
220
236
|
it 'should use value#to_time if use_plugin_parser setting is false and attribute is not timezone aware' do
|
221
|
-
@timezone_aware = false
|
222
237
|
value = '2000-01-01'
|
223
238
|
expect(value).to receive(:to_time)
|
224
239
|
parse(value)
|
@@ -20,8 +20,8 @@ RSpec.describe 'ValidatesTimeliness::Extensions::DateTimeSelect' do
|
|
20
20
|
"birth_datetime(6i)" => '14',
|
21
21
|
}
|
22
22
|
person.birth_datetime = nil
|
23
|
-
@output = datetime_select(:person, :birth_datetime, :
|
24
|
-
should_have_datetime_selected(:birth_datetime, :
|
23
|
+
@output = datetime_select(:person, :birth_datetime, include_blank: true, include_seconds: true)
|
24
|
+
should_have_datetime_selected(:birth_datetime, year: 2009, month: 'February', day: 29, hour: 12, min: 13, sec: 14)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should override object values and use params if present" do
|
@@ -34,26 +34,26 @@ RSpec.describe 'ValidatesTimeliness::Extensions::DateTimeSelect' do
|
|
34
34
|
"birth_datetime(6i)" => '14',
|
35
35
|
}
|
36
36
|
person.birth_datetime = "2010-01-01 15:16:17"
|
37
|
-
@output = datetime_select(:person, :birth_datetime, :
|
38
|
-
should_have_datetime_selected(:birth_datetime, :
|
37
|
+
@output = datetime_select(:person, :birth_datetime, include_blank: true, include_seconds: true)
|
38
|
+
should_have_datetime_selected(:birth_datetime, year: 2009, month: 'February', day: 29, hour: 12, min: 13, sec: 14)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should use attribute values from object if no params" do
|
42
42
|
person.birth_datetime = "2009-01-02 12:13:14"
|
43
|
-
@output = datetime_select(:person, :birth_datetime, :
|
44
|
-
should_have_datetime_selected(:birth_datetime, :
|
43
|
+
@output = datetime_select(:person, :birth_datetime, include_blank: true, include_seconds: true)
|
44
|
+
should_have_datetime_selected(:birth_datetime, year: 2009, month: 'January', day: 2, hour: 12, min: 13, sec: 14)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should use attribute values if params does not contain attribute params" do
|
48
48
|
person.birth_datetime = "2009-01-02 12:13:14"
|
49
49
|
@params["person"] = { }
|
50
|
-
@output = datetime_select(:person, :birth_datetime, :
|
51
|
-
should_have_datetime_selected(:birth_datetime, :
|
50
|
+
@output = datetime_select(:person, :birth_datetime, include_blank: true, include_seconds: true)
|
51
|
+
should_have_datetime_selected(:birth_datetime, year: 2009, month: 'January', day: 2, hour: 12, min: 13, sec: 14)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should not select values when attribute value is nil and has no param values" do
|
55
55
|
person.birth_datetime = nil
|
56
|
-
@output = datetime_select(:person, :birth_datetime, :
|
56
|
+
@output = datetime_select(:person, :birth_datetime, include_blank: true, include_seconds: true)
|
57
57
|
should_not_have_datetime_selected(:birth_datetime, :year, :month, :day, :hour, :min, :sec)
|
58
58
|
end
|
59
59
|
end
|
@@ -66,8 +66,8 @@ RSpec.describe 'ValidatesTimeliness::Extensions::DateTimeSelect' do
|
|
66
66
|
"birth_date(3i)" => '29',
|
67
67
|
}
|
68
68
|
person.birth_date = nil
|
69
|
-
@output = date_select(:person, :birth_date, :
|
70
|
-
should_have_datetime_selected(:birth_date, :
|
69
|
+
@output = date_select(:person, :birth_date, include_blank: true)
|
70
|
+
should_have_datetime_selected(:birth_date, year: 2009, month: 'February', day: 29)
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should override object values and use params if present" do
|
@@ -77,26 +77,26 @@ RSpec.describe 'ValidatesTimeliness::Extensions::DateTimeSelect' do
|
|
77
77
|
"birth_date(3i)" => '29',
|
78
78
|
}
|
79
79
|
person.birth_date = "2009-03-01"
|
80
|
-
@output = date_select(:person, :birth_date, :
|
81
|
-
should_have_datetime_selected(:birth_date, :
|
80
|
+
@output = date_select(:person, :birth_date, include_blank: true)
|
81
|
+
should_have_datetime_selected(:birth_date, year: 2009, month: 'February', day: 29)
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should select attribute values from object if no params" do
|
85
85
|
person.birth_date = "2009-01-02"
|
86
|
-
@output = date_select(:person, :birth_date, :
|
87
|
-
should_have_datetime_selected(:birth_date, :
|
86
|
+
@output = date_select(:person, :birth_date, include_blank: true)
|
87
|
+
should_have_datetime_selected(:birth_date, year: 2009, month: 'January', day: 2)
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should select attribute values if params does not contain attribute params" do
|
91
91
|
person.birth_date = "2009-01-02"
|
92
92
|
@params["person"] = { }
|
93
|
-
@output = date_select(:person, :birth_date, :
|
94
|
-
should_have_datetime_selected(:birth_date, :
|
93
|
+
@output = date_select(:person, :birth_date, include_blank: true)
|
94
|
+
should_have_datetime_selected(:birth_date, year: 2009, month: 'January', day: 2)
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should not select values when attribute value is nil and has no param values" do
|
98
98
|
person.birth_date = nil
|
99
|
-
@output = date_select(:person, :birth_date, :
|
99
|
+
@output = date_select(:person, :birth_date, include_blank: true)
|
100
100
|
should_not_have_datetime_selected(:birth_time, :year, :month, :day)
|
101
101
|
end
|
102
102
|
|
@@ -106,8 +106,8 @@ RSpec.describe 'ValidatesTimeliness::Extensions::DateTimeSelect' do
|
|
106
106
|
"birth_date(2i)" => '2',
|
107
107
|
}
|
108
108
|
|
109
|
-
@output = date_select(:person, :birth_date, :
|
110
|
-
should_have_datetime_selected(:birth_date, :
|
109
|
+
@output = date_select(:person, :birth_date, include_blank: true, discard_day: true)
|
110
|
+
should_have_datetime_selected(:birth_date, year: 2009, month: 'February')
|
111
111
|
should_not_have_datetime_selected(:birth_time, :day)
|
112
112
|
expect(@output).to have_tag("input[id=person_birth_date_3i][type=hidden][value='1']")
|
113
113
|
end
|
@@ -128,33 +128,33 @@ RSpec.describe 'ValidatesTimeliness::Extensions::DateTimeSelect' do
|
|
128
128
|
"birth_time(6i)" => '14',
|
129
129
|
}
|
130
130
|
person.birth_time = nil
|
131
|
-
@output = time_select(:person, :birth_time, :
|
132
|
-
should_have_datetime_selected(:birth_time, :
|
131
|
+
@output = time_select(:person, :birth_time, include_blank: true, include_seconds: true)
|
132
|
+
should_have_datetime_selected(:birth_time, hour: 12, min: 13, sec: 14)
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should select attribute values from object if no params" do
|
136
136
|
person.birth_time = "2000-01-01 12:13:14"
|
137
|
-
@output = time_select(:person, :birth_time, :
|
138
|
-
should_have_datetime_selected(:birth_time, :
|
137
|
+
@output = time_select(:person, :birth_time, include_blank: true, include_seconds: true)
|
138
|
+
should_have_datetime_selected(:birth_time, hour: 12, min: 13, sec: 14)
|
139
139
|
end
|
140
140
|
|
141
141
|
it "should not select values when attribute value is nil and has no param values" do
|
142
142
|
person.birth_time = nil
|
143
|
-
@output = time_select(:person, :birth_time, :
|
143
|
+
@output = time_select(:person, :birth_time, include_blank: true, include_seconds: true)
|
144
144
|
should_not_have_datetime_selected(:birth_time, :hour, :min, :sec)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
148
|
def should_have_datetime_selected(field, datetime_hash)
|
149
149
|
datetime_hash.each do |key, value|
|
150
|
-
index = {:
|
150
|
+
index = {year: 1, month: 2, day: 3, hour: 4, min: 5, sec: 6}[key]
|
151
151
|
expect(@output).to have_tag("select[id=person_#{field}_#{index}i] option[selected=selected]", value.to_s)
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
155
|
def should_not_have_datetime_selected(field, *attributes)
|
156
156
|
attributes.each do |attribute|
|
157
|
-
index = {:
|
157
|
+
index = {year: 1, month: 2, day: 3, hour: 4, min: 5, sec: 6}[attribute]
|
158
158
|
expect(@output).not_to have_tag("select[id=person_#{attribute}_#{index}i] option[selected=selected]")
|
159
159
|
end
|
160
160
|
end
|
@@ -1,36 +1,36 @@
|
|
1
1
|
RSpec.describe 'ValidatesTimeliness::Extensions::MultiparameterHandler' do
|
2
2
|
|
3
3
|
context "time column" do
|
4
|
-
it 'should
|
4
|
+
it 'should be nil invalid date portion' do
|
5
5
|
employee = record_with_multiparameter_attribute(:birth_datetime, [2000, 2, 31, 12, 0, 0])
|
6
|
-
expect(employee.
|
6
|
+
expect(employee.birth_datetime).to be_nil
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'should assign a Time value for valid datetimes' do
|
10
10
|
employee = record_with_multiparameter_attribute(:birth_datetime, [2000, 2, 28, 12, 0, 0])
|
11
|
-
expect(employee.
|
11
|
+
expect(employee.birth_datetime).to eq Time.zone.local(2000, 2, 28, 12, 0, 0)
|
12
12
|
end
|
13
13
|
|
14
|
-
it 'should
|
14
|
+
it 'should be nil for incomplete date portion' do
|
15
15
|
employee = record_with_multiparameter_attribute(:birth_datetime, [2000, nil, nil])
|
16
|
-
expect(employee.
|
16
|
+
expect(employee.birth_datetime).to be_nil
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
context "date column" do
|
21
|
-
it 'should assign
|
21
|
+
it 'should assign nil for invalid date' do
|
22
22
|
employee = record_with_multiparameter_attribute(:birth_date, [2000, 2, 31])
|
23
|
-
expect(employee.
|
23
|
+
expect(employee.birth_date).to be_nil
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should assign a Date value for valid date' do
|
27
27
|
employee = record_with_multiparameter_attribute(:birth_date, [2000, 2, 28])
|
28
|
-
expect(employee.
|
28
|
+
expect(employee.birth_date).to eq Date.new(2000, 2, 28)
|
29
29
|
end
|
30
30
|
|
31
|
-
it 'should assign
|
31
|
+
it 'should assign hash values for incomplete date' do
|
32
32
|
employee = record_with_multiparameter_attribute(:birth_date, [2000, nil, nil])
|
33
|
-
expect(employee.
|
33
|
+
expect(employee.birth_date).to be_nil
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|