Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/active_model/validations/date_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def validate_each(record, attr_name, value)
return
end

unless is_time?(value)
record.errors.add(attr_name, :not_a_date, options)
return
end

options.slice(*CHECKS.keys).each do |option, option_value|
option_value = option_value.call(record) if option_value.is_a?(Proc)
option_value = record.send(option_value) if option_value.is_a?(Symbol)
Expand Down
7 changes: 7 additions & 0 deletions test/date_validator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ module Validations
TestRecord.new(nil).valid?.must_equal false
end
end

describe 'with garbage input' do
it 'is invalid' do
TestRecord.validates(:expiration_date, date: true, allow_nil: true)
TestRecord.new('not a date').valid?.must_equal false
end
end
end

end
Expand Down