Skip to content

Commit

Permalink
Merge pull request #1045 from dmitry/fix/do-not-convert-rack-response
Browse files Browse the repository at this point in the history
Do not convert Rack::Response to Rack::Response
  • Loading branch information
dblock committed Jun 25, 2015
2 parents b474f5e + 7ad647a commit b8b6053
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ Next Release

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

0.12.0 (6/18/2015)
==================
Expand Down
1 change: 1 addition & 0 deletions lib/grape/middleware/base.rb
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
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 b8b6053

Please sign in to comment.