mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
fix ignore_usec for with_date and with_time options
This commit is contained in:
parent
0e382e15f2
commit
df3283e5a1
@ -62,13 +62,15 @@ module ValidatesTimeliness
|
||||
end
|
||||
|
||||
def validate_restrictions(record, attr_name, value)
|
||||
value = if configuration[:with_time] || configuration[:with_date]
|
||||
restriction_type = type
|
||||
|
||||
if configuration[:with_time] || configuration[:with_date]
|
||||
restriction_type = :datetime
|
||||
combine_date_and_time(value, record)
|
||||
else
|
||||
restriction_type = type
|
||||
self.class.type_cast_value(value, type, configuration[:ignore_usec])
|
||||
value = combine_date_and_time(value, record)
|
||||
end
|
||||
|
||||
value = self.class.type_cast_value(value, restriction_type, configuration[:ignore_usec])
|
||||
|
||||
return if value.nil?
|
||||
|
||||
RESTRICTION_METHODS.each do |option, method|
|
||||
|
||||
@ -423,20 +423,31 @@ describe ValidatesTimeliness::Validator do
|
||||
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), :equal_to => Time.mktime(2000,1,1,12,30), :ignore_usec => true)
|
||||
validate_with(:birth_date, "2000-01-01")
|
||||
should_have_no_error(:birth_date, :equal_to)
|
||||
end
|
||||
end
|
||||
|
||||
describe "instance with :with_date option" do
|
||||
|
||||
it "should validate time attribute as datetime combining value of :with_date against restrictions " do
|
||||
configure_validator(:type => :time, :with_date => '2009-01-01', :on_or_before => Time.mktime(2000,1,1,12,30))
|
||||
validate_with(:birth_date, "12:30")
|
||||
should_have_error(:birth_date, :on_or_before)
|
||||
validate_with(:birth_time, "12:30")
|
||||
should_have_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 => nil, :on_or_before => Time.mktime(2000,1,1,12,30))
|
||||
validate_with(:birth_date, "12:30")
|
||||
should_have_no_error(:birth_date, :on_or_before)
|
||||
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))
|
||||
should_have_no_error(:birth_time, :on_or_before)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user