Skip to content

Commit 7ad647a

Browse files
committed
Do not convert Rack::Response to Rack::Response
While using https://github.com/aserafin/grape_logging grape middleware after an upgrading grape from 0.11 to 0.12 I've been stuck with an issue: ``` NoMethodError (undefined method `downcase' for 2:Fixnum) ``` That's because `Middleware#response` tries to convert `Rack::Response` to `Rack::Response` and fails.
1 parent 2b39cfc commit 7ad647a

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Next Release
1010

1111
* [#1038](https://github.com/intridea/grape/pull/1038): Avoid dup-ing the String class when used in inherited params - [@rnubel](https://github.com/rnubel).
1212
* [#1042](https://github.com/intridea/grape/issues/1042): Fix coercion of complex arrays - [@dim](https://github.com/dim).
13+
* [#1045](https://github.com/intridea/grape/pull/1045): Do not convert `Rack::Response` to `Rack::Response` in middleware - [@dmitry](https://github.com/dmitry).
1314

1415
0.12.0 (6/18/2015)
1516
==================

lib/grape/middleware/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def after
3737
end
3838

3939
def response
40+
return @app_response if @app_response.is_a?(Rack::Response)
4041
Rack::Response.new(@app_response[2], @app_response[0], @app_response[1])
4142
end
4243

spec/grape/middleware/base_spec.rb

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,43 @@
3636

3737
describe '#response' do
3838
subject { Grape::Middleware::Base.new(response) }
39-
let(:response) { ->(_) { [204, { abc: 1 }, 'test'] } }
4039

41-
it 'status' do
42-
subject.call({})
43-
expect(subject.response.status).to eq(204)
44-
end
40+
context Array do
41+
let(:response) { ->(_) { [204, { abc: 1 }, 'test'] } }
42+
43+
it 'status' do
44+
subject.call({})
45+
expect(subject.response.status).to eq(204)
46+
end
4547

46-
it 'body' do
47-
subject.call({})
48-
expect(subject.response.body).to eq(['test'])
48+
it 'body' do
49+
subject.call({})
50+
expect(subject.response.body).to eq(['test'])
51+
end
52+
53+
it 'header' do
54+
subject.call({})
55+
expect(subject.response.header).to have_key(:abc)
56+
end
4957
end
5058

51-
it 'header' do
52-
subject.call({})
53-
expect(subject.response.header).to have_key(:abc)
59+
context Rack::Response do
60+
let(:response) { ->(_) { Rack::Response.new('test', 204, abc: 1) } }
61+
62+
it 'status' do
63+
subject.call({})
64+
expect(subject.response.status).to eq(204)
65+
end
66+
67+
it 'body' do
68+
subject.call({})
69+
expect(subject.response.body).to eq(['test'])
70+
end
71+
72+
it 'header' do
73+
subject.call({})
74+
expect(subject.response.header).to have_key(:abc)
75+
end
5476
end
5577
end
5678

0 commit comments

Comments
 (0)