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

Array version of allow_value #562

Closed
douglascamata opened this issue Jul 30, 2014 · 5 comments
Closed

Array version of allow_value #562

douglascamata opened this issue Jul 30, 2014 · 5 comments

Comments

@douglascamata
Copy link

Sometimes you need to see if some values are allowed for a defined field and using the current features you would have to use many allow_value().for() constructs. It would be nice to have a array version, like allow_values('foo', 'bar').for().

@mcmire
Copy link
Collaborator

mcmire commented Jul 30, 2014

You can say that already:

# will assert that both "foo" and "bar" are valid values for :attr
allow_value("foo", "bar").for(:attr)

The only case where this breaks down is in the should_not case, where you do need to have separate assertions.

Read more: http://thoughtbot.github.io/shoulda-matchers/v2.6.2/Shoulda/Matchers/ActiveModel.html#allow_value-instance_method

@douglascamata
Copy link
Author

@mcmire hum, that's cool but not intuitive. I thought allow_values would do something like this, not the singular one. Although, do you think it's possible to implement it to the negative assertion case?

@mcmire
Copy link
Collaborator

mcmire commented Jul 30, 2014

@douglascamata It is possible but it would break backward compatibility, so we plan on doing that in 3.0.

As for allow_values, I agree that the name doesn't express that this is possible. If you open a PR to make an alias for this (with a test for the alias, like this) then I will happily merge it in.

@douglascamata
Copy link
Author

@mcmire I'll happy implement that as soon as I get home 👍

@mcmire
Copy link
Collaborator

mcmire commented Apr 20, 2015

Closed by #692 -- the alias is now in master.

@mcmire mcmire closed this as completed Apr 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants