instiki/vendor/plugins/rack/test/spec_rack_methodoverride.rb
Jacques Distler 76f388f3e2 Vendor Rack 1.0.1
Incorporate patch from Revision 496.
2009-12-18 20:16:58 -06:00

60 lines
2.1 KiB
Ruby

require 'test/spec'
require 'rack/mock'
require 'rack/methodoverride'
require 'stringio'
context "Rack::MethodOverride" do
specify "should not affect GET requests" do
env = Rack::MockRequest.env_for("/?_method=delete", :method => "GET")
app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) })
req = app.call(env)
req.env["REQUEST_METHOD"].should.equal "GET"
end
specify "_method parameter should modify REQUEST_METHOD for POST requests" do
env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=put")
app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) })
req = app.call(env)
req.env["REQUEST_METHOD"].should.equal "PUT"
end
specify "X-HTTP-Method-Override header should modify REQUEST_METHOD for POST requests" do
env = Rack::MockRequest.env_for("/",
:method => "POST",
"HTTP_X_HTTP_METHOD_OVERRIDE" => "PUT"
)
app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) })
req = app.call(env)
req.env["REQUEST_METHOD"].should.equal "PUT"
end
specify "should not modify REQUEST_METHOD if the method is unknown" do
env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=foo")
app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) })
req = app.call(env)
req.env["REQUEST_METHOD"].should.equal "POST"
end
specify "should not modify REQUEST_METHOD when _method is nil" do
env = Rack::MockRequest.env_for("/", :method => "POST", :input => "foo=bar")
app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) })
req = app.call(env)
req.env["REQUEST_METHOD"].should.equal "POST"
end
specify "should store the original REQUEST_METHOD prior to overriding" do
env = Rack::MockRequest.env_for("/",
:method => "POST",
:input => "_method=options")
app = Rack::MethodOverride.new(lambda { |env| Rack::Request.new(env) })
req = app.call(env)
req.env["rack.methodoverride.original_method"].should.equal "POST"
end
end