Skip to content

Commit

Permalink
correctly initialize env and headers
Browse files Browse the repository at this point in the history
  • Loading branch information
leifg committed Jul 19, 2016
1 parent c9a81a8 commit 0b2b69c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/grape/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ def method_not_allowed(env, methods, endpoint)
env[Grape::Env::GRAPE_METHOD_NOT_ALLOWED] = true
current = endpoint.dup
current.instance_eval do
@env = env
@header = {}

@request = Grape::Request.new(env)
@params = @request.params
@headers = @request.headers

@lazy_initialized = false
lazy_initialize!
run_filters befores, :before
Expand Down
14 changes: 14 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,20 @@ def subject.enable_root_route!
end
end

context 'when accessing env' do
it 'returns a 405 for an unsupported method' do
subject.before do
custom_header = env['HTTP_X_CUSTOM_HEADER']
end
subject.get 'example' do
'example'
end
put '/example'
expect(last_response.status).to eql 405
expect(last_response.body).to eql '405 Not Allowed'
end
end

specify '405 responses includes an Allow header specifying supported methods' do
subject.get 'example' do
'example'
Expand Down

0 comments on commit 0b2b69c

Please sign in to comment.