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

Boolean type not working as expected #1551

Closed
Crystark opened this issue Jan 5, 2017 · 5 comments
Closed

Boolean type not working as expected #1551

Crystark opened this issue Jan 5, 2017 · 5 comments
Labels

Comments

@Crystark
Copy link

Crystark commented Jan 5, 2017

Hi,

I'm having trouble using the Boolean type with proper boolean values.

What I initially wanted to do:

optional :active, type: Boolean, default: true

Always returns active is invalid should I send { "active": true } or { "active": false }

What i had to do is actually add coerce_with using the identity lambda...

optional :active, type: Boolean, default: true, coerce_with: ->(v) { v }

Did I miss something here ?
I'm using version 0.18

@dblock
Copy link
Member

dblock commented Jan 5, 2017

Boolean is actually Virtus::Boolean if I am not mistaken. Either way try to write a spec for this, you obviously shouldn't need to coerce a boolean.

@dblock dblock added the bug? label Jan 5, 2017
@tuttiq
Copy link

tuttiq commented Mar 8, 2017

I just experienced the same problem when using type: Boolean, any value is considered invalid.
My workaround was to use the default coercion method, changing type for coerce in the param declaration.

optional :flag, coerce: Boolean

Then it works with any value that can be coerced into a Boolean, like {flag: true}, {flag: 'true'}, {flag: 1}, {flag: '1'}.

@LeFnord
Copy link
Member

LeFnord commented Mar 8, 2017

try to use Virtus::Attribute::Boolean instead, see: #1115

@dblock
Copy link
Member

dblock commented Mar 8, 2017

tiarly added a commit to tiarly/grape that referenced this issue Jun 30, 2017
This is commit adds additional specs to make sure Boolean type
is indeed working as expected.

ruby-grape#1551
tiarly added a commit to tiarly/grape that referenced this issue Jun 30, 2017
This is commit adds additional specs to make sure Boolean type
is indeed working as expected.

ruby-grape#1551
@dblock
Copy link
Member

dblock commented Jul 3, 2017

Closing via more tests in #1650.

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