validates_timeliness 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,44 +9,110 @@ describe ValidatesTimeliness::ActiveRecord::MultiparameterAttributes do
9
9
  time_string = time_array_to_string([2000,2,1,9,10,11], :datetime)
10
10
  time_string.should == "2000-02-01 09:10:11"
11
11
  end
12
-
12
+
13
13
  it "should convert array for date type into date string" do
14
14
  time_string = time_array_to_string([2000,2,1], :date)
15
15
  time_string.should == "2000-02-01"
16
16
  end
17
-
17
+
18
18
  it "should convert array for time type into time string" do
19
19
  time_string = time_array_to_string([2000,1,1,9,10,11], :time)
20
20
  time_string.should == "09:10:11"
21
21
  end
22
-
23
- describe "execute_callstack_for_multiparameter_attributes" do
24
- before do
25
- @callstack = {
26
- 'birth_date_and_time' => [2000,2,1,9,10,11],
27
- 'birth_date' => [2000,2,1,9,10,11],
28
- 'birth_time' => [2000,2,1,9,10,11]
29
- }
22
+
23
+ describe "execute_callstack_for_multiparameter_attributes" do
24
+
25
+ describe "for valid values" do
26
+ before do
27
+ @callstack = {
28
+ 'birth_date_and_time' => [2000,2,1,9,10,11],
29
+ 'birth_date' => [2000,2,1,9,10,11],
30
+ 'birth_time' => [2000,2,1,9,10,11]
31
+ }
32
+ end
33
+
34
+ it "should store datetime string for datetime column" do
35
+ obj.should_receive(:birth_date_and_time=).once.with("2000-02-01 09:10:11")
36
+ obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
37
+ end
38
+
39
+ it "should store date string for a date column" do
40
+ obj.should_receive(:birth_date=).once.with("2000-02-01")
41
+ obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
42
+ end
43
+
44
+ it "should store time string for a time column" do
45
+ obj.should_receive(:birth_time=).once.with("09:10:11")
46
+ obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
47
+ end
30
48
  end
31
-
32
- it "should store datetime string for datetime column" do
33
- obj.should_receive(:birth_date_and_time=).once.with("2000-02-01 09:10:11")
34
- obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
35
- end
36
-
37
- it "should store date string for a date column" do
38
- obj.should_receive(:birth_date=).once.with("2000-02-01")
39
- obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
49
+
50
+ describe "for invalid values" do
51
+ before do
52
+ @callstack = {
53
+ 'birth_date_and_time' => [2000,13,1,9,10,11],
54
+ 'birth_date' => [2000,2,41,9,10,11],
55
+ 'birth_time' => [2000,2,1,25,10,11]
56
+ }
57
+ end
58
+
59
+ it "should store invalid datetime string for datetime column" do
60
+ obj.should_receive(:birth_date_and_time=).once.with("2000-13-01 09:10:11")
61
+ obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
62
+ end
63
+
64
+ it "should store invalid date string for a date column" do
65
+ obj.should_receive(:birth_date=).once.with("2000-02-41")
66
+ obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
67
+ end
68
+
69
+ it "should store invalid time string for a time column" do
70
+ obj.should_receive(:birth_time=).once.with("25:10:11")
71
+ obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
72
+ end
40
73
  end
41
-
42
- it "should store time string for a time column" do
43
- obj.should_receive(:birth_time=).once.with("09:10:11")
44
- obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
74
+
75
+ describe "for missing values" do
76
+ it "should store nil if all datetime values nil" do
77
+ obj.should_receive(:birth_date_and_time=).once.with(nil)
78
+ callstack = { 'birth_date_and_time' => [nil,nil,nil,nil,nil,nil] }
79
+ obj.send(:execute_callstack_for_multiparameter_attributes, callstack)
80
+ end
81
+
82
+ it "should store nil year as empty value in string" do
83
+ obj.should_receive(:birth_date_and_time=).once.with("-02-01 09:10:11")
84
+ callstack = { 'birth_date_and_time' => [nil,2,1,9,10,11] }
85
+ obj.send(:execute_callstack_for_multiparameter_attributes, callstack)
86
+ end
87
+
88
+ it "should store nil month as empty value in string" do
89
+ obj.should_receive(:birth_date_and_time=).once.with("2000--01 09:10:11")
90
+ callstack = { 'birth_date_and_time' => [2000,nil,1,9,10,11] }
91
+ obj.send(:execute_callstack_for_multiparameter_attributes, callstack)
92
+ end
93
+
94
+ it "should store nil day as empty value in string" do
95
+ obj.should_receive(:birth_date_and_time=).once.with("2000-02- 09:10:11")
96
+ callstack = { 'birth_date_and_time' => [2000,2,nil,9,10,11] }
97
+ obj.send(:execute_callstack_for_multiparameter_attributes, callstack)
98
+ end
99
+
100
+ it "should store nil hour as empty value in string" do
101
+ obj.should_receive(:birth_date_and_time=).once.with("2000-02-01 :10:11")
102
+ callstack = { 'birth_date_and_time' => [2000,2,1,nil,10,11] }
103
+ obj.send(:execute_callstack_for_multiparameter_attributes, callstack)
104
+ end
105
+
106
+ it "should store nil minute as empty value in string" do
107
+ obj.should_receive(:birth_date_and_time=).once.with("2000-02-01 09:10:")
108
+ callstack = { 'birth_date_and_time' => [2000,2,1,9,10,nil] }
109
+ obj.send(:execute_callstack_for_multiparameter_attributes, callstack)
110
+ end
45
111
  end
46
112
  end
47
113
 
48
114
  def time_array_to_string(*args)
49
115
  ValidatesTimeliness::ActiveRecord.time_array_to_string(*args)
50
116
  end
51
-
117
+
52
118
  end
data/spec/formats_spec.rb CHANGED
@@ -1,28 +1,28 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe ValidatesTimeliness::Formats do
4
-
4
+
5
5
  describe "format proc generator" do
6
6
  it "should generate proc which outputs date array with values in correct order" do
7
7
  generate_proc('yyyy-mm-dd').call('2000', '1', '2').should == [2000,1,2,0,0,0,0]
8
- end
9
-
8
+ end
9
+
10
10
  it "should generate proc which outputs date array from format with different order" do
11
11
  generate_proc('dd/mm/yyyy').call('2', '1', '2000').should == [2000,1,2,0,0,0,0]
12
12
  end
13
-
13
+
14
14
  it "should generate proc which outputs time array" do
15
15
  generate_proc('hh:nn:ss').call('01', '02', '03').should == [0,0,0,1,2,3,0]
16
16
  end
17
-
17
+
18
18
  it "should generate proc which outputs time array with meridian 'pm' adjusted hour" do
19
19
  generate_proc('hh:nn:ss ampm').call('01', '02', '03', 'pm').should == [0,0,0,13,2,3,0]
20
20
  end
21
-
21
+
22
22
  it "should generate proc which outputs time array with meridian 'am' unadjusted hour" do
23
23
  generate_proc('hh:nn:ss ampm').call('01', '02', '03', 'am').should == [0,0,0,1,2,3,0]
24
24
  end
25
-
25
+
26
26
  it "should generate proc which outputs time array with microseconds" do
27
27
  generate_proc('hh:nn:ss.u').call('01', '02', '03', '99').should == [0,0,0,1,2,3,990000]
28
28
  end
@@ -31,11 +31,11 @@ describe ValidatesTimeliness::Formats do
31
31
  generate_proc('yyyy-mm-dd hh:nn:ss.u zo').call('2001', '02', '03', '04', '05', '06', '99', '+10:00').should == [2001,2,3,4,5,6,990000,36000]
32
32
  end
33
33
  end
34
-
35
- describe "validation regexps" do
36
-
34
+
35
+ describe "validate regexps" do
36
+
37
37
  describe "for time formats" do
38
- format_tests = {
38
+ format_tests = {
39
39
  'hh:nn:ss' => {:pass => ['12:12:12', '01:01:01'], :fail => ['1:12:12', '12:1:12', '12:12:1', '12-12-12']},
40
40
  'hh-nn-ss' => {:pass => ['12-12-12', '01-01-01'], :fail => ['1-12-12', '12-1-12', '12-12-1', '12:12:12']},
41
41
  'h:nn' => {:pass => ['12:12', '1:01'], :fail => ['12:2', '12-12']},
@@ -54,9 +54,9 @@ describe ValidatesTimeliness::Formats do
54
54
  values[:pass].each {|value| value.should match(regexp)}
55
55
  values[:fail].each {|value| value.should_not match(regexp)}
56
56
  end
57
- end
57
+ end
58
58
  end
59
-
59
+
60
60
  describe "for date formats" do
61
61
  format_tests = {
62
62
  'yyyy/mm/dd' => {:pass => ['2000/02/01'], :fail => ['2000\02\01', '2000/2/1', '00/02/01']},
@@ -68,50 +68,50 @@ describe ValidatesTimeliness::Formats do
68
68
  'd\m\yy' => {:pass => ['1\2\01', '1\02\00', '01\02\2000'], :fail => ['1\2\0', '1/2/01']},
69
69
  'd-m-yy' => {:pass => ['1-2-01', '1-02-00', '01-02-2000'], :fail => ['1-2-0', '1/2/01']},
70
70
  'd.m.yy' => {:pass => ['1.2.01', '1.02.00', '01.02.2000'], :fail => ['1.2.0', '1/2/01']},
71
- 'd mmm yy' => {:pass => ['1 Feb 00', '1 Feb 2000', '1 February 00', '01 February 2000'],
71
+ 'd mmm yy' => {:pass => ['1 Feb 00', '1 Feb 2000', '1 February 00', '01 February 2000'],
72
72
  :fail => ['1 Fe 00', 'Feb 1 2000', '1 Feb 0']}
73
- }
74
- format_tests.each do |format, values|
73
+ }
74
+ format_tests.each do |format, values|
75
75
  it "should correctly validate dates in format '#{format}'" do
76
76
  regexp = generate_regexp(format)
77
77
  values[:pass].each {|value| value.should match(regexp)}
78
78
  values[:fail].each {|value| value.should_not match(regexp)}
79
79
  end
80
- end
80
+ end
81
81
  end
82
-
82
+
83
83
  describe "for datetime formats" do
84
84
  format_tests = {
85
85
  'ddd mmm d hh:nn:ss zo yyyy' => {:pass => ['Sat Jul 19 12:00:00 +1000 2008'], :fail => []},
86
86
  'yyyy-mm-ddThh:nn:ss(?:Z|zo)' => {:pass => ['2008-07-19T12:00:00+10:00', '2008-07-19T12:00:00Z'], :fail => ['2008-07-19T12:00:00Z+10:00']},
87
- }
88
- format_tests.each do |format, values|
87
+ }
88
+ format_tests.each do |format, values|
89
89
  it "should correctly validate datetimes in format '#{format}'" do
90
90
  regexp = generate_regexp(format)
91
91
  values[:pass].each {|value| value.should match(regexp)}
92
92
  values[:fail].each {|value| value.should_not match(regexp)}
93
93
  end
94
- end
94
+ end
95
95
  end
96
96
  end
97
-
97
+
98
98
  describe "parse" do
99
-
99
+
100
100
  it "should return time array from date string" do
101
101
  time_array = formats.parse('12:13:14', :time, :strict => true)
102
102
  time_array.should == [2000,1,1,12,13,14,0]
103
103
  end
104
-
104
+
105
105
  it "should return date array from time string" do
106
106
  time_array = formats.parse('2000-02-01', :date, :strict => true)
107
107
  time_array.should == [2000,2,1,0,0,0,0]
108
108
  end
109
-
109
+
110
110
  it "should return datetime array from string value" do
111
111
  time_array = formats.parse('2000-02-01 12:13:14', :datetime, :strict => true)
112
112
  time_array.should == [2000,2,1,12,13,14,0]
113
113
  end
114
-
114
+
115
115
  it "should parse date string when type is datetime" do
116
116
  time_array = formats.parse('2000-02-01', :datetime, :strict => false)
117
117
  time_array.should == [2000,2,1,0,0,0,0]
@@ -126,18 +126,18 @@ describe ValidatesTimeliness::Formats do
126
126
  time_array = formats.parse('01-02-2000 12:13', :date, :strict => false)
127
127
  time_array.should == [2000,2,1,0,0,0,0]
128
128
  end
129
-
129
+
130
130
  it "should ignore date when extracting time and strict is false" do
131
131
  time_array = formats.parse('2000-02-01 12:13', :time, :strict => false)
132
132
  time_array.should == [2000,1,1,12,13,0,0]
133
133
  end
134
134
 
135
- it "should return zone offset when :include_offset options is true" do
135
+ it "should return zone offset when :include_offset option is true" do
136
136
  time_array = formats.parse('2000-02-01T12:13:14-10:30', :datetime, :include_offset => true)
137
137
  time_array.should == [2000,2,1,12,13,14,0,-37800]
138
138
  end
139
139
  end
140
-
140
+
141
141
  describe "parse with format option" do
142
142
  it "should return values if string matches specified format" do
143
143
  time_array = formats.parse('2000-02-01 12:13:14', :datetime, :format => 'yyyy-mm-dd hh:nn:ss')
@@ -188,45 +188,57 @@ describe ValidatesTimeliness::Formats do
188
188
  end
189
189
  end
190
190
 
191
+ describe "parse ISO8601 datetime" do
192
+ it "should return array without zone offset when no offset in string" do
193
+ time_array = formats.parse('2000-02-01T12:13:14Z', :datetime, :strict => true)
194
+ time_array.should == [2000,2,1,12,13,14,0]
195
+ end
196
+
197
+ it "should return array with zone offset when offset in string" do
198
+ time_array = formats.parse('2000-02-01T12:13:14+10:00', :datetime, :strict => true)
199
+ time_array.should == [2000,2,1,12,13,14,0,36000]
200
+ end
201
+ end
202
+
191
203
  describe "removing formats" do
192
- it "should remove format from format array" do
204
+ it "should remove format from format array" do
193
205
  formats.remove_formats(:time, 'h.nn_ampm')
194
206
  formats.time_formats.should_not include("h o'clock")
195
207
  end
196
-
197
- it "should not match time after its format is removed" do
208
+
209
+ it "should not match time after its format is removed" do
198
210
  validate('2.12am', :time).should be_true
199
211
  formats.remove_formats(:time, 'h.nn_ampm')
200
212
  validate('2.12am', :time).should be_false
201
213
  end
202
-
214
+
203
215
  it "should raise error if format does not exist" do
204
216
  lambda { formats.remove_formats(:time, "ss:hh:nn") }.should raise_error()
205
217
  end
206
-
218
+
207
219
  after do
208
220
  formats.time_formats << 'h.nn_ampm'
209
221
  formats.compile_format_expressions
210
222
  end
211
223
  end
212
-
213
- describe "adding formats" do
224
+
225
+ describe "adding formats" do
214
226
  before do
215
227
  formats.compile_format_expressions
216
228
  end
217
-
229
+
218
230
  it "should add format to format array" do
219
231
  formats.add_formats(:time, "h o'clock")
220
232
  formats.time_formats.should include("h o'clock")
221
233
  end
222
-
223
- it "should match new format after its added" do
234
+
235
+ it "should match new format after its added" do
224
236
  validate("12 o'clock", :time).should be_false
225
237
  formats.add_formats(:time, "h o'clock")
226
238
  validate("12 o'clock", :time).should be_true
227
239
  end
228
-
229
- it "should add format before specified format and be higher precedence" do
240
+
241
+ it "should add format before specified format and be higher precedence" do
230
242
  formats.add_formats(:time, "ss:hh:nn", :before => 'hh:nn:ss')
231
243
  validate("59:23:58", :time).should be_true
232
244
  time_array = formats.parse('59:23:58', :time)
@@ -236,18 +248,18 @@ describe ValidatesTimeliness::Formats do
236
248
  it "should raise error if format exists" do
237
249
  lambda { formats.add_formats(:time, "hh:nn:ss") }.should raise_error()
238
250
  end
239
-
251
+
240
252
  it "should raise error if format exists" do
241
253
  lambda { formats.add_formats(:time, "ss:hh:nn", :before => 'nn:hh:ss') }.should raise_error()
242
254
  end
243
-
255
+
244
256
  after do
245
257
  formats.time_formats.delete("h o'clock")
246
258
  formats.time_formats.delete("ss:hh:nn")
247
259
  # reload class instead
248
260
  end
249
261
  end
250
-
262
+
251
263
  describe "removing US formats" do
252
264
  it "should validate a date as European format when US formats removed" do
253
265
  time_array = formats.parse('01/02/2000', :date)
@@ -256,13 +268,13 @@ describe ValidatesTimeliness::Formats do
256
268
  time_array = formats.parse('01/02/2000', :date)
257
269
  time_array.should == [2000, 2, 1,0,0,0,0]
258
270
  end
259
-
271
+
260
272
  after do
261
- # reload class
273
+ # reload class
262
274
  end
263
275
  end
264
-
265
-
276
+
277
+
266
278
  def formats
267
279
  ValidatesTimeliness::Formats
268
280
  end
@@ -274,20 +286,20 @@ describe ValidatesTimeliness::Formats do
274
286
  end
275
287
  valid
276
288
  end
277
-
289
+
278
290
  def generate_regexp(format)
279
291
  # wrap in line start and end anchors to emulate extract values method
280
- /\A#{formats.send(:format_expression_generator, format)[0]}\Z/
292
+ /\A#{formats.send(:generate_format_expression, format)[0]}\Z/
281
293
  end
282
-
294
+
283
295
  def generate_regexp_str(format)
284
- formats.send(:format_expression_generator, format)[0].inspect
296
+ formats.send(:generate_format_expression, format)[0].inspect
285
297
  end
286
-
298
+
287
299
  def generate_proc(format)
288
- formats.send(:format_expression_generator, format)[1]
300
+ formats.send(:generate_format_expression, format)[1]
289
301
  end
290
-
302
+
291
303
  def delete_format(type, format)
292
304
  formats.send("#{type}_formats").delete(format)
293
305
  end
@@ -1,15 +1,15 @@
1
1
  # For use with the ginger gem to test plugin against multiple versions of Rails.
2
2
  #
3
3
  # To use ginger:
4
- #
5
- # sudo gem install freelancing-god-ginger --source=http://gems.github.com
4
+ #
5
+ # gem install ginger
6
6
  #
7
7
  # Then run
8
8
  #
9
9
  # ginger spec
10
10
  #
11
11
  Ginger.configure do |config|
12
- rails_versions = ['2.0.2', '2.1.2', '2.2.2', '2.3.3', '2.3.4']
12
+ rails_versions = ['2.0.2', '2.1.2', '2.2.2', '2.3.3', '2.3.4', '2.3.5']
13
13
 
14
14
  rails_versions.each do |v|
15
15
  g = Ginger::Scenario.new("Rails #{v}")
@@ -5,24 +5,24 @@ class NoValidation < Person
5
5
  end
6
6
 
7
7
  class WithValidation < Person
8
- validates_date :birth_date,
9
- :equal_to => '2000-01-01',
8
+ validates_date :birth_date,
9
+ :is_at => '2000-01-01',
10
10
  :before => '2000-01-10',
11
11
  :after => '2000-01-01',
12
12
  :on_or_before => '2000-01-09',
13
13
  :on_or_after => '2000-01-02',
14
14
  :between => ['2000-01-01', '2000-01-03']
15
15
 
16
- validates_time :birth_time,
17
- :equal_to => '09:00',
16
+ validates_time :birth_time,
17
+ :is_at => '09:00',
18
18
  :before => '23:00',
19
19
  :after => '09:00',
20
20
  :on_or_before => '22:00',
21
21
  :on_or_after => '10:00',
22
22
  :between => ['09:00', '17:00']
23
23
 
24
- validates_datetime :birth_date_and_time,
25
- :equal_to => '2000-01-01 09:00',
24
+ validates_datetime :birth_date_and_time,
25
+ :is_at => '2000-01-01 09:00',
26
26
  :before => '2000-01-10 23:00',
27
27
  :after => '2000-01-01 09:00',
28
28
  :on_or_before => '2000-01-09 23:00',
@@ -46,44 +46,44 @@ end
46
46
 
47
47
  describe "ValidateTimeliness matcher" do
48
48
  attr_accessor :no_validation, :with_validation
49
-
49
+
50
50
  @@attribute_for_type = { :date => :birth_date, :time => :birth_time, :datetime => :birth_date_and_time }
51
-
51
+
52
52
  before do
53
53
  @no_validation = NoValidation.new
54
54
  @with_validation = WithValidation.new
55
55
  end
56
56
 
57
57
  [:date, :time, :datetime].each do |type|
58
-
58
+
59
59
  it "should report that #{type} is validated" do
60
60
  with_validation.should self.send("validate_#{type}", attribute_for_type(type))
61
61
  end
62
-
62
+
63
63
  it "should report that #{type} is not validated" do
64
64
  no_validation.should_not self.send("validate_#{type}", attribute_for_type(type))
65
- end
65
+ end
66
66
  end
67
-
68
- describe "with equal_to option" do
67
+
68
+ describe "with is_at option" do
69
69
  test_values = {
70
70
  :date => ['2000-01-01', '2000-01-02'],
71
71
  :time => ['09:00', '09:01'],
72
72
  :datetime => ['2000-01-01 09:00', '2000-01-01 09:01']
73
73
  }
74
-
74
+
75
75
  [:date, :time, :datetime].each do |type|
76
76
 
77
77
  it "should report that #{type} is validated" do
78
- with_validation.should self.send("validate_#{type}", attribute_for_type(type), :equal_to => test_values[type][0])
78
+ with_validation.should self.send("validate_#{type}", attribute_for_type(type), :is_at => test_values[type][0])
79
79
  end
80
-
80
+
81
81
  it "should report that #{type} is not validated when option value is incorrect" do
82
- with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :equal_to => test_values[type][1])
82
+ with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :is_at => test_values[type][1])
83
83
  end
84
-
84
+
85
85
  it "should report that #{type} is not validated with option" do
86
- no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :equal_to => test_values[type][0])
86
+ no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :is_at => test_values[type][0])
87
87
  end
88
88
  end
89
89
  end
@@ -92,111 +92,111 @@ describe "ValidateTimeliness matcher" do
92
92
  test_values = {
93
93
  :date => ['2000-01-10', '2000-01-11'],
94
94
  :time => ['23:00', '22:59'],
95
- :datetime => ['2000-01-10 23:00', '2000-01-10 22:59']
95
+ :datetime => ['2000-01-10 23:00', '2000-01-10 22:59']
96
96
  }
97
-
97
+
98
98
  [:date, :time, :datetime].each do |type|
99
99
 
100
100
  it "should report that #{type} is validated" do
101
101
  with_validation.should self.send("validate_#{type}", attribute_for_type(type), :before => test_values[type][0])
102
102
  end
103
-
103
+
104
104
  it "should report that #{type} is not validated when option value is incorrect" do
105
105
  with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :before => test_values[type][1])
106
106
  end
107
-
107
+
108
108
  it "should report that #{type} is not validated with option" do
109
109
  no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :before => test_values[type][0])
110
110
  end
111
111
  end
112
112
  end
113
-
113
+
114
114
  describe "with after option" do
115
115
  test_values = {
116
116
  :date => ['2000-01-01', '2000-01-02'],
117
117
  :time => ['09:00', '09:01'],
118
- :datetime => ['2000-01-01 09:00', '2000-01-01 09:01']
118
+ :datetime => ['2000-01-01 09:00', '2000-01-01 09:01']
119
119
  }
120
-
120
+
121
121
  [:date, :time, :datetime].each do |type|
122
122
 
123
123
  it "should report that #{type} is validated" do
124
124
  with_validation.should self.send("validate_#{type}", attribute_for_type(type), :after => test_values[type][0])
125
125
  end
126
-
126
+
127
127
  it "should report that #{type} is not validated when option value is incorrect" do
128
128
  with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :after => test_values[type][1])
129
129
  end
130
-
130
+
131
131
  it "should report that #{type} is not validated with option" do
132
132
  no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :after => test_values[type][0])
133
133
  end
134
134
  end
135
135
  end
136
-
136
+
137
137
  describe "with on_or_before option" do
138
138
  test_values = {
139
139
  :date => ['2000-01-09', '2000-01-08'],
140
140
  :time => ['22:00', '21:59'],
141
- :datetime => ['2000-01-09 23:00', '2000-01-09 22:59']
141
+ :datetime => ['2000-01-09 23:00', '2000-01-09 22:59']
142
142
  }
143
-
143
+
144
144
  [:date, :time, :datetime].each do |type|
145
145
 
146
146
  it "should report that #{type} is validated" do
147
147
  with_validation.should self.send("validate_#{type}", attribute_for_type(type), :on_or_before => test_values[type][0])
148
148
  end
149
-
149
+
150
150
  it "should report that #{type} is not validated when option value is incorrect" do
151
151
  with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :on_or_before => test_values[type][1])
152
152
  end
153
-
153
+
154
154
  it "should report that #{type} is not validated with option" do
155
155
  no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :on_or_before => test_values[type][0])
156
156
  end
157
157
  end
158
158
  end
159
-
159
+
160
160
  describe "with on_or_after option" do
161
161
  test_values = {
162
162
  :date => ['2000-01-02', '2000-01-03'],
163
163
  :time => ['10:00', '10:01'],
164
- :datetime => ['2000-01-02 09:00', '2000-01-02 09:01']
164
+ :datetime => ['2000-01-02 09:00', '2000-01-02 09:01']
165
165
  }
166
-
166
+
167
167
  [:date, :time, :datetime].each do |type|
168
168
 
169
169
  it "should report that #{type} is validated" do
170
170
  with_validation.should self.send("validate_#{type}", attribute_for_type(type), :on_or_after => test_values[type][0])
171
171
  end
172
-
172
+
173
173
  it "should report that #{type} is not validated when option value is incorrect" do
174
174
  with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :on_or_after => test_values[type][1])
175
175
  end
176
-
176
+
177
177
  it "should report that #{type} is not validated with option" do
178
178
  no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :on_or_after => test_values[type][0])
179
179
  end
180
180
  end
181
181
  end
182
-
182
+
183
183
  describe "between option" do
184
184
  test_values = {
185
185
  :date => [ ['2000-01-01', '2000-01-03'], ['2000-01-01', '2000-01-04'] ],
186
- :time => [ ['09:00', '17:00'], ['09:00', '17:01'] ],
187
- :datetime => [ ['2000-01-01 09:00', '2000-01-01 17:00'], ['2000-01-01 09:00', '2000-01-01 17:01'] ]
186
+ :time => [ ['09:00', '17:00'], ['09:00', '17:01'] ],
187
+ :datetime => [ ['2000-01-01 09:00', '2000-01-01 17:00'], ['2000-01-01 09:00', '2000-01-01 17:01'] ]
188
188
  }
189
-
189
+
190
190
  [:date, :time, :datetime].each do |type|
191
191
 
192
192
  it "should report that #{type} is validated" do
193
193
  with_validation.should self.send("validate_#{type}", attribute_for_type(type), :between => test_values[type][0])
194
194
  end
195
-
195
+
196
196
  it "should report that #{type} is not validated when option value is incorrect" do
197
197
  with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :between => test_values[type][1])
198
198
  end
199
-
199
+
200
200
  it "should report that #{type} is not validated with option" do
201
201
  no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :between => test_values[type][0])
202
202
  end
@@ -208,35 +208,35 @@ describe "ValidateTimeliness matcher" do
208
208
  before do
209
209
  @person = CustomMessages.new
210
210
  end
211
-
211
+
212
212
  it "should match error message for invalid" do
213
213
  @person.should validate_date(:birth_date, :invalid_date_message => 'is not really a date')
214
214
  end
215
-
215
+
216
216
  it "should match error message for before option" do
217
- @person.should validate_date(:birth_date, :before => '2000-01-10',
217
+ @person.should validate_date(:birth_date, :before => '2000-01-10',
218
218
  :invalid_date_message => 'is not really a date',
219
219
  :before_message => 'is too late')
220
220
  end
221
-
221
+
222
222
  it "should match error message for after option" do
223
- @person.should validate_date(:birth_date, :after => '2000-01-01',
223
+ @person.should validate_date(:birth_date, :after => '2000-01-01',
224
224
  :invalid_date_message => 'is not really a date',
225
225
  :after_message => 'is too early')
226
- end
226
+ end
227
227
 
228
228
  it "should match error message for on_or_before option" do
229
229
  @person.should validate_date(:birth_date, :on_or_before => '2000-01-09',
230
230
  :invalid_date_message => 'is not really a date',
231
231
  :on_or_before_message => 'is just too late')
232
232
  end
233
-
233
+
234
234
  it "should match error message for on_or_after option" do
235
235
  @person.should validate_date(:birth_date, :on_or_after => '2000-01-02',
236
236
  :invalid_date_message => 'is not really a date',
237
237
  :on_or_after_message => 'is just too early')
238
238
  end
239
-
239
+
240
240
  end
241
241
 
242
242
  def attribute_for_type(type)