Skip to content

Add tests for coercing bad values to a boolean #2045

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

Closed
wants to merge 1 commit into from

Conversation

DanielHeath
Copy link

I was going to open an issue, but thought that including code would help illustrate, so it's a PR instead.

Currently, if you supply "" for a boolean parameter, it does not get coerced at all - instead, it gets passed through.

I think that's confusing and inconsistent; it would be better to return Nil. Is that a sensible change?

@grape-bot
Copy link

1 Warning
⚠️ Unless you’re refactoring existing code, please update CHANGELOG.md.
1 Message
📖 We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!

Here's an example of a CHANGELOG.md entry:

* [#2045](https://github.com/ruby-grape/grape/pull/2045): Add tests for coercing bad values to a boolean - [@DanielHeath](https://github.com/DanielHeath).

Generated by 🚫 danger

Copy link
Member

@dnesteryuk dnesteryuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to move tests to that place.

@dnesteryuk
Copy link
Member

I would prefer to coerce an empty string to false in this case 🤔 The reason of the current behavior is there.

@DanielHeath
Copy link
Author

IMO an empty string is an invalid value to assign a boolean and should be treated the same as (eg) passing a string to a numeric value.

@myxoh
Copy link
Member

myxoh commented Apr 30, 2020

I tend to agree I would expect nil here as well. Thanks for adding the test!

@dblock
Copy link
Member

dblock commented May 1, 2020

I think I agree, I'd want this to be nil. Would take a PR. What else breaks?

@dnesteryuk
Copy link
Member

Dry-types treats an empty string as invalid for the boolean type 🤔

Dry::Types::CoercionError ( cannot be coerced to false)

@dblock
Copy link
Member

dblock commented May 3, 2020

Dry-types treats an empty string as invalid for the boolean type 🤔

Dry::Types::CoercionError ( cannot be coerced to false)

Interesting. I don't know ;)

@dnesteryuk
Copy link
Member

@DanielHeath thanks for the test, the request was implemented 😉

@dnesteryuk dnesteryuk closed this May 3, 2020
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

Successfully merging this pull request may close these issues.

5 participants