diff --git a/lib/validates_timeliness/validator.rb b/lib/validates_timeliness/validator.rb index b530fe0..e0c497f 100644 --- a/lib/validates_timeliness/validator.rb +++ b/lib/validates_timeliness/validator.rb @@ -86,7 +86,7 @@ def validate_restrictions(record, attr_name, value) def add_error(record, attr_name, message, value=nil) value = format_error_value(value) if value message_options = { message: options.fetch(:"#{message}_message", options[:message]), restriction: value } - record.errors.add(attr_name, message, **message_options) + record.errors.add(attr_name, message, **options, **message_options) end def format_error_value(value) diff --git a/spec/validates_timeliness/validator_spec.rb b/spec/validates_timeliness/validator_spec.rb index c016d31..83c70b8 100644 --- a/spec/validates_timeliness/validator_spec.rb +++ b/spec/validates_timeliness/validator_spec.rb @@ -185,6 +185,27 @@ class PersonWithFormatOption end end + describe "custom option" do + class PersonWithCustomOption + include TestModel + include TestModelShim + attribute :birth_date, :date + attribute :birth_time, :time + attribute :birth_datetime, :datetime + validates_date :birth_date, :format => 'dd-mm-yyyy', :custom_option => "custom option" + end + + let(:person) { PersonWithCustomOption.new } + + with_config(:use_plugin_parser, true) + + it "should be included in the errors" do + person.birth_date = '1913-12-11' + person.valid? + expect(person.errors.first.options).to include(:custom_option => "custom option") + end + end + describe "restriction value errors" do let(:person) { Person.new(:birth_date => Date.today) }