mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
Merge branch 'master' of github.com:adzap/validates_timeliness
This commit is contained in:
commit
e275b63203
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user