Merge branch 'master' of github.com:adzap/validates_timeliness

This commit is contained in:
Adam Meehan 2018-05-13 21:01:36 +10:00
commit e275b63203
2 changed files with 15 additions and 1 deletions

View File

@ -91,7 +91,7 @@ module ValidatesTimeliness
def add_error(record, attr_name, message, value=nil)
value = format_error_value(value) if value
message_options = { :message => options[:"#{message}_message"], :restriction => value }
message_options = { :message => options.fetch(:"#{message}_message", options[:message]), :restriction => value }
record.errors.add(attr_name, message, message_options)
end

View File

@ -87,6 +87,20 @@ RSpec.describe ValidatesTimeliness::Validator do
end
end
describe ':message options' do
it 'should allow message option too' do
Person.validates_date :birth_date, on_or_after: :today, message: 'cannot be in past'
invalid!(:birth_date, Date.today - 5.days, 'cannot be in past')
valid!(:birth_date, Date.today)
end
it 'should first allow the defined message' do
Person.validates_date :birth_date, on_or_after: :today, on_or_after_message: 'cannot be in past', message: 'dummy message'
invalid!(:birth_date, Date.today - 5.days, 'cannot be in past')
valid!(:birth_date, Date.today)
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