Skip to content

Commit

Permalink
Do not convert Rack::Response to Rack::Response
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmitry committed Jun 25, 2015
1 parent 2b39cfc commit 4e0fc3a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/grape/middleware/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def after
end

def response
return @app_response if @app_response.is_a?(Rack::Response)
Rack::Response.new(@app_response[2], @app_response[0], @app_response[1])
end

Expand Down
44 changes: 33 additions & 11 deletions spec/grape/middleware/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,43 @@

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

it 'status' do
subject.call({})
expect(subject.response.status).to eq(204)
end
context Array do
let(:response) { ->(_) { [204, { abc: 1 }, 'test'] } }

it 'status' do
subject.call({})
expect(subject.response.status).to eq(204)
end

it 'body' do
subject.call({})
expect(subject.response.body).to eq(['test'])
it 'body' do
subject.call({})
expect(subject.response.body).to eq(['test'])
end

it 'header' do
subject.call({})
expect(subject.response.header).to have_key(:abc)
end
end

it 'header' do
subject.call({})
expect(subject.response.header).to have_key(:abc)
context Rack::Response do
let(:response) { ->(_) { Rack::Response.new('test', 204, abc: 1) } }

it 'status' do
subject.call({})
expect(subject.response.status).to eq(204)
end

it 'body' do
subject.call({})
expect(subject.response.body).to eq(['test'])
end

it 'header' do
subject.call({})
expect(subject.response.header).to have_key(:abc)
end
end
end

Expand Down

0 comments on commit 4e0fc3a

Please sign in to comment.