Skip to content
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

add failing spec for leaking indices between requests #2461

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions spec/grape/validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,49 @@ def define_requires_none
end
end

# Ensure there is no leakage of indices between requests
context 'required with a hash inside an array' do
before do
subject.params do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is subject being cleared between tests or are we calling params on the same Grape::API?

requires :items, type: Array do
requires :item, type: Hash do
requires :name, type: String
end
end
end
subject.post '/required' do
'required works'
end
end

let(:valid_item) { { item: { name: 'foo' } } }

let(:params) do
{
items: [
valid_item,
valid_item,
{}
]
}
end

it 'make sure the error message is independent of the previous request' do
post_with_json '/required', {}
expect(last_response.status).to eq(400)
expect(last_response.body).to eq('items is missing, items[item][name] is missing')

post_with_json '/required', params
expect(last_response.status).to eq(400)
expect(last_response.body).to eq('items[2][item] is missing, items[2][item][name] is missing')

post_with_json '/required', {}
expect(last_response.status).to eq(400)
# actual 'items is missing, items[2][item][name] is missing'
expect(last_response.body).to eq('items is missing, items[item][name] is missing')
end
end

context 'required with a Hash block' do
before do
subject.params do
Expand Down
Loading