markos_validates_timeliness 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +121 -0
- data/LICENSE +20 -0
- data/README.rdoc +402 -0
- data/Rakefile +52 -0
- data/TODO +8 -0
- data/lib/validates_timeliness/action_view/instance_tag.rb +52 -0
- data/lib/validates_timeliness/active_record/attribute_methods.rb +77 -0
- data/lib/validates_timeliness/active_record/multiparameter_attributes.rb +69 -0
- data/lib/validates_timeliness/formats.rb +368 -0
- data/lib/validates_timeliness/locale/en.new.yml +18 -0
- data/lib/validates_timeliness/locale/en.old.yml +18 -0
- data/lib/validates_timeliness/matcher.rb +1 -0
- data/lib/validates_timeliness/parser.rb +44 -0
- data/lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb +162 -0
- data/lib/validates_timeliness/validation_methods.rb +46 -0
- data/lib/validates_timeliness/validator.rb +230 -0
- data/lib/validates_timeliness/version.rb +3 -0
- data/lib/validates_timeliness.rb +59 -0
- data/spec/action_view/instance_tag_spec.rb +194 -0
- data/spec/active_record/attribute_methods_spec.rb +157 -0
- data/spec/active_record/multiparameter_attributes_spec.rb +118 -0
- data/spec/formats_spec.rb +313 -0
- data/spec/ginger_scenarios.rb +19 -0
- data/spec/parser_spec.rb +65 -0
- data/spec/resources/application.rb +2 -0
- data/spec/resources/person.rb +3 -0
- data/spec/resources/schema.rb +10 -0
- data/spec/resources/sqlite_patch.rb +19 -0
- data/spec/spec/rails/matchers/validate_timeliness_spec.rb +245 -0
- data/spec/spec_helper.rb +58 -0
- data/spec/time_travel/MIT-LICENSE +20 -0
- data/spec/time_travel/time_extensions.rb +33 -0
- data/spec/time_travel/time_travel.rb +12 -0
- data/spec/validator_spec.rb +723 -0
- metadata +104 -0
@@ -0,0 +1,194 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe 'ValidatesTimeliness::ActionView::InstanceTag' do
|
4
|
+
include ActionView::Helpers::DateHelper
|
5
|
+
include ActionController::Assertions::SelectorAssertions
|
6
|
+
|
7
|
+
before do
|
8
|
+
@person = Person.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def params
|
12
|
+
@params ||= {}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "datetime_select" do
|
16
|
+
it "should use param values when attribute is nil" do
|
17
|
+
params["person"] = {
|
18
|
+
"birth_date_and_time(1i)" => 2009,
|
19
|
+
"birth_date_and_time(2i)" => 2,
|
20
|
+
"birth_date_and_time(3i)" => 29,
|
21
|
+
"birth_date_and_time(4i)" => 12,
|
22
|
+
"birth_date_and_time(5i)" => 13,
|
23
|
+
"birth_date_and_time(6i)" => 14,
|
24
|
+
}
|
25
|
+
@person.birth_date_and_time = nil
|
26
|
+
output = datetime_select(:person, :birth_date_and_time, :include_blank => true, :include_seconds => true)
|
27
|
+
output.should have_tag('select[id=person_birth_date_and_time_1i] option[selected=selected]', '2009')
|
28
|
+
output.should have_tag('select[id=person_birth_date_and_time_2i] option[selected=selected]', 'February')
|
29
|
+
output.should have_tag('select[id=person_birth_date_and_time_3i] option[selected=selected]', '29')
|
30
|
+
output.should have_tag('select[id=person_birth_date_and_time_4i] option[selected=selected]', '12')
|
31
|
+
output.should have_tag('select[id=person_birth_date_and_time_5i] option[selected=selected]', '13')
|
32
|
+
output.should have_tag('select[id=person_birth_date_and_time_6i] option[selected=selected]', '14')
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should override object values and use params if present" do
|
36
|
+
params["person"] = {
|
37
|
+
"birth_date_and_time(1i)" => 2009,
|
38
|
+
"birth_date_and_time(2i)" => 2,
|
39
|
+
"birth_date_and_time(3i)" => 29,
|
40
|
+
"birth_date_and_time(4i)" => 13,
|
41
|
+
"birth_date_and_time(5i)" => 14,
|
42
|
+
"birth_date_and_time(6i)" => 15,
|
43
|
+
}
|
44
|
+
@person.birth_date_and_time = "2009-03-01 13:14:15"
|
45
|
+
output = datetime_select(:person, :birth_date_and_time, :include_blank => true, :include_seconds => true)
|
46
|
+
output.should have_tag('select[id=person_birth_date_and_time_1i] option[selected=selected]', '2009')
|
47
|
+
output.should have_tag('select[id=person_birth_date_and_time_2i] option[selected=selected]', 'February')
|
48
|
+
output.should have_tag('select[id=person_birth_date_and_time_3i] option[selected=selected]', '29')
|
49
|
+
output.should have_tag('select[id=person_birth_date_and_time_4i] option[selected=selected]', '13')
|
50
|
+
output.should have_tag('select[id=person_birth_date_and_time_5i] option[selected=selected]', '14')
|
51
|
+
output.should have_tag('select[id=person_birth_date_and_time_6i] option[selected=selected]', '15')
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should select attribute values from object if no params" do
|
55
|
+
@person.birth_date_and_time = "2009-01-02 13:14:15"
|
56
|
+
output = datetime_select(:person, :birth_date_and_time, :include_blank => true, :include_seconds => true)
|
57
|
+
output.should have_tag('select[id=person_birth_date_and_time_1i] option[selected=selected]', '2009')
|
58
|
+
output.should have_tag('select[id=person_birth_date_and_time_2i] option[selected=selected]', 'January')
|
59
|
+
output.should have_tag('select[id=person_birth_date_and_time_3i] option[selected=selected]', '2')
|
60
|
+
output.should have_tag('select[id=person_birth_date_and_time_4i] option[selected=selected]', '13')
|
61
|
+
output.should have_tag('select[id=person_birth_date_and_time_5i] option[selected=selected]', '14')
|
62
|
+
output.should have_tag('select[id=person_birth_date_and_time_6i] option[selected=selected]', '15')
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should select attribute values if params does not contain attribute params" do
|
66
|
+
@person.birth_date_and_time = "2009-01-02 13:14:15"
|
67
|
+
params["person"] = { }
|
68
|
+
output = datetime_select(:person, :birth_date_and_time, :include_blank => true, :include_seconds => true)
|
69
|
+
output.should have_tag('select[id=person_birth_date_and_time_1i] option[selected=selected]', '2009')
|
70
|
+
output.should have_tag('select[id=person_birth_date_and_time_2i] option[selected=selected]', 'January')
|
71
|
+
output.should have_tag('select[id=person_birth_date_and_time_3i] option[selected=selected]', '2')
|
72
|
+
output.should have_tag('select[id=person_birth_date_and_time_4i] option[selected=selected]', '13')
|
73
|
+
output.should have_tag('select[id=person_birth_date_and_time_5i] option[selected=selected]', '14')
|
74
|
+
output.should have_tag('select[id=person_birth_date_and_time_6i] option[selected=selected]', '15')
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should not select values when attribute value is nil and has no param values" do
|
78
|
+
@person.birth_date_and_time = nil
|
79
|
+
output = datetime_select(:person, :birth_date_and_time, :include_blank => true, :include_seconds => true)
|
80
|
+
output.should_not have_tag('select[id=person_birth_date_and_time_1i] option[selected=selected]')
|
81
|
+
output.should_not have_tag('select[id=person_birth_date_and_time_2i] option[selected=selected]')
|
82
|
+
output.should_not have_tag('select[id=person_birth_date_and_time_3i] option[selected=selected]')
|
83
|
+
output.should_not have_tag('select[id=person_birth_date_and_time_4i] option[selected=selected]')
|
84
|
+
output.should_not have_tag('select[id=person_birth_date_and_time_5i] option[selected=selected]')
|
85
|
+
output.should_not have_tag('select[id=person_birth_date_and_time_6i] option[selected=selected]')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "date_select" do
|
90
|
+
it "should use param values when attribute is nil" do
|
91
|
+
params["person"] = {
|
92
|
+
"birth_date(1i)" => 2009,
|
93
|
+
"birth_date(2i)" => 2,
|
94
|
+
"birth_date(3i)" => 29,
|
95
|
+
}
|
96
|
+
@person.birth_date = nil
|
97
|
+
output = date_select(:person, :birth_date, :include_blank => true, :include_seconds => true)
|
98
|
+
output.should have_tag('select[id=person_birth_date_1i] option[selected=selected]', '2009')
|
99
|
+
output.should have_tag('select[id=person_birth_date_2i] option[selected=selected]', 'February')
|
100
|
+
output.should have_tag('select[id=person_birth_date_3i] option[selected=selected]', '29')
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should override object values and use params if present" do
|
104
|
+
params["person"] = {
|
105
|
+
"birth_date(1i)" => 2009,
|
106
|
+
"birth_date(2i)" => 2,
|
107
|
+
"birth_date(3i)" => 29,
|
108
|
+
}
|
109
|
+
@person.birth_date = "2009-03-01"
|
110
|
+
output = date_select(:person, :birth_date, :include_blank => true, :include_seconds => true)
|
111
|
+
output.should have_tag('select[id=person_birth_date_1i] option[selected=selected]', '2009')
|
112
|
+
output.should have_tag('select[id=person_birth_date_2i] option[selected=selected]', 'February')
|
113
|
+
output.should have_tag('select[id=person_birth_date_3i] option[selected=selected]', '29')
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should select attribute values from object if no params" do
|
117
|
+
@person.birth_date = "2009-01-02"
|
118
|
+
output = date_select(:person, :birth_date, :include_blank => true, :include_seconds => true)
|
119
|
+
output.should have_tag('select[id=person_birth_date_1i] option[selected=selected]', '2009')
|
120
|
+
output.should have_tag('select[id=person_birth_date_2i] option[selected=selected]', 'January')
|
121
|
+
output.should have_tag('select[id=person_birth_date_3i] option[selected=selected]', '2')
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should select attribute values if params does not contain attribute params" do
|
125
|
+
@person.birth_date = "2009-01-02"
|
126
|
+
params["person"] = { }
|
127
|
+
output = date_select(:person, :birth_date, :include_blank => true, :include_seconds => true)
|
128
|
+
output.should have_tag('select[id=person_birth_date_1i] option[selected=selected]', '2009')
|
129
|
+
output.should have_tag('select[id=person_birth_date_2i] option[selected=selected]', 'January')
|
130
|
+
output.should have_tag('select[id=person_birth_date_3i] option[selected=selected]', '2')
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should not select values when attribute value is nil and has no param values" do
|
134
|
+
@person.birth_date = nil
|
135
|
+
output = date_select(:person, :birth_date, :include_blank => true, :include_seconds => true)
|
136
|
+
output.should_not have_tag('select[id=person_birth_date_1i] option[selected=selected]')
|
137
|
+
output.should_not have_tag('select[id=person_birth_date_2i] option[selected=selected]')
|
138
|
+
output.should_not have_tag('select[id=person_birth_date_3i] option[selected=selected]')
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "time_select" do
|
143
|
+
before :all do
|
144
|
+
Time.now = Time.mktime(2009,1,1)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should use param values when attribute is nil" do
|
148
|
+
params["person"] = {
|
149
|
+
"birth_time(1i)" => 2000,
|
150
|
+
"birth_time(2i)" => 1,
|
151
|
+
"birth_time(3i)" => 1,
|
152
|
+
"birth_time(4i)" => 12,
|
153
|
+
"birth_time(5i)" => 13,
|
154
|
+
"birth_time(6i)" => 14,
|
155
|
+
}
|
156
|
+
@person.birth_time = nil
|
157
|
+
output = time_select(:person, :birth_time, :include_blank => true, :include_seconds => true)
|
158
|
+
output.should have_tag('input[id=person_birth_time_1i][value=2000]')
|
159
|
+
output.should have_tag('input[id=person_birth_time_2i][value=1]')
|
160
|
+
output.should have_tag('input[id=person_birth_time_3i][value=1]')
|
161
|
+
output.should have_tag('select[id=person_birth_time_4i] option[selected=selected]', '12')
|
162
|
+
output.should have_tag('select[id=person_birth_time_5i] option[selected=selected]', '13')
|
163
|
+
output.should have_tag('select[id=person_birth_time_6i] option[selected=selected]', '14')
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should select attribute values from object if no params" do
|
167
|
+
@person.birth_time = "13:14:15"
|
168
|
+
output = time_select(:person, :birth_time, :include_blank => true, :include_seconds => true)
|
169
|
+
output.should have_tag('input[id=person_birth_time_1i][value=2000]')
|
170
|
+
output.should have_tag('input[id=person_birth_time_2i][value=1]')
|
171
|
+
output.should have_tag('input[id=person_birth_time_3i][value=1]')
|
172
|
+
output.should have_tag('select[id=person_birth_time_4i] option[selected=selected]', '13')
|
173
|
+
output.should have_tag('select[id=person_birth_time_5i] option[selected=selected]', '14')
|
174
|
+
output.should have_tag('select[id=person_birth_time_6i] option[selected=selected]', '15')
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should not select values when attribute value is nil and has no param values" do
|
178
|
+
@person.birth_time = nil
|
179
|
+
output = time_select(:person, :birth_time, :include_blank => true, :include_seconds => true)
|
180
|
+
output.should have_tag('input[id=person_birth_time_1i][value=""]')
|
181
|
+
# Annoyingly these may or not have value attribute depending on rails version.
|
182
|
+
# output.should have_tag('input[id=person_birth_time_2i][value=""]')
|
183
|
+
# output.should have_tag('input[id=person_birth_time_3i][value=""]')
|
184
|
+
output.should_not have_tag('select[id=person_birth_time_4i] option[selected=selected]')
|
185
|
+
output.should_not have_tag('select[id=person_birth_time_5i] option[selected=selected]')
|
186
|
+
output.should_not have_tag('select[id=person_birth_time_6i] option[selected=selected]')
|
187
|
+
end
|
188
|
+
|
189
|
+
after :all do
|
190
|
+
Time.now = nil
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
|
4
|
+
before do
|
5
|
+
@person = Person.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should define and call write method on first assign" do
|
9
|
+
Person.class_eval { @generated_methods = Set.new; @_defined_class_methods = nil }
|
10
|
+
Person.send(:undef_method, :birth_date=) if Person.instance_methods.include?('birth_date=')
|
11
|
+
person = Person.new
|
12
|
+
person.should_receive(:write_date_time_attribute)
|
13
|
+
person.birth_date = "2000-01-01"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should call write_date_time_attribute when time attribute assigned value" do
|
17
|
+
@person.should_receive(:write_date_time_attribute)
|
18
|
+
@person.birth_time = "12:00"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should call write_date_time_attribute when datetime attribute assigned value" do
|
22
|
+
@person.should_receive(:write_date_time_attribute)
|
23
|
+
@person.birth_date_and_time = "2000-01-01 12:00"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should call parser on write for datetime attribute" do
|
27
|
+
ValidatesTimeliness::Parser.should_receive(:parse).once
|
28
|
+
@person.birth_date_and_time = "2000-01-01 02:03:04"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should call parser on write for date attribute" do
|
32
|
+
ValidatesTimeliness::Parser.should_receive(:parse).once
|
33
|
+
@person.birth_date = "2000-01-01"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should call parser on write for time attribute" do
|
37
|
+
ValidatesTimeliness::Parser.should_receive(:parse).once
|
38
|
+
@person.birth_time = "12:00"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return raw string value for attribute_before_type_cast when written as string" do
|
42
|
+
time_string = "2000-01-01 02:03:04"
|
43
|
+
@person.birth_date_and_time = time_string
|
44
|
+
@person.birth_date_and_time_before_type_cast.should == time_string
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return Time object for attribute_before_type_cast when written as Time" do
|
48
|
+
@person.birth_date_and_time = Time.mktime(2000, 1, 1, 2, 3, 4)
|
49
|
+
@person.birth_date_and_time_before_type_cast.should be_kind_of(Time)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return Time object for datetime attribute read method when assigned Time object" do
|
53
|
+
@person.birth_date_and_time = Time.now
|
54
|
+
@person.birth_date_and_time.should be_kind_of(Time)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return Time object for datetime attribute read method when assigned Date object" do
|
58
|
+
@person.birth_date_and_time = Date.today
|
59
|
+
@person.birth_date_and_time.should be_kind_of(Time)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return Time object for datetime attribute read method when assigned string" do
|
63
|
+
@person.birth_date_and_time = "2000-01-01 02:03:04"
|
64
|
+
@person.birth_date_and_time.should be_kind_of(Time)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return Date object for date attribute read method when assigned Date object" do
|
68
|
+
@person.birth_date = Date.today
|
69
|
+
@person.birth_date.should be_kind_of(Date)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return Date object for date attribute read method when assigned string" do
|
73
|
+
@person.birth_date = '2000-01-01'
|
74
|
+
@person.birth_date.should be_kind_of(Date)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return nil when time is invalid" do
|
78
|
+
@person.birth_date_and_time = "2000-01-32 02:03:04"
|
79
|
+
@person.birth_date_and_time.should be_nil
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should not save invalid date value to database" do
|
83
|
+
time_string = "2000-01-32 02:03:04"
|
84
|
+
@person.birth_date_and_time = time_string
|
85
|
+
@person.save
|
86
|
+
@person.reload
|
87
|
+
@person.birth_date_and_time_before_type_cast.should be_nil
|
88
|
+
end
|
89
|
+
|
90
|
+
if RAILS_VER < '2.1'
|
91
|
+
|
92
|
+
it "should return time object from database in default timezone" do
|
93
|
+
ActiveRecord::Base.default_timezone = :utc
|
94
|
+
time_string = "2000-01-01 09:00:00"
|
95
|
+
@person.birth_date_and_time = time_string
|
96
|
+
@person.save
|
97
|
+
@person.reload
|
98
|
+
@person.birth_date_and_time.strftime('%Y-%m-%d %H:%M:%S %Z').should == time_string + ' UTC'
|
99
|
+
end
|
100
|
+
|
101
|
+
else
|
102
|
+
|
103
|
+
it "should return stored time string as Time with correct timezone" do
|
104
|
+
Time.zone = 'Melbourne'
|
105
|
+
time_string = "2000-06-01 02:03:04"
|
106
|
+
@person.birth_date_and_time = time_string
|
107
|
+
@person.birth_date_and_time.strftime('%Y-%m-%d %H:%M:%S %Z %z').should == time_string + ' EST +1000'
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should return time object from database in correct timezone" do
|
111
|
+
Time.zone = 'Melbourne'
|
112
|
+
time_string = "2000-06-01 09:00:00"
|
113
|
+
@person.birth_date_and_time = time_string
|
114
|
+
@person.save
|
115
|
+
@person.reload
|
116
|
+
@person.birth_date_and_time.strftime('%Y-%m-%d %H:%M:%S %Z %z').should == time_string + ' EST +1000'
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should return correct date value after new value assigned" do
|
122
|
+
today = Date.today
|
123
|
+
tomorrow = Date.today + 1.day
|
124
|
+
@person.birth_date = today
|
125
|
+
@person.birth_date.should == today
|
126
|
+
@person.birth_date = tomorrow
|
127
|
+
@person.birth_date.should == tomorrow
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should update date attribute on existing object" do
|
131
|
+
today = Date.today
|
132
|
+
tomorrow = Date.today + 1.day
|
133
|
+
person = Person.create(:birth_date => today)
|
134
|
+
person.birth_date = tomorrow
|
135
|
+
person.save!
|
136
|
+
person.reload
|
137
|
+
person.birth_date.should == tomorrow
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "attribute writer" do
|
141
|
+
|
142
|
+
it "should be able to be overridden in class" do
|
143
|
+
Person.class_eval { attr_accessor :birth_date }
|
144
|
+
person = Person.new
|
145
|
+
person.birth_date = 'overriden'
|
146
|
+
person.birth_date.should == 'overriden'
|
147
|
+
end
|
148
|
+
|
149
|
+
after do
|
150
|
+
Person.class_eval do
|
151
|
+
undef_method(:birth_date)
|
152
|
+
undef_method(:birth_date=)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
@@ -0,0 +1,118 @@
|
|
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
|