-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix error messages for nested multiple params validations #1913
Fix error messages for nested multiple params validations #1913
Conversation
170ee14
to
a64401d
Compare
@@ -5,11 +5,12 @@ class AttributesIterator | |||
|
|||
attr_reader :scope | |||
|
|||
def initialize(validator, scope, params) | |||
def initialize(validator, scope, params, multiple_params: false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about writing another attribute iterator, MutlipleParamsAttributeIterator
and SingleParamsAttributeIterator
instead of this additional parameter? Subclass from an AttributeIterator
and we have something much cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea, thanks! I changed this part in the last commit, please check it out. Also the build is green now.
This is solid work. See above for my comments. Needs a green build, please. |
Previously all the multiple params validators returned messages without considering the scope. For example, in case of hash params: `{ "param_1,param_2": 'error message' }` instead of: `{ "hash[param_1],hash[param_2]": 'error message' }` Or in case of arrays indexes were ignored completely: `{ "param_1,param_2": 'error message' }` instead of: `{ "array[1][param_1],array[1][param_2]": 'error message' }` This commit fixes it by using AttributesIterator in a similar way to Grape::Validations::Base.
TBH, no idea how they managed to pass before
a64401d
to
b9c1a32
Compare
Perfect, merged. |
Previously multiple params validators returned messages without considering the scope.
For example, in case of hash params:
{ "param_1,param_2": 'error message' }
instead of:
{ "hash[param_1],hash[param_2]": 'error message' }
Or in case of arrays, indexes were ignored completely:
{ "param_1,param_2": 'error message' }
instead of:
{ "array[1][param_1],array[1][param_2]": 'error message' }
This PR fixes it by using
AttributesIterator
in a similar way toGrape::Validations::Base
.Also the specs are refactored to work in a similar way to the ordinary single-parameter validations.