diff --git a/lib/validates_timeliness/validations.rb b/lib/validates_timeliness/validations.rb index 0de9af4..7b4b902 100644 --- a/lib/validates_timeliness/validations.rb +++ b/lib/validates_timeliness/validations.rb @@ -72,14 +72,12 @@ module ValidatesTimeliness column = record.column_for_attribute(attr_name) begin unless time = parse_date_time(raw_value, configuration[:type]) - record.send("#{attr_name}=", nil) record.errors.add(attr_name, configuration["invalid_#{configuration[:type]}_message".to_sym]) next end validate_timeliness_restrictions(record, attr_name, time, configuration) - rescue Exception => e - record.send("#{attr_name}=", nil) + rescue Exception => e record.errors.add(attr_name, configuration["invalid_#{configuration[:type]}_message".to_sym]) end end diff --git a/spec/validations_spec.rb b/spec/validations_spec.rb index 2a79e52..6d2145a 100644 --- a/spec/validations_spec.rb +++ b/spec/validations_spec.rb @@ -83,16 +83,20 @@ describe ValidatesTimeliness::Validations do person.errors.on(:birth_time).should == "is not a valid time" end + it "should have same value for before_type_cast after failed validation" do + person.birth_date_and_time = "2000-01-01 25:02:03" + person.should_not be_valid + person.birth_date_and_time_before_type_cast.should == "2000-01-01 25:02:03" + end + it "should be valid with valid values" do person.birth_date_and_time = "2000-01-01 12:12:12" person.birth_date = "2000-01-31" person.should be_valid end - it "should be valid with values before out of Time range" do + it "should be valid with value out of range for Time class" do person.birth_date_and_time = "1890-01-01 12:12:12" - person.birth_date = "1890-01-31" - person.birth_time = "23:59:59" person.should be_valid end