Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the Globals middleware #1005

Merged
merged 1 commit into from
Apr 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* [#936](/~https://github.com/intridea/grape/pull/936): Fixed default params processing for optional groups - [@dm1try](/~https://github.com/dm1try).
* [#942](/~https://github.com/intridea/grape/pull/942): Fixed forced presence for optional params when based on a reused entity that was also required in another context - [@croeck](/~https://github.com/croeck).
* [#1001](/~https://github.com/intridea/grape/pull/1001): Fixed calling endpoint with specified format with format in its path - [@hodak](/~https://github.com/hodak).
* [#1005](/~https://github.com/intridea/grape/pull/1005): Fixed the Grape::Middleware::Globals - [@urkle](/~https://github.com/urkle).

* Your contribution here.

Expand Down
1 change: 1 addition & 0 deletions lib/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ module Middleware
autoload :Versioner
autoload :Formatter
autoload :Error
autoload :Globals

module Auth
extend ActiveSupport::Autoload
Expand Down
3 changes: 2 additions & 1 deletion lib/grape/middleware/globals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module Grape
module Middleware
class Globals < Base
def before
@env['grape.request'] = Grape::Request.new(@env)
request = Grape::Request.new(@env)
@env['grape.request'] = request
@env['grape.request.headers'] = request.headers
@env['grape.request.params'] = request.params if @env['rack.input']
end
Expand Down
27 changes: 27 additions & 0 deletions spec/grape/middleware/globals_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'spec_helper'

describe Grape::Middleware::Globals do
subject { Grape::Middleware::Globals.new(blank_app) }
before { allow(subject).to receive(:dup).and_return(subject) }

let(:blank_app) { lambda { |env| [200, {}, 'Hi there.'] } }

it 'calls through to the app' do
expect(subject.call({})).to eq([200, {}, 'Hi there.'])
end

context 'environment' do
it 'should set the grape.request environment' do
subject.call({})
expect(subject.env['grape.request']).to be_a(Grape::Request)
end
it 'should set the grape.request.headers environment' do
subject.call({})
expect(subject.env['grape.request.headers']).to be_a(Hash)
end
it 'should set the grape.request.params environment' do
subject.call('QUERY_STRING' => 'test=1', 'rack.input' => StringIO.new)
expect(subject.env['grape.request.params']).to be_a(Hash)
end
end
end