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

nil Value for type: Integer Does Not Return Error #622

Closed
jackdesert opened this issue Apr 8, 2014 · 5 comments
Closed

nil Value for type: Integer Does Not Return Error #622

jackdesert opened this issue Apr 8, 2014 · 5 comments
Labels

Comments

@jackdesert
Copy link

Using 0.7.1, If I set

params do
  requires :id, type: Integer
end

And then I pass in

{ id: nil }

Grape does not detect an error.

@dblock dblock added the bug? label Apr 8, 2014
@dblock
Copy link
Member

dblock commented Apr 8, 2014

You POST this via JSON? Is it different when it's in the URL query string? Would appreciate a failing test in Grape if you have a moment.

@jackdesert
Copy link
Author

Just pushed a pull request with a failing test:
#624

On Tue, Apr 8, 2014 at 4:11 AM, Daniel Doubrovkine (dB.) @dblockdotorg <
notifications@github.com> wrote:

You POST this via JSON? Is it different when it's in the URL query string?
Would appreciate a failing test in Grape if you have a moment.

Reply to this email directly or view it on GitHubhttps://github.com//issues/622#issuecomment-39835932
.

@mynameisrufus
Copy link
Contributor

I think nil is still a valid value, I think a validation would make more sense allow_nil: true.

requires :foo, allow_nil: true

What if grape did not have optional and required and only had param plus a mixture of validators?

param :foo, allow_nil: true, presence: true

@dm1try
Copy link
Member

dm1try commented Sep 22, 2014

btw, you can use allow_blank to allow nil

requires :id, type: Integer, allow_blank: true #default

@dblock
Copy link
Member

dblock commented Nov 28, 2014

@dm1try is right on, modified specs with allow_blank in dblock@048c158 to demonstrate.

@dblock dblock closed this as completed Nov 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants