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

Document empty array parsing bug for #2079 #2080

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions spec/grape/endpoint_spec.rb
Expand Up @@ -589,6 +589,40 @@ def app
end
end

describe 'array handling' do
let(:json) { JSON.parse(last_response.body) }
let(:arr) { json.fetch 'arr' }

before do
subject.format :json
subject.params do
optional :arr, type: Array
end
subject.get '/declared' do
declared(params, include_missing: false)
end
end

# see: https://github.com/lostisland/faraday/pull/801
it 'correctly parses an empty array as passed by faraday' do
get '/declared?arr[]'

expect(arr).to eq []
end

it 'correctly parses other empty-ish array notation' do
get '/declared?arr[]='

expect(arr).to eq []
end

it 'correctly parses an array with content' do
get '/declared?arr[]=a&arr[]=b'

expect(arr).to eq %w[a b]
end
end

describe '#declared; call from child namespace' do
before do
subject.format :json
Expand Down