mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
exit restriction validation when combined :with_time or :with_date value is nil
This commit is contained in:
parent
e711941744
commit
3533ce0702
@ -60,6 +60,7 @@ module ValidatesTimeliness
|
||||
def validate_restrictions(record, attr_name, value)
|
||||
if configuration[:with_time] || configuration[:with_date]
|
||||
value = combine_date_and_time(value, record)
|
||||
return if value.nil?
|
||||
end
|
||||
|
||||
value = self.class.type_cast_value(value, implied_type, configuration[:ignore_usec])
|
||||
|
||||
@ -442,6 +442,12 @@ describe ValidatesTimeliness::Validator do
|
||||
should_have_no_error(:birth_date, :on_or_before)
|
||||
end
|
||||
|
||||
it "should skip restriction validation if :with_time value evaluates to nil" do
|
||||
configure_validator(:type => :date, :with_time => lambda { nil }, :on_or_before => Time.mktime(2000,1,1,12,30))
|
||||
validate_with(:birth_date, "2000-01-01")
|
||||
should_have_no_error(:birth_date, :on_or_before)
|
||||
end
|
||||
|
||||
it "should should ignore usec value on combined value if :ignore_usec option is true" do
|
||||
configure_validator(:type => :date, :with_time => Time.mktime(2000,1,1,12,30,0,500), :is_at => Time.mktime(2000,1,1,12,30), :ignore_usec => true)
|
||||
validate_with(:birth_date, "2000-01-01")
|
||||
@ -463,6 +469,12 @@ describe ValidatesTimeliness::Validator do
|
||||
should_have_no_error(:birth_time, :on_or_before)
|
||||
end
|
||||
|
||||
it "should skip restriction validation if :with_date value is nil" do
|
||||
configure_validator(:type => :time, :with_date => lambda { nil }, :on_or_before => Time.mktime(2000,1,1,12,30))
|
||||
validate_with(:birth_time, "12:30")
|
||||
should_have_no_error(:birth_time, :on_or_before)
|
||||
end
|
||||
|
||||
it "should should ignore usec value on combined value if :ignore_usec option is true" do
|
||||
configure_validator(:type => :time, :with_date => Date.new(2000,1,1), :on_or_before => Time.mktime(2000,1,1,12,30), :ignore_usec => true)
|
||||
validate_with(:birth_time, Time.mktime(2000,1,1,12,30,0,50))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user