mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 06:16:44 +00:00
remove setting attribute to nil in validations when invalid to preserve before_type_cast value
This commit is contained in:
parent
037c3ea5c5
commit
8cad1b880e
@ -72,14 +72,12 @@ module ValidatesTimeliness
|
|||||||
column = record.column_for_attribute(attr_name)
|
column = record.column_for_attribute(attr_name)
|
||||||
begin
|
begin
|
||||||
unless time = parse_date_time(raw_value, configuration[:type])
|
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])
|
record.errors.add(attr_name, configuration["invalid_#{configuration[:type]}_message".to_sym])
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
validate_timeliness_restrictions(record, attr_name, time, configuration)
|
validate_timeliness_restrictions(record, attr_name, time, configuration)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
record.send("#{attr_name}=", nil)
|
|
||||||
record.errors.add(attr_name, configuration["invalid_#{configuration[:type]}_message".to_sym])
|
record.errors.add(attr_name, configuration["invalid_#{configuration[:type]}_message".to_sym])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -83,16 +83,20 @@ describe ValidatesTimeliness::Validations do
|
|||||||
person.errors.on(:birth_time).should == "is not a valid time"
|
person.errors.on(:birth_time).should == "is not a valid time"
|
||||||
end
|
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
|
it "should be valid with valid values" do
|
||||||
person.birth_date_and_time = "2000-01-01 12:12:12"
|
person.birth_date_and_time = "2000-01-01 12:12:12"
|
||||||
person.birth_date = "2000-01-31"
|
person.birth_date = "2000-01-31"
|
||||||
person.should be_valid
|
person.should be_valid
|
||||||
end
|
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_and_time = "1890-01-01 12:12:12"
|
||||||
person.birth_date = "1890-01-31"
|
|
||||||
person.birth_time = "23:59:59"
|
|
||||||
person.should be_valid
|
person.should be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user