@@ -274,6 +274,28 @@ def define_requires_none
274274 end
275275 end
276276
277+ # Ensure there is no leakage between declared Array types and
278+ # subsequent Hash types
279+ context 'required with an Array and a Hash block' do
280+ before do
281+ subject . params do
282+ requires :cats , type : Array [ String ] , default : [ ]
283+ requires :items , type : Hash do
284+ requires :key
285+ end
286+ end
287+ subject . get '/required' do
288+ 'required works'
289+ end
290+ end
291+
292+ it 'does not output index [0] for Hash types' do
293+ get '/required' , cats : [ 'Garfield' ] , items : { foo : 'bar' }
294+ expect ( last_response . status ) . to eq ( 400 )
295+ expect ( last_response . body ) . to eq ( 'items[key] is missing' )
296+ end
297+ end
298+
277299 context 'required with a Hash block' do
278300 before do
279301 subject . params do
@@ -292,6 +314,12 @@ def define_requires_none
292314 expect ( last_response . body ) . to eq ( 'items is missing, items[key] is missing' )
293315 end
294316
317+ it 'errors when nested param not present' do
318+ get '/required' , items : { foo : 'bar' }
319+ expect ( last_response . status ) . to eq ( 400 )
320+ expect ( last_response . body ) . to eq ( 'items[key] is missing' )
321+ end
322+
295323 it 'errors when param is not a Hash' do
296324 get '/required' , items : 'hello'
297325 expect ( last_response . status ) . to eq ( 400 )
0 commit comments