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

Endpoint Param of Type Integer Cannot Set Values Array #580

Closed
xevix opened this issue Feb 18, 2014 · 5 comments
Closed

Endpoint Param of Type Integer Cannot Set Values Array #580

xevix opened this issue Feb 18, 2014 · 5 comments

Comments

@xevix
Copy link
Contributor

xevix commented Feb 18, 2014

Given an Integer type parameter like the below:

optional :number, type: Integer, desc: "An integer", values: [10,11], default: 10

Grape will fail on start with the following:

grape-0.6.1/lib/grape/validations.rb:193:in `validates': type: Integer is incompatible with values: [10, 11] (Grape::Exceptions::IncompatibleOptionValues)

This is unexpected, since String and Symbol appear to work fine, and 10 and 11 are integers. I took a quick look at the validations code where the exceptions are raised but didn't understand the code too well. Is the Integer type not supported for the values check?

@dblock
Copy link
Member

dblock commented Feb 21, 2014

This may be a bug, but I didn't dig. Start by writing a test within grape?

@ksoderstrom
Copy link

The problem is in this check of the class of the supplied values.

https://github.com/intridea/grape/blob/master/lib/grape/validations.rb#L242-L245

The values are actually Fixnum, while the specified type is Integer. Changing the call to instance_of? to kind_of? fixes it, but does that introduce any side effects that I don't see?

@dm1try
Copy link
Member

dm1try commented Feb 23, 2014

@ksoderstrom I don't think any side effect will appear, coerce validator does it same way https://github.com/intridea/grape/blob/master/lib/grape/validations/coerce.rb#L36
anyway you should writing a failing spec and fix it, then run all specs and you will know if something wrong :)

@dm1try
Copy link
Member

dm1try commented Feb 23, 2014

better solution is to use coerce validator logic and DRY if it's possible

@dblock
Copy link
Member

dblock commented Mar 7, 2014

Closed via 4934baa.

@dblock dblock closed this as completed Mar 7, 2014
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

4 participants