mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
added strict_time_type_cast method to handle casting
refactored to be simler and rely on read_atribute method conversion rather than use new reader method definer got time (Rails 2.1)
This commit is contained in:
@@ -33,6 +33,9 @@ describe ValidatesTimeliness::AttributeMethods do
|
||||
end
|
||||
end
|
||||
|
||||
# This fails running as plugin under vendor using Rails 2.1RC
|
||||
# due to write_attribute_with_dirty ignoring the write method for time zone
|
||||
# method. But invalid dates do return nil when running app.
|
||||
it "should return nil when time is invalid" do
|
||||
@person.birth_date_and_time = "2000-02-30 01:02:03"
|
||||
@person.birth_date_and_time.should be_nil
|
||||
|
||||
@@ -34,4 +34,38 @@ describe ValidatesTimeliness::Base do
|
||||
execute_callstack_for_multiparameter_attributes(callstack)
|
||||
end
|
||||
end
|
||||
|
||||
describe "strict_time_type_cast" do
|
||||
it "should return time object for valid time string" do
|
||||
strict_time_type_cast("2000-01-01 12:13:14").should be_kind_of(Time)
|
||||
end
|
||||
|
||||
it "should return nil for time string with invalid date part" do
|
||||
strict_time_type_cast("2000-02-30 12:13:14").should be_nil
|
||||
end
|
||||
|
||||
it "should return nil for time string with invalid time part" do
|
||||
strict_time_type_cast("2000-02-01 25:13:14").should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "read_attribute" do
|
||||
it "should return time object from time string" do
|
||||
@attributes = {}
|
||||
self.stub!(:column_for_attribute).and_return( mock('Column', :klass => Time) )
|
||||
self.stub!(:unserializable_attribute?).and_return(false)
|
||||
|
||||
@attributes['birth_date_and_time'] = "1980-01-01 00:00:00"
|
||||
read_attribute(:birth_date_and_time).should be_kind_of(Time)
|
||||
end
|
||||
|
||||
it "should return nil from invalid time string" do
|
||||
@attributes = {}
|
||||
self.stub!(:column_for_attribute).and_return( mock('Column', :klass => Time) )
|
||||
self.stub!(:unserializable_attribute?).and_return(false)
|
||||
|
||||
@attributes['birth_date_and_time'] = "1980-02-30 00:00:00"
|
||||
read_attribute(:birth_date_and_time).should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user