Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validates_inclusion_of with_message does not respect interpolated value in the message #1233

Open
dlinch opened this issue Jul 16, 2019 · 1 comment

Comments

@dlinch
Copy link

dlinch commented Jul 16, 2019

validate_inclusion_of accepts a message option, inside which you are able to specify the value that was passed to the field for validation. It looks like:

with_message('the value: %{value} is not inside the acceptable list')

Shoulda-matchers does not seem to respect the interpolation of this custom value. It is shown in the method documentation here:

When I try this locally, my code looks like this:

  validates_inclusion_of :rating, in: 1..5, allow_nil: true, message: 'the value: %{value} is not between 1 and 5'

And the error message I receive is:

Expected Survey to validate that :rating lies inside the
       range ‹1› to ‹5› as long as it is not nil, producing a custom validation
       error on failure, but this could not be proved.
         After setting :rating to ‹0›, the matcher expected the
         Survey to be invalid and to produce the validation error "the value:
         %{value} is not between 1 and 5" on :rating. The record was
         indeed invalid, but it produced these validation errors instead:
     
         * rating: ["the value: 0 is not between 1 and 5"]

I believe this is an error in the shoulda-matchers code, as it is not interpolating the value correctly with the error message.

@GeneDer
Copy link

GeneDer commented Jul 26, 2019

I am encounter the same issue, currently just use regex to test the message. Hope there will be a fix coming out soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants