From 4a66f09e6dd062a211dc70d1534066616e377997 Mon Sep 17 00:00:00 2001 From: AkitaOnRails Date: Mon, 24 May 2010 04:10:05 -0300 Subject: [PATCH] Adding support for the PATCH Verb as it was already approved (http://www.innoq.com/blog/st/2010/03/rfc_5789_patch_method_for_http.html) --- lib/rack/mock.rb | 5 +++-- lib/rack/request.rb | 1 + test/spec_rack_auth_digest.rb | 8 ++++++++ test/spec_rack_mock.rb | 4 ++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/rack/mock.rb b/lib/rack/mock.rb index e8bc8e4..30ed8ae 100644 --- a/lib/rack/mock.rb +++ b/lib/rack/mock.rb @@ -9,12 +9,12 @@ module Rack # Rack::MockRequest helps testing your Rack application without # actually using HTTP. # - # After performing a request on a URL with get/post/put/delete, it + # After performing a request on a URL with get/post/put/patch/delete, it # returns a MockResponse with useful helper methods for effective # testing. # # You can pass a hash with additional configuration to the - # get/post/put/delete. + # get/post/put/patch/delete. # :input:: A String or IO-like to be used as rack.input. # :fatal:: Raise a FatalWarning if the app writes to rack.errors. # :lint:: If true, wrap the application in a Rack::Lint. @@ -56,6 +56,7 @@ module Rack def get(uri, opts={}) request("GET", uri, opts) end def post(uri, opts={}) request("POST", uri, opts) end def put(uri, opts={}) request("PUT", uri, opts) end + def patch(uri, opts={}) request("PATCH", uri, opts) end def delete(uri, opts={}) request("DELETE", uri, opts) end def request(method="GET", uri="", opts={}) diff --git a/lib/rack/request.rb b/lib/rack/request.rb index b3de1ce..50ffef5 100644 --- a/lib/rack/request.rb +++ b/lib/rack/request.rb @@ -83,6 +83,7 @@ module Rack def get?; request_method == "GET" end def post?; request_method == "POST" end def put?; request_method == "PUT" end + def patch?; request_method == "PATCH" end def delete?; request_method == "DELETE" end def head?; request_method == "HEAD" end diff --git a/test/spec_rack_auth_digest.rb b/test/spec_rack_auth_digest.rb index a980acc..6a5ec7e 100644 --- a/test/spec_rack_auth_digest.rb +++ b/test/spec_rack_auth_digest.rb @@ -219,6 +219,14 @@ context 'Rack::Auth::Digest::MD5' do end end + specify 'should return application output if correct credentials given for PATCH (using method override of POST)' do + @request = Rack::MockRequest.new(protected_app_with_method_override) + request_with_digest_auth 'POST', '/', 'Alice', 'correct-password', :input => "_method=patch" do |response| + response.status.should.equal 200 + response.body.to_s.should.equal 'Hi Alice' + end + end + specify 'realm as optional constructor arg' do app = Rack::Auth::Digest::MD5.new(unprotected_app, realm) { true } assert_equal realm, app.realm diff --git a/test/spec_rack_mock.rb b/test/spec_rack_mock.rb index ca52398..3d90d61 100644 --- a/test/spec_rack_mock.rb +++ b/test/spec_rack_mock.rb @@ -56,6 +56,10 @@ context "Rack::MockRequest" do env = YAML.load(res.body) env["REQUEST_METHOD"].should.equal "PUT" + res = Rack::MockRequest.new(app).patch("", :input => "foo") + env = YAML.load(res.body) + env["REQUEST_METHOD"].should.equal "PATCH" + res = Rack::MockRequest.new(app).delete("", :input => "foo") env = YAML.load(res.body) env["REQUEST_METHOD"].should.equal "DELETE" -- 1.7.0