validates_timeliness 2.3.2 → 3.0.0.beta
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.
- data/CHANGELOG +12 -4
- data/LICENSE +1 -1
- data/README.rdoc +138 -280
- data/Rakefile +30 -16
- data/lib/generators/validates_timeliness/install_generator.rb +17 -0
- data/lib/generators/validates_timeliness/templates/en.yml +16 -0
- data/lib/generators/validates_timeliness/templates/validates_timeliness.rb +22 -0
- data/lib/validates_timeliness.rb +46 -52
- data/lib/validates_timeliness/attribute_methods.rb +51 -0
- data/lib/validates_timeliness/conversion.rb +69 -0
- data/lib/validates_timeliness/extensions.rb +14 -0
- data/lib/validates_timeliness/extensions/date_time_select.rb +45 -0
- data/lib/validates_timeliness/extensions/multiparameter_handler.rb +31 -0
- data/lib/validates_timeliness/helper_methods.rb +41 -0
- data/lib/validates_timeliness/orms/active_record.rb +14 -0
- data/lib/validates_timeliness/parser.rb +389 -17
- data/lib/validates_timeliness/validator.rb +37 -200
- data/lib/validates_timeliness/version.rb +1 -1
- data/spec/model_helpers.rb +27 -0
- data/spec/spec_helper.rb +74 -43
- data/spec/test_model.rb +56 -0
- data/spec/validates_timeliness/attribute_methods_spec.rb +36 -0
- data/spec/validates_timeliness/conversion_spec.rb +204 -0
- data/spec/validates_timeliness/extensions/date_time_select_spec.rb +178 -0
- data/spec/validates_timeliness/extensions/multiparameter_handler_spec.rb +21 -0
- data/spec/validates_timeliness/helper_methods_spec.rb +36 -0
- data/spec/{formats_spec.rb → validates_timeliness/parser_spec.rb} +105 -71
- data/spec/validates_timeliness/validator/after_spec.rb +59 -0
- data/spec/validates_timeliness/validator/before_spec.rb +59 -0
- data/spec/validates_timeliness/validator/is_at_spec.rb +63 -0
- data/spec/validates_timeliness/validator/on_or_after_spec.rb +59 -0
- data/spec/validates_timeliness/validator/on_or_before_spec.rb +59 -0
- data/spec/validates_timeliness/validator_spec.rb +172 -0
- data/validates_timeliness.gemspec +30 -0
- metadata +42 -40
- data/TODO +0 -8
- data/lib/validates_timeliness/action_view/instance_tag.rb +0 -52
- data/lib/validates_timeliness/active_record/attribute_methods.rb +0 -77
- data/lib/validates_timeliness/active_record/multiparameter_attributes.rb +0 -69
- data/lib/validates_timeliness/formats.rb +0 -368
- data/lib/validates_timeliness/locale/en.new.yml +0 -18
- data/lib/validates_timeliness/locale/en.old.yml +0 -18
- data/lib/validates_timeliness/matcher.rb +0 -1
- data/lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb +0 -162
- data/lib/validates_timeliness/validation_methods.rb +0 -46
- data/spec/action_view/instance_tag_spec.rb +0 -194
- data/spec/active_record/attribute_methods_spec.rb +0 -157
- data/spec/active_record/multiparameter_attributes_spec.rb +0 -118
- data/spec/ginger_scenarios.rb +0 -19
- data/spec/parser_spec.rb +0 -65
- data/spec/resources/application.rb +0 -2
- data/spec/resources/person.rb +0 -3
- data/spec/resources/schema.rb +0 -10
- data/spec/resources/sqlite_patch.rb +0 -19
- data/spec/spec/rails/matchers/validate_timeliness_spec.rb +0 -245
- data/spec/time_travel/MIT-LICENSE +0 -20
- data/spec/time_travel/time_extensions.rb +0 -33
- data/spec/time_travel/time_travel.rb +0 -12
- data/spec/validator_spec.rb +0 -723
@@ -1,118 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe ValidatesTimeliness::ActiveRecord::MultiparameterAttributes do
|
4
|
-
def obj
|
5
|
-
@obj ||= Person.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should convert array for datetime type into datetime string" do
|
9
|
-
time_string = time_array_to_string([2000,2,1,9,10,11], :datetime)
|
10
|
-
time_string.should == "2000-02-01 09:10:11"
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should convert array for date type into date string" do
|
14
|
-
time_string = time_array_to_string([2000,2,1], :date)
|
15
|
-
time_string.should == "2000-02-01"
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should convert array for time type into time string" do
|
19
|
-
time_string = time_array_to_string([2000,1,1,9,10,11], :time)
|
20
|
-
time_string.should == "09:10:11"
|
21
|
-
end
|
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
|
48
|
-
end
|
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
|
73
|
-
end
|
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
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def time_array_to_string(*args)
|
115
|
-
ValidatesTimeliness::ActiveRecord.time_array_to_string(*args)
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
data/spec/ginger_scenarios.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# For use with the ginger gem to test plugin against multiple versions of Rails.
|
2
|
-
#
|
3
|
-
# To use ginger:
|
4
|
-
#
|
5
|
-
# gem install ginger
|
6
|
-
#
|
7
|
-
# Then run
|
8
|
-
#
|
9
|
-
# ginger spec
|
10
|
-
#
|
11
|
-
Ginger.configure do |config|
|
12
|
-
rails_versions = ['2.0.2', '2.1.2', '2.2.2', '2.3.3', '2.3.4', '2.3.5', '2.3.6', '2.3.9']
|
13
|
-
|
14
|
-
rails_versions.each do |v|
|
15
|
-
g = Ginger::Scenario.new("Rails #{v}")
|
16
|
-
g['rails'] = v
|
17
|
-
config.scenarios << g.dup
|
18
|
-
end
|
19
|
-
end
|
data/spec/parser_spec.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe ValidatesTimeliness::Parser do
|
4
|
-
attr_accessor :person
|
5
|
-
|
6
|
-
describe "parse" do
|
7
|
-
it "should return time object for valid time string" do
|
8
|
-
parse("2000-01-01 12:13:14", :datetime).should be_kind_of(Time)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should return Time object for ISO 8601 string with time zone" do
|
12
|
-
parse("2000-01-01T12:23:42+09:00", :datetime).should be_kind_of(Time)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should return nil for time string with invalid date part" do
|
16
|
-
parse("2000-02-30 12:13:14", :datetime).should be_nil
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should return nil for time string with invalid time part" do
|
20
|
-
parse("2000-02-01 25:13:14", :datetime).should be_nil
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should return Time object when passed a Time object" do
|
24
|
-
parse(Time.now, :datetime).should be_kind_of(Time)
|
25
|
-
end
|
26
|
-
|
27
|
-
if RAILS_VER >= '2.1'
|
28
|
-
it "should convert time string into current timezone" do
|
29
|
-
Time.zone = 'Melbourne'
|
30
|
-
time = parse("2000-06-01 12:13:14", :datetime)
|
31
|
-
time.utc_offset.should == 10.hours
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should return nil for invalid date string" do
|
36
|
-
parse("2000-02-30", :date).should be_nil
|
37
|
-
end
|
38
|
-
|
39
|
-
def parse(*args)
|
40
|
-
ValidatesTimeliness::Parser.parse(*args)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "make_time" do
|
45
|
-
|
46
|
-
if RAILS_VER >= '2.1'
|
47
|
-
|
48
|
-
it "should create time using current timezone" do
|
49
|
-
Time.zone = 'Melbourne'
|
50
|
-
time = ValidatesTimeliness::Parser.make_time([2000,1,1,12,0,0])
|
51
|
-
time.zone.should == "EST"
|
52
|
-
end
|
53
|
-
|
54
|
-
else
|
55
|
-
|
56
|
-
it "should create time using default timezone" do
|
57
|
-
time = ValidatesTimeliness::Parser.make_time([2000,1,1,12,0,0])
|
58
|
-
time.zone.should == "UTC"
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
data/spec/resources/person.rb
DELETED
data/spec/resources/schema.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# patches adapter in rails 2.0 which mistakenly made time attributes map to datetime column type
|
2
|
-
ActiveRecord::ConnectionAdapters::SQLiteAdapter.class_eval do
|
3
|
-
def native_database_types #:nodoc:
|
4
|
-
{
|
5
|
-
:primary_key => default_primary_key_type,
|
6
|
-
:string => { :name => "varchar", :limit => 255 },
|
7
|
-
:text => { :name => "text" },
|
8
|
-
:integer => { :name => "integer" },
|
9
|
-
:float => { :name => "float" },
|
10
|
-
:decimal => { :name => "decimal" },
|
11
|
-
:datetime => { :name => "datetime" },
|
12
|
-
:timestamp => { :name => "datetime" },
|
13
|
-
:time => { :name => "time" },
|
14
|
-
:date => { :name => "date" },
|
15
|
-
:binary => { :name => "blob" },
|
16
|
-
:boolean => { :name => "boolean" }
|
17
|
-
}
|
18
|
-
end
|
19
|
-
end
|
@@ -1,245 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
-
require 'validates_timeliness/matcher'
|
3
|
-
|
4
|
-
class NoValidation < Person
|
5
|
-
end
|
6
|
-
|
7
|
-
class WithValidation < Person
|
8
|
-
validates_date :birth_date,
|
9
|
-
:is_at => '2000-01-01',
|
10
|
-
:before => '2000-01-10',
|
11
|
-
:after => '2000-01-01',
|
12
|
-
:on_or_before => '2000-01-09',
|
13
|
-
:on_or_after => '2000-01-02',
|
14
|
-
:between => ['2000-01-01', '2000-01-03']
|
15
|
-
|
16
|
-
validates_time :birth_time,
|
17
|
-
:is_at => '09:00',
|
18
|
-
:before => '23:00',
|
19
|
-
:after => '09:00',
|
20
|
-
:on_or_before => '22:00',
|
21
|
-
:on_or_after => '10:00',
|
22
|
-
:between => ['09:00', '17:00']
|
23
|
-
|
24
|
-
validates_datetime :birth_date_and_time,
|
25
|
-
:is_at => '2000-01-01 09:00',
|
26
|
-
:before => '2000-01-10 23:00',
|
27
|
-
:after => '2000-01-01 09:00',
|
28
|
-
:on_or_before => '2000-01-09 23:00',
|
29
|
-
:on_or_after => '2000-01-02 09:00',
|
30
|
-
:between => ['2000-01-01 09:00', '2000-01-01 17:00']
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
class CustomMessages < Person
|
35
|
-
validates_date :birth_date,
|
36
|
-
:invalid_date_message => 'is not really a date',
|
37
|
-
:before => '2000-01-10',
|
38
|
-
:before_message => 'is too late',
|
39
|
-
:after => '2000-01-01',
|
40
|
-
:after_message => 'is too early',
|
41
|
-
:on_or_before => '2000-01-09',
|
42
|
-
:on_or_before_message => 'is just too late',
|
43
|
-
:on_or_after => '2000-01-02',
|
44
|
-
:on_or_after_message => 'is just too early'
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "ValidateTimeliness matcher" do
|
48
|
-
attr_accessor :no_validation, :with_validation
|
49
|
-
|
50
|
-
@@attribute_for_type = { :date => :birth_date, :time => :birth_time, :datetime => :birth_date_and_time }
|
51
|
-
|
52
|
-
before do
|
53
|
-
@no_validation = NoValidation.new
|
54
|
-
@with_validation = WithValidation.new
|
55
|
-
end
|
56
|
-
|
57
|
-
[:date, :time, :datetime].each do |type|
|
58
|
-
|
59
|
-
it "should report that #{type} is validated" do
|
60
|
-
with_validation.should self.send("validate_#{type}", attribute_for_type(type))
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should report that #{type} is not validated" do
|
64
|
-
no_validation.should_not self.send("validate_#{type}", attribute_for_type(type))
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "with is_at option" do
|
69
|
-
test_values = {
|
70
|
-
:date => ['2000-01-01', '2000-01-02'],
|
71
|
-
:time => ['09:00', '09:01'],
|
72
|
-
:datetime => ['2000-01-01 09:00', '2000-01-01 09:01']
|
73
|
-
}
|
74
|
-
|
75
|
-
[:date, :time, :datetime].each do |type|
|
76
|
-
|
77
|
-
it "should report that #{type} is validated" do
|
78
|
-
with_validation.should self.send("validate_#{type}", attribute_for_type(type), :is_at => test_values[type][0])
|
79
|
-
end
|
80
|
-
|
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), :is_at => test_values[type][1])
|
83
|
-
end
|
84
|
-
|
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), :is_at => test_values[type][0])
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "with before option" do
|
92
|
-
test_values = {
|
93
|
-
:date => ['2000-01-10', '2000-01-11'],
|
94
|
-
:time => ['23:00', '22:59'],
|
95
|
-
:datetime => ['2000-01-10 23:00', '2000-01-10 22:59']
|
96
|
-
}
|
97
|
-
|
98
|
-
[:date, :time, :datetime].each do |type|
|
99
|
-
|
100
|
-
it "should report that #{type} is validated" do
|
101
|
-
with_validation.should self.send("validate_#{type}", attribute_for_type(type), :before => test_values[type][0])
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should report that #{type} is not validated when option value is incorrect" do
|
105
|
-
with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :before => test_values[type][1])
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should report that #{type} is not validated with option" do
|
109
|
-
no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :before => test_values[type][0])
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe "with after option" do
|
115
|
-
test_values = {
|
116
|
-
:date => ['2000-01-01', '2000-01-02'],
|
117
|
-
:time => ['09:00', '09:01'],
|
118
|
-
:datetime => ['2000-01-01 09:00', '2000-01-01 09:01']
|
119
|
-
}
|
120
|
-
|
121
|
-
[:date, :time, :datetime].each do |type|
|
122
|
-
|
123
|
-
it "should report that #{type} is validated" do
|
124
|
-
with_validation.should self.send("validate_#{type}", attribute_for_type(type), :after => test_values[type][0])
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should report that #{type} is not validated when option value is incorrect" do
|
128
|
-
with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :after => test_values[type][1])
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should report that #{type} is not validated with option" do
|
132
|
-
no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :after => test_values[type][0])
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe "with on_or_before option" do
|
138
|
-
test_values = {
|
139
|
-
:date => ['2000-01-09', '2000-01-08'],
|
140
|
-
:time => ['22:00', '21:59'],
|
141
|
-
:datetime => ['2000-01-09 23:00', '2000-01-09 22:59']
|
142
|
-
}
|
143
|
-
|
144
|
-
[:date, :time, :datetime].each do |type|
|
145
|
-
|
146
|
-
it "should report that #{type} is validated" do
|
147
|
-
with_validation.should self.send("validate_#{type}", attribute_for_type(type), :on_or_before => test_values[type][0])
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should report that #{type} is not validated when option value is incorrect" do
|
151
|
-
with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :on_or_before => test_values[type][1])
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should report that #{type} is not validated with option" do
|
155
|
-
no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :on_or_before => test_values[type][0])
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe "with on_or_after option" do
|
161
|
-
test_values = {
|
162
|
-
:date => ['2000-01-02', '2000-01-03'],
|
163
|
-
:time => ['10:00', '10:01'],
|
164
|
-
:datetime => ['2000-01-02 09:00', '2000-01-02 09:01']
|
165
|
-
}
|
166
|
-
|
167
|
-
[:date, :time, :datetime].each do |type|
|
168
|
-
|
169
|
-
it "should report that #{type} is validated" do
|
170
|
-
with_validation.should self.send("validate_#{type}", attribute_for_type(type), :on_or_after => test_values[type][0])
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should report that #{type} is not validated when option value is incorrect" do
|
174
|
-
with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :on_or_after => test_values[type][1])
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should report that #{type} is not validated with option" do
|
178
|
-
no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :on_or_after => test_values[type][0])
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
describe "between option" do
|
184
|
-
test_values = {
|
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'] ]
|
188
|
-
}
|
189
|
-
|
190
|
-
[:date, :time, :datetime].each do |type|
|
191
|
-
|
192
|
-
it "should report that #{type} is validated" do
|
193
|
-
with_validation.should self.send("validate_#{type}", attribute_for_type(type), :between => test_values[type][0])
|
194
|
-
end
|
195
|
-
|
196
|
-
it "should report that #{type} is not validated when option value is incorrect" do
|
197
|
-
with_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :between => test_values[type][1])
|
198
|
-
end
|
199
|
-
|
200
|
-
it "should report that #{type} is not validated with option" do
|
201
|
-
no_validation.should_not self.send("validate_#{type}", attribute_for_type(type), :between => test_values[type][0])
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
describe "custom messages" do
|
207
|
-
|
208
|
-
before do
|
209
|
-
@person = CustomMessages.new
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should match error message for invalid" do
|
213
|
-
@person.should validate_date(:birth_date, :invalid_date_message => 'is not really a date')
|
214
|
-
end
|
215
|
-
|
216
|
-
it "should match error message for before option" do
|
217
|
-
@person.should validate_date(:birth_date, :before => '2000-01-10',
|
218
|
-
:invalid_date_message => 'is not really a date',
|
219
|
-
:before_message => 'is too late')
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should match error message for after option" do
|
223
|
-
@person.should validate_date(:birth_date, :after => '2000-01-01',
|
224
|
-
:invalid_date_message => 'is not really a date',
|
225
|
-
:after_message => 'is too early')
|
226
|
-
end
|
227
|
-
|
228
|
-
it "should match error message for on_or_before option" do
|
229
|
-
@person.should validate_date(:birth_date, :on_or_before => '2000-01-09',
|
230
|
-
:invalid_date_message => 'is not really a date',
|
231
|
-
:on_or_before_message => 'is just too late')
|
232
|
-
end
|
233
|
-
|
234
|
-
it "should match error message for on_or_after option" do
|
235
|
-
@person.should validate_date(:birth_date, :on_or_after => '2000-01-02',
|
236
|
-
:invalid_date_message => 'is not really a date',
|
237
|
-
:on_or_after_message => 'is just too early')
|
238
|
-
end
|
239
|
-
|
240
|
-
end
|
241
|
-
|
242
|
-
def attribute_for_type(type)
|
243
|
-
@@attribute_for_type[type.to_sym]
|
244
|
-
end
|
245
|
-
end
|