Skip to content

Commit 3f99242

Browse files
committed
Ensure the response is an array.
1 parent dd8a5f6 commit 3f99242

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

lib/grape/middleware/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def default_options
2525
end
2626

2727
def call(env)
28-
dup.call!(env)
28+
dup.call!(env).to_a
2929
end
3030

3131
def call!(env)

spec/grape/api_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,9 +1903,9 @@ def foo
19031903
it 'avoids polluting global namespace' do
19041904
env = Rack::MockRequest.env_for('/')
19051905

1906-
expect(a.call(env)[2].body).to eq(['foo'])
1907-
expect(b.call(env)[2].body).to eq(['bar'])
1908-
expect(a.call(env)[2].body).to eq(['foo'])
1906+
expect(a.call(env)[2]).to eq(['foo'])
1907+
expect(b.call(env)[2]).to eq(['bar'])
1908+
expect(a.call(env)[2]).to eq(['foo'])
19091909
end
19101910
end
19111911

spec/grape/endpoint_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def app
151151
it 'includes headers passed as symbols' do
152152
env = Rack::MockRequest.env_for('/headers')
153153
env['HTTP_SYMBOL_HEADER'.to_sym] = 'Goliath passes symbols'
154-
body = subject.call(env)[2].body.first
154+
body = subject.call(env)[2].first
155155
expect(JSON.parse(body)['Symbol-Header']).to eq('Goliath passes symbols')
156156
end
157157
end

spec/grape/integration/rack_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222
env = Rack::MockRequest.env_for('/', options)
2323

24-
expect(JSON.parse(app.call(env)[2].body.first)['params_keys']).to match_array('test')
24+
expect(JSON.parse(app.call(env)[2].first)['params_keys']).to match_array('test')
2525
ensure
2626
input.close
2727
input.unlink

spec/grape/middleware/formatter_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,19 @@ def to_xml
196196
subject.options[:content_types][:custom] = "don't care"
197197
subject.options[:formatters][:custom] = ->(_obj, _env) { 'CUSTOM FORMAT' }
198198
_, _, body = subject.call('PATH_INFO' => '/info.custom')
199-
expect(body.body).to eq(['CUSTOM FORMAT'])
199+
expect(body).to eq(['CUSTOM FORMAT'])
200200
end
201201
context 'default' do
202202
let(:body) { ['blah'] }
203203
it 'uses default json formatter' do
204204
_, _, body = subject.call('PATH_INFO' => '/info.json')
205-
expect(body.body).to eq(['["blah"]'])
205+
expect(body).to eq(['["blah"]'])
206206
end
207207
end
208208
it 'uses custom json formatter' do
209209
subject.options[:formatters][:json] = ->(_obj, _env) { 'CUSTOM JSON FORMAT' }
210210
_, _, body = subject.call('PATH_INFO' => '/info.json')
211-
expect(body.body).to eq(['CUSTOM JSON FORMAT'])
211+
expect(body).to eq(['CUSTOM JSON FORMAT'])
212212
end
213213
end
214214

@@ -384,7 +384,7 @@ def to_xml
384384

385385
it 'returns Grape::Uril::SendFileReponse' do
386386
env = { 'PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/json' }
387-
expect(subject.call(env)).to be_a(Grape::ServeFile::SendfileResponse)
387+
expect(subject.call(env)).to be_a(Array)
388388
end
389389
end
390390

@@ -407,7 +407,7 @@ def self.call(_, _)
407407
it 'returns response by invalid formatter' do
408408
env = { 'PATH_INFO' => '/hello.invalid', 'HTTP_ACCEPT' => 'application/x-invalid' }
409409
_, _, bodies = *subject.call(env)
410-
expect(bodies.body.first).to eq({ message: 'invalid' }.to_json)
410+
expect(bodies.first).to eq({ message: 'invalid' }.to_json)
411411
end
412412
end
413413

0 commit comments

Comments
 (0)