Skip to content

Commit

Permalink
Add test proving leak between Array types and subsequent Hash types
Browse files Browse the repository at this point in the history
This confirms the issue raised in this comment:
#1131 (comment)
  • Loading branch information
lsimoneau committed Aug 17, 2016
1 parent f33cf12 commit 2131dd5
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions spec/grape/validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,28 @@ def define_requires_none
end
end

# Ensure there is no leakage between declared Array types and
# subsequent Hash types
context 'required with an Array and a Hash block' do
before do
subject.params do
requires :cats, type: Array[String], default: []
requires :items, type: Hash do
requires :key
end
end
subject.get '/required' do
'required works'
end
end

it 'does not output index [0] for Hash types' do
get '/required', cats: ['Garfield'], items: { foo: 'bar' }
expect(last_response.status).to eq(400)
expect(last_response.body).to eq('items[key] is missing')
end
end

context 'required with a Hash block' do
before do
subject.params do
Expand All @@ -292,6 +314,12 @@ def define_requires_none
expect(last_response.body).to eq('items is missing, items[key] is missing')
end

it 'errors when nested param not present' do
get '/required', items: { foo: "bar" }
expect(last_response.status).to eq(400)
expect(last_response.body).to eq('items[key] is missing')
end

it 'errors when param is not a Hash' do
get '/required', items: 'hello'
expect(last_response.status).to eq(400)
Expand Down

0 comments on commit 2131dd5

Please sign in to comment.