-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Update boolean handling of false #749
Update boolean handling of false #749
Conversation
Create a test to relicate what we are seeing in use, When passing the value of `false` to a `:boolean` parameter (as opposed to `"false"` which is parsed as a string) it was ignoring the value and falling foul of the value.blank? check that is always true for a FalseClass value
Remove some debugging steps and add a test for the correct raising of an error when a String parameter is sent an empty value
I couldn't find a collaboration guide, so I hope this is okay? |
Ensure an empty string passed to boolean still fails, this is correctly failed by `!@validator.valid?(value)` returning an invalid response when expecting `true` or `false`
Given the discussion in #750 I think there's probably a deeper underlying issue here and not something purely affecting only the boolean case. So I think a fix / change also would need to address things more generically and not only for boolean values. |
Agreed - I was only fixing the issue I saw! 👍 |
@colinbruce Thank you so much for this quick fix and added tests. |
@mathieujobin I don't think this fix is complete then though? See also the comment earlier in #749 (comment). Would more changes be necessary here? |
@dbussink this still appears to be a good fix to add, the remaining issue can be fixed as a separate PR. |
What I was trying to say is that the issue extends to anything where |
I am thinking we should actually question ActiveSupport as to why false.blank? Is true? I don't know of any other objects that would have such a problem. The allow_blank option was defaulting to false but wasn't enforced. So thing #733 and this PR is good. I think I will add more tests with more object types. |
Expand the logic around blank value checking.
If
@allow_blank
is false, make sure it's not a BooleanValidator before looking forvalue.blank?
asfalse
is a valid boolean response, butCreate a test to replicate what we are seeing in use, when passing the value of
false
to a:boolean
parameter (as opposed to"false"
which is parsed as a string)