Values Validator => Proc's arity < 2 ?
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
While running specs with --warnings I found an interesting API endpoint under spec/grape/validations/validators/values_spec.rb with a successful test but maybe not the way we wanted.
The api is defined like this
params do
requires :input_one, :input_two, type: Integer, values: { value: ->(v1, v2) { v1 + v2 > 10 } }
end
get '/proc/arity2'
And the test goes like this
context 'when arity is > 1' do
it 'returns an error status code' do
get '/proc/arity2', input_one: 2, input_two: 3
expect(last_response.status).to eq 400
end
end
It will pass but it also emits 2 warnings
Error 'wrong number of arguments (given 1, expected 2)' raised while validating attribute 'input_one'
Error 'wrong number of arguments (given 1, expected 2)' raised while validating attribute 'input_two'
If we take a closer look a the code
- Proc's arity is expected to be < 2
- each params a process individually (SingleAttributeIterator) so there's no relation between
:input_oneand:input_twoeven if it seems to be.
I was wondering if its really a bug. Also, I think we should raise more awareness with proper error instead of a warning.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with spec/grape/validations/validators/values_spec.rb around the arity-greater-than-one example, then inspect lib/grape/validations/validators/values_validator.rb and the SingleAttributeIterator behavior. Run the targeted values validator specs with warnings enabled. Done means the behavior for a Proc requiring multiple arguments is explicitly defined and covered without the current misleading warnings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100