#2673·paperclip

With Ruby 3.0 validator produces "ArgumentError: wrong number of arguments (given 3, expected 1..2)"

Author: vtamaraCreated Feb 23, 2021Updated Sep 13, 2022

The regression tests of an open source rails engine called sip, that uses paperclip, work good with Ruby 2.7 as can be seen at: https://travis-ci.org/github/pasosdeJesus/sip/jobs/760216853

However with Ruby 3.0 the following errors appear (as can be seen at https://travis-ci.org/github/pasosdeJesus/sip/jobs/760216854#L976):

1) Error:

Sip::AnexoTest#test_no_valido_1:

ArgumentError: wrong number of arguments (given 3, expected 1..2)

    /home/travis/build/pasosdeJesus/sip/vendor/bundle/ruby/3.0.0/gems/activemodel-6.1.3/lib/active_model/errors.rb:404:in `add'

    /home/travis/build/pasosdeJesus/sip/vendor/bundle/ruby/3.0.0/gems/paperclip-6.1.0/lib/paperclip/validators/attachment_presence_validator.rb:8:in `validate_each'
...

and

2) Error:

Sip::AnexoTest#test_no_valido_2:

ArgumentError: wrong number of arguments (given 3, expected 1..2)

    /home/travis/build/pasosdeJesus/sip/vendor/bundle/ruby/3.0.0/gems/activemodel-6.1.3/lib/active_model/errors.rb:404:in `add'

    /home/travis/build/pasosdeJesus/sip/vendor/bundle/ruby/3.0.0/gems/paperclip-6.1.0/lib/paperclip/validators/attachment_presence_validator.rb:8:in `validate_each'
...

Both are related to expressions anexo.valid? where anexo is amodel with a paperclip attachment. Both use the validator AttachmetntPresenceValidator that includes the statement producing the error:

def validate_each(record, attribute, value)
    if record.send("#{attribute}_file_name").blank?
      record.errors.add(attribute, :blank, *options)
    end
end