Invalid combinators to raise ArgumentError #1465
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on #1396
The reporter encountered two issues:
#ransack!
is called.I can see why unrecognised combinators default to "AND", it's the more conservative, safe option. But it's very surprising and a potential source of bugs for downstream users. Also the users have intentionally called the dangerous method, so should be error handling as appropriate for their domain. The right thing to do is to raise on invalid args.
However we'd best minimize impact for users currently passing invalid args. The most obvious errors would be rather than passing the expected "or", they might be passing one of "OR", :or and not noticing the fault. We can correct behavior in these common cases by downcasing and converting to a string. Indeed Ransack already does conversion to a string in some pathways, just not as part of a search. Also Anything more exotic is really unrecognisable and an error.
This PR comes with a set of tests describing expected behavior and including a few that would have failed prior to the changes.