Remove unneeded rescue from DOB Validator (#37785)

This commit is contained in:
Matt Jankowski 2026-02-10 11:24:23 -05:00 committed by GitHub
parent 63aac77b61
commit 66b09318ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 1 additions and 3 deletions

View File

@ -3,8 +3,6 @@
class DateOfBirthValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors.add(attribute, :below_limit) if value.present? && value.to_date > min_age.ago
rescue Date::Error
record.errors.add(attribute, :invalid)
end
private

View File

@ -10,7 +10,7 @@ RSpec.describe DateOfBirthValidator do
context 'with an invalid date' do
let(:invalid_date) { '76.830.10' }
it { is_expected.to_not allow_values(invalid_date).for(:date_of_birth) }
it { is_expected.to_not allow_values(invalid_date).for(:date_of_birth).with_message(:blank) }
end
context 'with a date below the age limit' do