more date value standardisation

This commit is contained in:
Adam Meehan 2008-07-25 19:19:47 +10:00
parent 24db8ab774
commit 608f3b569f

View File

@ -10,12 +10,12 @@ describe ValidatesTimeliness::AttributeMethods do
it "should call parser on write for datetime attribute" do
@person.class.should_receive(:parse_date_time).once
@person.birth_date_and_time = "2000-06-01 02:03:04"
@person.birth_date_and_time = "2000-01-01 02:03:04"
end
it "should call parser on write for date attribute" do
@person.class.should_receive(:parse_date_time).once
@person.birth_date = "2000-06-01"
@person.birth_date = "2000-01-01"
end
it "should call parser on write for time attribute" do
@ -24,18 +24,18 @@ describe ValidatesTimeliness::AttributeMethods do
end
it "should return raw string value for attribute_before_type_cast when written as string" do
time_string = "2000-06-01 02:03:04"
time_string = "2000-01-01 02:03:04"
@person.birth_date_and_time = time_string
@person.birth_date_and_time_before_type_cast.should == time_string
end
it "should return Time object for attribute_before_type_cast when written as Time" do
@person.birth_date_and_time = Time.mktime(2000, 6, 1, 2, 3, 4)
@person.birth_date_and_time = Time.mktime(2000, 1, 1, 2, 3, 4)
@person.birth_date_and_time_before_type_cast.should be_kind_of(Time)
end
it "should return Time object using attribute read method when written with string" do
@person.birth_date_and_time = "2000-06-01 02:03:04"
@person.birth_date_and_time = "2000-01-01 02:03:04"
@person.birth_date_and_time.should be_kind_of(Time)
end
@ -72,13 +72,13 @@ describe ValidatesTimeliness::AttributeMethods do
end
it "should return true for attribute changed?" do
time_string = "2000-06-01 02:03:04"
time_string = "2000-01-01 02:03:04"
@person.birth_date_and_time = time_string
@person.birth_date_and_time_changed?.should be_true
end
it "should show changes for time attribute as nil to Time object" do
time_string = "2000-06-01 02:03:04"
time_string = "2000-01-01 02:03:04"
@person.birth_date_and_time = time_string
time = @person.birth_date_and_time
@person.changes.should == {"birth_date_and_time" => [nil, time]}
@ -88,7 +88,7 @@ describe ValidatesTimeliness::AttributeMethods do
it "should return time object from database in default timezone" do
ActiveRecord::Base.default_timezone = :utc
time_string = "2000-06-01 09:00:00"
time_string = "2000-01-01 09:00:00"
@person = Person.new
@person.birth_date_and_time = time_string
@person.save
@ -100,7 +100,7 @@ describe ValidatesTimeliness::AttributeMethods do
it "should return same time object on repeat reads" do
Time.zone = 'Melbourne' unless RAILS_VER < '2.1'
time_string = "2000-06-01 09:00:00"
time_string = "2000-01-01 09:00:00"
@person = Person.new
@person.birth_date_and_time = time_string
@person.save