mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 06:16:44 +00:00
tightened up specs for attribute methods
This commit is contained in:
parent
1269d794d0
commit
7fadc2c164
@ -30,7 +30,7 @@ module ValidatesTimeliness
|
|||||||
# checks if date is valid which enforces number of days in a month unlike Time
|
# checks if date is valid which enforces number of days in a month unlike Time
|
||||||
Date.new(*time_array[0..2])
|
Date.new(*time_array[0..2])
|
||||||
|
|
||||||
# checks if time is valid and return object
|
# checks if time part is valid and returns object
|
||||||
Time.mktime(*time_array)
|
Time.mktime(*time_array)
|
||||||
rescue
|
rescue
|
||||||
nil
|
nil
|
||||||
|
|||||||
@ -8,30 +8,33 @@ describe ValidatesTimeliness::AttributeMethods do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should return string value for attribute_before_type_cast when written as string" do
|
it "should return string value for attribute_before_type_cast when written as string" do
|
||||||
@person.birth_date_and_time = "1980-12-25 01:02:03"
|
time_string = "2000-06-01 01:02:03"
|
||||||
@person.birth_date_and_time_before_type_cast.should == "1980-12-25 01:02:03"
|
@person.birth_date_and_time = time_string
|
||||||
|
@person.birth_date_and_time_before_type_cast.should == time_string
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return Time object for attribute_before_type_cast when written as Time" do
|
it "should return Time object for attribute_before_type_cast when written as Time" do
|
||||||
@person.birth_date_and_time = Time.mktime(1980, 12, 25, 1, 2, 3)
|
@person.birth_date_and_time = Time.mktime(2000, 06, 01, 1, 2, 3)
|
||||||
@person.birth_date_and_time_before_type_cast.should be_kind_of(Time)
|
@person.birth_date_and_time_before_type_cast.should be_kind_of(Time)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return Time object using attribute read method when written with string" do
|
it "should return Time object using attribute read method when written with string" do
|
||||||
@person.birth_date_and_time = "1980-12-25 01:02:03"
|
@person.birth_date_and_time = "2000-06-01 01:02:03"
|
||||||
@person.birth_date_and_time.should be_kind_of(Time)
|
@person.birth_date_and_time.should be_kind_of(Time)
|
||||||
end
|
end
|
||||||
|
|
||||||
unless Rails::VERSION::STRING <= '2.0.2'
|
unless Rails::VERSION::STRING <= '2.0.2'
|
||||||
it "should return stored time string as Time with correct timezone" do
|
it "should return stored time string as Time with correct timezone" do
|
||||||
Time.zone = TimeZone['Sydney'] # no I'm not from Sydney but there is no Melbourne timezone!
|
Time.zone = TimeZone['Melbourne']
|
||||||
@person.birth_date_and_time = "1980-12-25 01:02:03"
|
time_string = "2000-06-01 01:02:03"
|
||||||
@person.birth_date_and_time.zone == Time.zone
|
@person.birth_date_and_time = time_string
|
||||||
|
@person.birth_date_and_time.utc_offset.should == 10.hours
|
||||||
|
@person.birth_date_and_time.strftime('%Y-%m-%d %H:%M:%S').should == time_string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return nil when time is invalid" do
|
it "should return nil when time is invalid" do
|
||||||
@person.birth_date_and_time = "1980-02-30 01:02:03"
|
@person.birth_date_and_time = "2000-02-30 01:02:03"
|
||||||
@person.birth_date_and_time.should be_nil
|
@person.birth_date_and_time.should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user