adzap / validates_timeliness

Date and time validation plugin for ActiveModel and Rails. Supports multiple ORMs and allows custom date/time formats.
MIT License
1.59k stars 227 forks source link

`add_error` call with wrong number of arguments #204

Closed lostie closed 2 years ago

lostie commented 2 years ago

@adzap I believe 6.0.0.beta1 version has introduced a breaking change:

# ArgumentError:
#   wrong number of arguments (given 3, expected 1..2)
lib/ruby/gems/3.0.0/gems/activemodel-6.1.4.1/lib/active_model/errors.rb:404:in `add'
lib/ruby/gems/3.0.0/gems/validates_timeliness-6.0.0.beta1/lib/validates_timeliness/validator.rb:89:in `add_error'
lib/ruby/gems/3.0.0/gems/validates_timeliness-6.0.0.beta1/lib/validates_timeliness/validator.rb:80:in `rescue in block in validate_restrictions'
lib/ruby/gems/3.0.0/gems/validates_timeliness-6.0.0.beta1/lib/validates_timeliness/validator.rb:72:in `block in validate_restrictions'
lib/ruby/gems/3.0.0/gems/validates_timeliness-6.0.0.beta1/lib/validates_timeliness/validator.rb:71:in `each'
lib/ruby/gems/3.0.0/gems/validates_timeliness-6.0.0.beta1/lib/validates_timeliness/validator.rb:71:in `validate_restrictions'
lib/ruby/gems/3.0.0/gems/validates_timeliness-6.0.0.beta1/lib/validates_timeliness/validator.rb:67:in `validate_each'

The options passed through ActiveModel's add method needs to be provided with a double splat (**).

record.errors.add(attr_name, message, **message_options)
adzap commented 2 years ago

Is this specific Ruby 3?

schinery commented 2 years ago

Is this specific Ruby 3?

It is. Basically where you used to be able to pass a hash as last keyword args you now have explicitly splat them.

https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/