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

Coerce empty string to nil for all Primitive types except String #2067

Merged
merged 3 commits into from
Jun 9, 2020

Conversation

petekinnecom
Copy link
Contributor

No description provided.

This matches the behavior in v1.2.5 with the exception of Symbol. In
v1.2.5 an empty string was coerced to an empty symbol (:''), now it is
coerced to nil.
@petekinnecom
Copy link
Contributor Author

Here's a reproduction of the behavior on v.1.2.5: petekinnecom@ec99d8c#diff-d4c132540f49911bbd1c73264c2c738bR12

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 looks right to me 👍

@dblock
Copy link
Member

dblock commented Jun 3, 2020

This does modify external behavior of interacting with an API. I think we need:

WDYT?

@dnesteryuk
Copy link
Member

@dblock do you mean more integration tests? What is wrong with unit tests? 🤔 Personally, I like more unit tests, they are more focused (point to code under tests).

@dblock
Copy link
Member

dblock commented Jun 5, 2020

@dblock do you mean more integration tests? What is wrong with unit tests? 🤔 Personally, I like more unit tests, they are more focused (point to code under tests).

Yes. This behavior affects what happens when you call an API, and there are no changes in tests for that external behavior. We often rely on those integration tests when we're not sure what's supposed to happen and still keep introducing regressions. Better safe than sorry. @petekinnecom if you aren't adding any I'm OK with merging this though. Just let us know?

These specs mirror the specs for nil params. Exceptions are made for
non-primitive types based on their current behavior.
@petekinnecom
Copy link
Contributor Author

I've pushed a commit that has integration tests that mirror the tests found for nil (they are found just above in the same file I edited). The behavior for primitive types is all that's been updated here, so for other types, this just captures existing behavior. For the exceptions here the params are not parsed as an empty string but rather cause a 400 response:

619db09#diff-d4c132540f49911bbd1c73264c2c738bR533
619db09#diff-d4c132540f49911bbd1c73264c2c738bR550

@dblock dblock merged commit 83960b0 into ruby-grape:master Jun 9, 2020
@dblock
Copy link
Member

dblock commented Jun 9, 2020

Perfect, merged. Thank you.

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.

3 participants