Skip to content

Commit 03c279d

Browse files
committed
Merge pull request #1029 from dblock/rack-response-to-a
Do not convert a Rack::Response to an array.
2 parents 877e089 + 129ad6e commit 03c279d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/grape/middleware/formatter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def after
4040
throw :error, status: 500, message: e.message
4141
end
4242
headers[Grape::Http::Headers::CONTENT_TYPE] = content_type_for(env['api.format']) unless headers[Grape::Http::Headers::CONTENT_TYPE]
43-
Rack::Response.new(bodymap, status, headers).to_a
43+
Rack::Response.new(bodymap, status, headers)
4444
end
4545

4646
private

spec/grape/middleware/formatter_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def to_json
2121
end
2222
end
2323

24-
subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/json').last.each { |b| expect(b).to eq('"bar"') }
24+
subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/json').to_a.last.each { |b| expect(b).to eq('"bar"') }
2525
end
2626

2727
it 'calls #to_json if the content type is jsonapi' do
@@ -32,7 +32,7 @@ def to_json
3232
end
3333
end
3434

35-
subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/vnd.api+json').last.each { |b| expect(b).to eq('{"foos":[{"bar":"baz"}] }') }
35+
subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/vnd.api+json').to_a.last.each { |b| expect(b).to eq('{"foos":[{"bar":"baz"}] }') }
3636
end
3737

3838
it 'calls #to_xml if the content type is xml' do
@@ -43,7 +43,7 @@ def to_xml
4343
end
4444
end
4545

46-
subject.call('PATH_INFO' => '/somewhere.xml', 'HTTP_ACCEPT' => 'application/json').last.each { |b| expect(b).to eq('<bar/>') }
46+
subject.call('PATH_INFO' => '/somewhere.xml', 'HTTP_ACCEPT' => 'application/json').to_a.last.each { |b| expect(b).to eq('<bar/>') }
4747
end
4848
end
4949

0 commit comments

Comments
 (0)