validates_timeliness 3.0.8 → 4.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 +7 -0
- data/.travis.yml +21 -0
- data/CHANGELOG.rdoc +21 -1
- data/README.rdoc +20 -22
- data/Rakefile +5 -1
- data/gemfiles/rails_4_0.gemfile +19 -0
- data/gemfiles/rails_4_1.gemfile +19 -0
- data/gemfiles/rails_4_2.gemfile +19 -0
- data/lib/generators/validates_timeliness/install_generator.rb +0 -1
- data/lib/generators/validates_timeliness/templates/validates_timeliness.rb +3 -3
- data/lib/validates_timeliness/attribute_methods.rb +42 -26
- data/lib/validates_timeliness/extensions/date_time_select.rb +2 -9
- data/lib/validates_timeliness/extensions/multiparameter_handler.rb +59 -54
- data/lib/validates_timeliness/extensions.rb +3 -4
- data/lib/validates_timeliness/helper_methods.rb +7 -6
- data/lib/validates_timeliness/orm/active_record.rb +70 -15
- data/lib/validates_timeliness/railtie.rb +2 -1
- data/lib/validates_timeliness/validator.rb +29 -4
- data/lib/validates_timeliness/version.rb +1 -1
- data/lib/validates_timeliness.rb +13 -13
- data/spec/spec_helper.rb +10 -5
- data/spec/support/config_helper.rb +10 -0
- data/spec/support/model_helpers.rb +4 -4
- data/spec/support/tag_matcher.rb +35 -0
- data/spec/support/test_model.rb +0 -1
- data/spec/validates_timeliness/attribute_methods_spec.rb +22 -7
- data/spec/validates_timeliness/conversion_spec.rb +41 -41
- data/spec/validates_timeliness/extensions/date_time_select_spec.rb +5 -4
- data/spec/validates_timeliness/extensions/multiparameter_handler_spec.rb +28 -16
- data/spec/validates_timeliness/helper_methods_spec.rb +12 -12
- data/spec/validates_timeliness/orm/active_record_spec.rb +178 -44
- data/spec/validates_timeliness/validator/after_spec.rb +3 -3
- data/spec/validates_timeliness/validator/before_spec.rb +3 -3
- data/spec/validates_timeliness/validator/is_at_spec.rb +4 -4
- data/spec/validates_timeliness/validator/on_or_after_spec.rb +3 -3
- data/spec/validates_timeliness/validator/on_or_before_spec.rb +3 -3
- data/spec/validates_timeliness/validator_spec.rb +66 -25
- data/spec/validates_timeliness_spec.rb +8 -8
- data/validates_timeliness.gemspec +2 -2
- metadata +41 -60
- data/lib/validates_timeliness/orm/mongoid.rb +0 -54
- data/spec/validates_timeliness/orm/mongoid_spec.rb +0 -113
|
@@ -12,68 +12,68 @@ describe ValidatesTimeliness::Conversion do
|
|
|
12
12
|
describe "#type_cast_value" do
|
|
13
13
|
describe "for date type" do
|
|
14
14
|
it "should return same value for date value" do
|
|
15
|
-
type_cast_value(Date.new(2010, 1, 1), :date).
|
|
15
|
+
expect(type_cast_value(Date.new(2010, 1, 1), :date)).to eq(Date.new(2010, 1, 1))
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "should return date part of time value" do
|
|
19
|
-
type_cast_value(Time.mktime(2010, 1, 1, 0, 0, 0), :date).
|
|
19
|
+
expect(type_cast_value(Time.mktime(2010, 1, 1, 0, 0, 0), :date)).to eq(Date.new(2010, 1, 1))
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "should return date part of datetime value" do
|
|
23
|
-
type_cast_value(DateTime.new(2010, 1, 1, 0, 0, 0), :date).
|
|
23
|
+
expect(type_cast_value(DateTime.new(2010, 1, 1, 0, 0, 0), :date)).to eq(Date.new(2010, 1, 1))
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it 'should return nil for invalid value types' do
|
|
27
|
-
type_cast_value(12, :date).
|
|
27
|
+
expect(type_cast_value(12, :date)).to eq(nil)
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
describe "for time type" do
|
|
32
32
|
it "should return same value for time value matching dummy date part" do
|
|
33
|
-
type_cast_value(Time.utc(2000, 1, 1, 0, 0, 0), :time).
|
|
33
|
+
expect(type_cast_value(Time.utc(2000, 1, 1, 0, 0, 0), :time)).to eq(Time.utc(2000, 1, 1, 0, 0, 0))
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "should return dummy time value with same time part for time value with different date" do
|
|
37
|
-
type_cast_value(Time.utc(2010, 1, 1, 0, 0, 0), :time).
|
|
37
|
+
expect(type_cast_value(Time.utc(2010, 1, 1, 0, 0, 0), :time)).to eq(Time.utc(2000, 1, 1, 0, 0, 0))
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it "should return dummy time only for date value" do
|
|
41
|
-
type_cast_value(Date.new(2010, 1, 1), :time).
|
|
41
|
+
expect(type_cast_value(Date.new(2010, 1, 1), :time)).to eq(Time.utc(2000, 1, 1, 0, 0, 0))
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it "should return dummy date with time part for datetime value" do
|
|
45
|
-
type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56), :time).
|
|
45
|
+
expect(type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56), :time)).to eq(Time.utc(2000, 1, 1, 12, 34, 56))
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it 'should return nil for invalid value types' do
|
|
49
|
-
type_cast_value(12, :time).
|
|
49
|
+
expect(type_cast_value(12, :time)).to eq(nil)
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
describe "for datetime type" do
|
|
54
54
|
it "should return Date as Time value" do
|
|
55
|
-
type_cast_value(Date.new(2010, 1, 1), :datetime).
|
|
55
|
+
expect(type_cast_value(Date.new(2010, 1, 1), :datetime)).to eq(Time.local(2010, 1, 1, 0, 0, 0))
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
it "should return same Time value" do
|
|
59
59
|
value = Time.utc(2010, 1, 1, 12, 34, 56)
|
|
60
|
-
type_cast_value(Time.utc(2010, 1, 1, 12, 34, 56), :datetime).
|
|
60
|
+
expect(type_cast_value(Time.utc(2010, 1, 1, 12, 34, 56), :datetime)).to eq(value)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it "should return as Time with same component values" do
|
|
64
|
-
type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56), :datetime).
|
|
64
|
+
expect(type_cast_value(DateTime.civil_from_format(:utc, 2010, 1, 1, 12, 34, 56), :datetime)).to eq(Time.utc(2010, 1, 1, 12, 34, 56))
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "should return same Time in correct zone if timezone aware" do
|
|
68
68
|
@timezone_aware = true
|
|
69
69
|
value = Time.utc(2010, 1, 1, 12, 34, 56)
|
|
70
70
|
result = type_cast_value(value, :datetime)
|
|
71
|
-
result.
|
|
72
|
-
result.zone.
|
|
71
|
+
expect(result).to eq(Time.zone.local(2010, 1, 1, 23, 34, 56))
|
|
72
|
+
expect(result.zone).to eq('AEDT')
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
it 'should return nil for invalid value types' do
|
|
76
|
-
type_cast_value(12, :datetime).
|
|
76
|
+
expect(type_cast_value(12, :datetime)).to eq(nil)
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
|
@@ -82,41 +82,41 @@ describe ValidatesTimeliness::Conversion do
|
|
|
82
82
|
|
|
83
83
|
it "should ignore usec on time values when evaluated" do
|
|
84
84
|
value = Time.utc(2010, 1, 1, 12, 34, 56, 10000)
|
|
85
|
-
type_cast_value(value, :datetime).
|
|
85
|
+
expect(type_cast_value(value, :datetime)).to eq(Time.utc(2010, 1, 1, 12, 34, 56))
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
it "should ignore usec and return time in correct zone if timezone aware" do
|
|
89
89
|
@timezone_aware = true
|
|
90
90
|
value = Time.utc(2010, 1, 1, 12, 34, 56, 10000)
|
|
91
91
|
result = type_cast_value(value, :datetime)
|
|
92
|
-
result.
|
|
93
|
-
result.zone.
|
|
92
|
+
expect(result).to eq(Time.zone.local(2010, 1, 1, 23, 34, 56))
|
|
93
|
+
expect(result.zone).to eq('AEDT')
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
describe "#dummy_time" do
|
|
99
99
|
it 'should return Time with dummy date values but same time components' do
|
|
100
|
-
dummy_time(Time.utc(2010, 11, 22, 12, 34, 56)).
|
|
100
|
+
expect(dummy_time(Time.utc(2010, 11, 22, 12, 34, 56))).to eq(Time.utc(2000, 1, 1, 12, 34, 56))
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
it 'should return same value for Time which already has dummy date values' do
|
|
104
|
-
dummy_time(Time.utc(2000, 1, 1, 12, 34, 56)).
|
|
104
|
+
expect(dummy_time(Time.utc(2000, 1, 1, 12, 34, 56))).to eq(Time.utc(2000, 1, 1, 12, 34, 56))
|
|
105
105
|
end
|
|
106
106
|
|
|
107
107
|
it 'should return time component values shifted to current zone if timezone aware' do
|
|
108
108
|
@timezone_aware = true
|
|
109
|
-
dummy_time(Time.utc(2000, 1, 1, 12, 34, 56)).
|
|
109
|
+
expect(dummy_time(Time.utc(2000, 1, 1, 12, 34, 56))).to eq(Time.zone.local(2000, 1, 1, 23, 34, 56))
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
it 'should return base dummy time value for Date value' do
|
|
113
|
-
dummy_time(Date.new(2010, 11, 22)).
|
|
113
|
+
expect(dummy_time(Date.new(2010, 11, 22))).to eq(Time.utc(2000, 1, 1, 0, 0, 0))
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
describe "with custom dummy date" do
|
|
117
117
|
it 'should return dummy time with custom dummy date' do
|
|
118
118
|
with_config(:dummy_date_for_time_type, [2010, 1, 1] ) do
|
|
119
|
-
dummy_time(Time.utc(1999, 11, 22, 12, 34, 56)).
|
|
119
|
+
expect(dummy_time(Time.utc(1999, 11, 22, 12, 34, 56))).to eq(Time.utc(2010, 1, 1, 12, 34, 56))
|
|
120
120
|
end
|
|
121
121
|
end
|
|
122
122
|
end
|
|
@@ -127,56 +127,56 @@ describe ValidatesTimeliness::Conversion do
|
|
|
127
127
|
|
|
128
128
|
it 'should return Date object as is' do
|
|
129
129
|
value = Date.new(2010,1,1)
|
|
130
|
-
evaluate_option_value(value, person).
|
|
130
|
+
expect(evaluate_option_value(value, person)).to eq(value)
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
it 'should return Time object as is' do
|
|
134
134
|
value = Time.mktime(2010,1,1)
|
|
135
|
-
evaluate_option_value(value, person).
|
|
135
|
+
expect(evaluate_option_value(value, person)).to eq(value)
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
it 'should return DateTime object as is' do
|
|
139
139
|
value = DateTime.new(2010,1,1,0,0,0)
|
|
140
|
-
evaluate_option_value(value, person).
|
|
140
|
+
expect(evaluate_option_value(value, person)).to eq(value)
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
it 'should return Time value returned from proc with 0 arity' do
|
|
144
144
|
value = Time.mktime(2010,1,1)
|
|
145
|
-
evaluate_option_value(lambda { value }, person).
|
|
145
|
+
expect(evaluate_option_value(lambda { value }, person)).to eq(value)
|
|
146
146
|
end
|
|
147
147
|
|
|
148
148
|
it 'should return Time value returned by record attribute call in proc arity of 1' do
|
|
149
149
|
value = Time.mktime(2010,1,1)
|
|
150
150
|
person.birth_time = value
|
|
151
|
-
evaluate_option_value(lambda {|r| r.birth_time }, person).
|
|
151
|
+
expect(evaluate_option_value(lambda {|r| r.birth_time }, person)).to eq(value)
|
|
152
152
|
end
|
|
153
153
|
|
|
154
154
|
it 'should return Time value for attribute method symbol which returns Time' do
|
|
155
155
|
value = Time.mktime(2010,1,1)
|
|
156
156
|
person.birth_time = value
|
|
157
|
-
evaluate_option_value(:birth_time, person).
|
|
157
|
+
expect(evaluate_option_value(:birth_time, person)).to eq(value)
|
|
158
158
|
end
|
|
159
159
|
|
|
160
160
|
it 'should return Time value is default zone from string time value' do
|
|
161
161
|
value = '2010-01-01 12:00:00'
|
|
162
|
-
evaluate_option_value(value, person).
|
|
162
|
+
expect(evaluate_option_value(value, person)).to eq(Time.utc(2010,1,1,12,0,0))
|
|
163
163
|
end
|
|
164
164
|
|
|
165
165
|
it 'should return Time value is current zone from string time value if timezone aware' do
|
|
166
166
|
@timezone_aware = true
|
|
167
167
|
value = '2010-01-01 12:00:00'
|
|
168
|
-
evaluate_option_value(value, person).
|
|
168
|
+
expect(evaluate_option_value(value, person)).to eq(Time.zone.local(2010,1,1,12,0,0))
|
|
169
169
|
end
|
|
170
170
|
|
|
171
171
|
it 'should return Time value in default zone from proc which returns string time' do
|
|
172
172
|
value = '2010-01-01 12:00:00'
|
|
173
|
-
evaluate_option_value(lambda { value }, person).
|
|
173
|
+
expect(evaluate_option_value(lambda { value }, person)).to eq(Time.utc(2010,1,1,12,0,0))
|
|
174
174
|
end
|
|
175
175
|
|
|
176
176
|
it 'should return Time value for attribute method symbol which returns string time value' do
|
|
177
177
|
value = '2010-01-01 12:00:00'
|
|
178
178
|
person.birth_time = value
|
|
179
|
-
evaluate_option_value(:birth_time, person).
|
|
179
|
+
expect(evaluate_option_value(:birth_time, person)).to eq(Time.zone.local(2010,1,1,12,0,0))
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
context "restriction shorthand" do
|
|
@@ -185,17 +185,17 @@ describe ValidatesTimeliness::Conversion do
|
|
|
185
185
|
end
|
|
186
186
|
|
|
187
187
|
it 'should evaluate :now as current time' do
|
|
188
|
-
evaluate_option_value(:now, person).
|
|
188
|
+
expect(evaluate_option_value(:now, person)).to eq(Time.now)
|
|
189
189
|
end
|
|
190
190
|
|
|
191
191
|
it 'should evaluate :today as current time' do
|
|
192
|
-
evaluate_option_value(:today, person).
|
|
192
|
+
expect(evaluate_option_value(:today, person)).to eq(Date.today)
|
|
193
193
|
end
|
|
194
194
|
|
|
195
195
|
it 'should not use shorthand if symbol if is record method' do
|
|
196
196
|
time = 1.day.from_now
|
|
197
|
-
person.
|
|
198
|
-
evaluate_option_value(:now, person).
|
|
197
|
+
allow(person).to receive(:now).and_return(time)
|
|
198
|
+
expect(evaluate_option_value(:now, person)).to eq(time)
|
|
199
199
|
end
|
|
200
200
|
end
|
|
201
201
|
end
|
|
@@ -205,7 +205,7 @@ describe ValidatesTimeliness::Conversion do
|
|
|
205
205
|
with_config(:use_plugin_parser, true)
|
|
206
206
|
|
|
207
207
|
it 'should use timeliness' do
|
|
208
|
-
Timeliness::Parser.
|
|
208
|
+
expect(Timeliness::Parser).to receive(:parse)
|
|
209
209
|
parse('2000-01-01')
|
|
210
210
|
end
|
|
211
211
|
end
|
|
@@ -215,20 +215,20 @@ describe ValidatesTimeliness::Conversion do
|
|
|
215
215
|
|
|
216
216
|
it 'should use Time.zone.parse attribute is timezone aware' do
|
|
217
217
|
@timezone_aware = true
|
|
218
|
-
Time.zone.
|
|
218
|
+
expect(Time.zone).to receive(:parse)
|
|
219
219
|
parse('2000-01-01')
|
|
220
220
|
end
|
|
221
221
|
|
|
222
222
|
it 'should use value#to_time if use_plugin_parser setting is false and attribute is not timezone aware' do
|
|
223
223
|
@timezone_aware = false
|
|
224
224
|
value = '2000-01-01'
|
|
225
|
-
value.
|
|
225
|
+
expect(value).to receive(:to_time)
|
|
226
226
|
parse(value)
|
|
227
227
|
end
|
|
228
228
|
end
|
|
229
229
|
|
|
230
230
|
it 'should return nil if value is nil' do
|
|
231
|
-
parse(nil).
|
|
231
|
+
expect(parse(nil)).to be_nil
|
|
232
232
|
end
|
|
233
233
|
end
|
|
234
234
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe ValidatesTimeliness::Extensions::DateTimeSelect do
|
|
3
|
+
describe 'ValidatesTimeliness::Extensions::DateTimeSelect' do
|
|
4
4
|
include ActionView::Helpers::DateHelper
|
|
5
5
|
attr_reader :person, :params
|
|
6
6
|
|
|
@@ -111,7 +111,7 @@ describe ValidatesTimeliness::Extensions::DateTimeSelect do
|
|
|
111
111
|
@output = date_select(:person, :birth_date, :include_blank => true, :discard_day => true)
|
|
112
112
|
should_have_datetime_selected(:birth_date, :year => 2009, :month => 'February')
|
|
113
113
|
should_not_have_datetime_selected(:birth_time, :day)
|
|
114
|
-
@output.
|
|
114
|
+
expect(@output).to have_tag("input[id=person_birth_date_3i][type=hidden][value='1']")
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
|
|
@@ -150,14 +150,15 @@ describe ValidatesTimeliness::Extensions::DateTimeSelect do
|
|
|
150
150
|
def should_have_datetime_selected(field, datetime_hash)
|
|
151
151
|
datetime_hash.each do |key, value|
|
|
152
152
|
index = {:year => 1, :month => 2, :day => 3, :hour => 4, :min => 5, :sec => 6}[key]
|
|
153
|
-
@output.
|
|
153
|
+
expect(@output).to have_tag("select[id=person_#{field}_#{index}i] option[selected=selected]", value.to_s)
|
|
154
154
|
end
|
|
155
155
|
end
|
|
156
156
|
|
|
157
157
|
def should_not_have_datetime_selected(field, *attributes)
|
|
158
158
|
attributes.each do |attribute|
|
|
159
159
|
index = {:year => 1, :month => 2, :day => 3, :hour => 4, :min => 5, :sec => 6}[attribute]
|
|
160
|
-
@output.
|
|
160
|
+
expect(@output).not_to have_tag("select[id=person_#{attribute}_#{index}i] option[selected=selected]")
|
|
161
161
|
end
|
|
162
162
|
end
|
|
163
|
+
|
|
163
164
|
end
|
|
@@ -1,33 +1,45 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe ValidatesTimeliness::Extensions::MultiparameterHandler do
|
|
4
|
-
let(:employee) { Employee.new }
|
|
3
|
+
describe 'ValidatesTimeliness::Extensions::MultiparameterHandler' do
|
|
5
4
|
|
|
6
5
|
context "time column" do
|
|
7
|
-
it 'should
|
|
8
|
-
|
|
9
|
-
employee.birth_datetime_before_type_cast.
|
|
6
|
+
it 'should assign a string value for invalid date portion' do
|
|
7
|
+
employee = record_with_multiparameter_attribute(:birth_datetime, [2000, 2, 31, 12, 0, 0])
|
|
8
|
+
expect(employee.birth_datetime_before_type_cast).to eq '2000-02-31 12:00:00'
|
|
10
9
|
end
|
|
11
10
|
|
|
12
|
-
it 'should
|
|
13
|
-
|
|
14
|
-
employee.birth_datetime_before_type_cast.
|
|
11
|
+
it 'should assign a Time value for valid datetimes' do
|
|
12
|
+
employee = record_with_multiparameter_attribute(:birth_datetime, [2000, 2, 28, 12, 0, 0])
|
|
13
|
+
expect(employee.birth_datetime_before_type_cast).to eq Time.zone.local(2000, 2, 28, 12, 0, 0)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'should assign a string value for incomplete time' do
|
|
17
|
+
employee = record_with_multiparameter_attribute(:birth_datetime, [2000, nil, nil])
|
|
18
|
+
expect(employee.birth_datetime_before_type_cast).to eq '2000-00-00'
|
|
15
19
|
end
|
|
16
20
|
end
|
|
17
21
|
|
|
18
22
|
context "date column" do
|
|
19
|
-
it 'should
|
|
20
|
-
|
|
21
|
-
employee.birth_date_before_type_cast.
|
|
23
|
+
it 'should assign a string value for invalid date' do
|
|
24
|
+
employee = record_with_multiparameter_attribute(:birth_date, [2000, 2, 31])
|
|
25
|
+
expect(employee.birth_date_before_type_cast).to eq '2000-02-31'
|
|
22
26
|
end
|
|
23
27
|
|
|
24
|
-
it 'should
|
|
25
|
-
|
|
26
|
-
employee.birth_date_before_type_cast.
|
|
28
|
+
it 'should assign a Date value for valid date' do
|
|
29
|
+
employee = record_with_multiparameter_attribute(:birth_date, [2000, 2, 28])
|
|
30
|
+
expect(employee.birth_date_before_type_cast).to eq Date.new(2000, 2, 28)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'should assign a string value for incomplete date' do
|
|
34
|
+
employee = record_with_multiparameter_attribute(:birth_date, [2000, nil, nil])
|
|
35
|
+
expect(employee.birth_date_before_type_cast).to eq '2000-00-00'
|
|
27
36
|
end
|
|
28
37
|
end
|
|
29
38
|
|
|
30
|
-
def
|
|
31
|
-
|
|
39
|
+
def record_with_multiparameter_attribute(name, values)
|
|
40
|
+
hash = {}
|
|
41
|
+
values.each_with_index {|value, index| hash["#{name}(#{index+1}i)"] = value.to_s }
|
|
42
|
+
Employee.new(hash)
|
|
32
43
|
end
|
|
44
|
+
|
|
33
45
|
end
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe ValidatesTimeliness, 'HelperMethods' do
|
|
4
|
+
let(:record) { Person.new }
|
|
5
|
+
|
|
4
6
|
it 'should define class validation methods' do
|
|
5
|
-
Person.
|
|
6
|
-
Person.
|
|
7
|
-
Person.
|
|
7
|
+
expect(Person).to respond_to(:validates_date)
|
|
8
|
+
expect(Person).to respond_to(:validates_time)
|
|
9
|
+
expect(Person).to respond_to(:validates_datetime)
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
it 'should define instance validation methods' do
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
expect(record).to respond_to(:validates_date)
|
|
14
|
+
expect(record).to respond_to(:validates_time)
|
|
15
|
+
expect(record).to respond_to(:validates_datetime)
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
it 'should validate instance using class validation defined' do
|
|
17
19
|
Person.validates_date :birth_date
|
|
18
|
-
|
|
19
|
-
r.valid?
|
|
20
|
+
record.valid?
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
expect(record.errors[:birth_date]).not_to be_empty
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
it 'should validate instance using instance valiation method' do
|
|
25
|
-
|
|
26
|
-
r.validates_date :birth_date
|
|
26
|
+
record.validates_date :birth_date
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
expect(record.errors[:birth_date]).not_to be_empty
|
|
29
29
|
end
|
|
30
30
|
end
|