-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Blake Mizerany
committed
Oct 3, 2007
1 parent
f0bc231
commit 4953825
Showing
4 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
module Rack | |||
|
|||
class Request | |||
|
|||
def request_method | |||
if @env['REQUEST_METHOD'] == 'POST' && %w(PUT DELETE).include?(params['_method']) | |||
params['_method'].upcase | |||
else | |||
@env['REQUEST_METHOD'] | |||
end | |||
end | |||
|
|||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
require File.dirname(__FILE__) + '/../helper' | |||
|
|||
describe "Rack::Request" do | |||
it "should return PUT and DELETE based on _method param" do | |||
env = {'REQUEST_METHOD' => 'POST', 'rack.input' => StringIO.new('_method=DELETE')} | |||
Rack::Request.new(env).request_method.should.equal 'DELETE' | |||
|
|||
env = {'REQUEST_METHOD' => 'POST', 'rack.input' => StringIO.new('_method=PUT')} | |||
Rack::Request.new(env).request_method.should.equal 'PUT' | |||
end | |||
|
|||
it "should not allow faking" do | |||
env = {'REQUEST_METHOD' => 'POST', 'rack.input' => StringIO.new('_method=GET')} | |||
Rack::Request.new(env).request_method.should.equal 'POST' | |||
|
|||
env = {'REQUEST_METHOD' => 'GET', 'rack.input' => StringIO.new('_method=POST')} | |||
Rack::Request.new(env).request_method.should.equal 'GET' | |||
end | |||
end | |||
|
|||
|