spec/validator_spec.rb in validates_timeliness-2.1.0 vs spec/validator_spec.rb in validates_timeliness-2.2.0

- old
+ new

@@ -356,22 +356,10 @@ it "should have error when value not equal to :equal_to restriction" do validate_with(:birth_date_and_time, Time.now + 1) should_have_error(:birth_date_and_time, :equal_to) end - it "should have error when value is equal to :equal_to restriction for all values except microscond, and microsecond is not ignored" do - configure_validator(:equal_to => Time.utc(2000, 1, 1, 0, 0, 0, 0), :ignore_usec => false) - validate_with(:birth_date_and_time, Time.utc(2000, 1, 1, 0, 0, 0, 500)) - should_have_error(:birth_date_and_time, :equal_to) - end - - it "should be valid when value is equal to :equal_to restriction for all values except microscond, and microsecond is ignored" do - configure_validator(:equal_to => Time.utc(2000, 1, 1, 0, 0, 0, 0), :ignore_usec => true) - validate_with(:birth_date_and_time, Time.utc(2000, 1, 1, 0, 0, 0, 500)) - should_have_no_error(:birth_date_and_time, :equal_to) - end - it "should be valid when value is equal to :equal_to restriction" do validate_with(:birth_date_and_time, Time.now) should_have_no_error(:birth_date_and_time, :equal_to) end end @@ -407,10 +395,20 @@ should_have_no_error(:birth_time, :equal_to) end end end + describe "instance with :ignore_usec option" do + + it "should ignore usec on time values when evaluated" do + configure_validator(:equal_to => Time.utc(2000, 1, 1, 0, 0, 0, 0), :ignore_usec => true) + validate_with(:birth_date_and_time, Time.utc(2000, 1, 1, 0, 0, 0, 500)) + should_have_no_error(:birth_date_and_time, :equal_to) + end + + end + describe "instance with :with_time option" do it "should validate date attribute as datetime combining value of :with_time against restrictions " do configure_validator(:type => :date, :with_time => '12:31', :on_or_before => Time.mktime(2000,1,1,12,30)) validate_with(:birth_date, "2000-01-01") @@ -421,23 +419,34 @@ configure_validator(:type => :date, :with_time => 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), :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 describe "instance with mixed value and restriction types" do