Skip to content
Open
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
6 changes: 3 additions & 3 deletions lib/validates_timeliness/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ def validate_restrictions(record, attr_name, value)
@restrictions_to_check.each do |restriction|
begin
restriction_value = @converter.type_cast_value(@converter.evaluate(options[restriction], record))
unless value.send(RESTRICTIONS[restriction], restriction_value)
add_error(record, attr_name, restriction, value: value, restriction_value: restriction_value) and break
end
valid = value.send(RESTRICTIONS[restriction], restriction_value)
rescue => e
unless ValidatesTimeliness.ignore_restriction_errors
message = RESTRICTION_ERROR_MESSAGE % [ attr_name, restriction.inspect, e.message ]
add_error(record, attr_name, message) and break
end
else
add_error(record, attr_name, restriction, value: value, restriction_value: restriction_value) and break unless valid
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/validates_timeliness/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@
end
end

describe ':strict option' do
[false, true].each do |ignore_restriction_errors|
it "raises the restriction error when ignore_restriction_errors is #{ignore_restriction_errors}" do
Person.validates_date :birth_date, before: :today, strict: true

with_config(:ignore_restriction_errors, ignore_restriction_errors) do
expect { Person.new(birth_date: Date.today).valid? }
.to raise_error(ActiveModel::StrictValidationFailed, 'Birth date must be before 2010-01-01')
end
end
end
end

describe ":between option" do
describe "array value" do
it 'should be split option into :on_or_after and :on_or_before values' do
Expand Down