diff --git a/lib/active_model/validations/date_validator.rb b/lib/active_model/validations/date_validator.rb index 422d0c4..748f04c 100644 --- a/lib/active_model/validations/date_validator.rb +++ b/lib/active_model/validations/date_validator.rb @@ -93,7 +93,7 @@ def validate_each(record, attr_name, value) value = value.to_datetime if value.is_a?(Date) end - unless is_time?(option_value) && value.to_i.send(CHECKS[option], option_value.to_i) + unless is_time?(option_value) && value.send(CHECKS[option], option_value) record.errors.add(attr_name, :"date_#{option}", **options.merge( value: original_value, date: (I18n.localize(original_option_value) rescue original_option_value) diff --git a/test/date_validator_test.rb b/test/date_validator_test.rb index d7c235b..70bfaeb 100644 --- a/test/date_validator_test.rb +++ b/test/date_validator_test.rb @@ -39,14 +39,14 @@ module Validations describe _context do [:after, :before, :after_or_equal_to, :before_or_equal_to, :equal_to].each do |check| - now = Time.now.to_datetime + now = Time.now.to_datetime.change(usec: 0) model_date = case check when :after then must_be == :valid ? now + 21000 : now - 1 when :before then must_be == :valid ? now - 21000 : now + 1 when :after_or_equal_to then must_be == :valid ? now : now - 21000 when :before_or_equal_to then must_be == :valid ? now : now + 21000 - when :equal_to then must_be == :valid ? now : now + 21000 + when :equal_to then must_be == :valid ? now : now.change(usec: 1) end it "ensures that an attribute is #{must_be} when #{must_be == :valid ? 'respecting' : 'offending' } the #{check} check" do