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

Params of incorrect type are still processed by values: condition #1676

Closed
nicholasserra opened this issue Aug 22, 2017 · 1 comment
Closed

Comments

@nicholasserra
Copy link

nicholasserra commented Aug 22, 2017

Apologies if this is a dupe or if it turns out i'm doing something wrong :)

Reporting an odd behavior with types and values conditions.

Example: optional param that has to be a positive integer

optional :page, type: Integer, values: ->(v) { v.positive? }, default: 1

If I pass a string to this param I would expect to get back a page is invalid error, as the type is Integer. If you omit the values condition, this works.

But in my example, it seems the values condition is processed before the type is checked, resulting in #<NoMethodError: undefined method `positive?' for \"testing\":String> exception.

Does the values condition have priority by design? Should any values conditions be robust enough to handle various types?

Thanks :)

@dblock
Copy link
Member

dblock commented Aug 22, 2017

There's clearly some order, in this case you're always getting the "raw" value, not a coerced one, so I think the "right" way here would be to rewrite -> (v) { v.is_a?(Numeric) && v.positive? }, no?

I'll close this, but feel free to reopen if you feel strongly otherwise and describe what you think should happen here.

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

No branches or pull requests

2 participants