Permalink
Browse files

Make RackRequest#request_method respect _method

  • Loading branch information...
lifo committed Jul 16, 2008
1 parent fea5b6f commit 1d002f6bcbd4e4f5cc421ee4da5be18839ccc4cb
@@ -98,10 +98,6 @@ def remote_addr
@env['REMOTE_ADDR']
end
- def request_method
- @env['REQUEST_METHOD'].downcase.to_sym
- end
-
def server_port
@env['SERVER_PORT'].to_i
end
@@ -53,6 +53,14 @@ def setup
end
def default_test; end
+
+ private
+
+ def set_content_data(data)
+ @request.env['CONTENT_LENGTH'] = data.length
+ @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
+ @request.env['RAW_POST_DATA'] = data
+ end
end
class CgiRequestTest < BaseCgiTest
@@ -180,6 +188,31 @@ def test_xml_content_type_verification
end
end
+class CgiRequestMethodTest < BaseCgiTest
+ def test_get
+ assert_equal :get, @request.request_method
+ end
+
+ def test_post
+ @request.env['REQUEST_METHOD'] = 'POST'
+ assert_equal :post, @request.request_method
+ end
+
+ def test_put
+ @request.env['REQUEST_METHOD'] = 'POST'
+ set_content_data '_method=put'
+
+ assert_equal :put, @request.request_method
+ end
+
+ def test_delete
+ @request.env['REQUEST_METHOD'] = 'POST'
+ set_content_data '_method=delete'
+
+ assert_equal :delete, @request.request_method
+ end
+end
+
class CgiRequestNeedsRewoundTest < BaseCgiTest
def test_body_should_be_rewound
data = 'foo'
@@ -51,6 +51,14 @@ def setup
end
def default_test; end
+
+ private
+
+ def set_content_data(data)
+ @request.env['CONTENT_LENGTH'] = data.length
+ @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
+ @request.env['RAW_POST_DATA'] = data
+ end
end
class RackRequestTest < BaseRackTest
@@ -178,6 +186,31 @@ def test_xml_content_type_verification
end
end
+class RackRequestMethodTest < BaseRackTest
+ def test_get
+ assert_equal :get, @request.request_method
+ end
+
+ def test_post
+ @request.env['REQUEST_METHOD'] = 'POST'
+ assert_equal :post, @request.request_method
+ end
+
+ def test_put
+ @request.env['REQUEST_METHOD'] = 'POST'
+ set_content_data '_method=put'
+
+ assert_equal :put, @request.request_method
+ end
+
+ def test_delete
+ @request.env['REQUEST_METHOD'] = 'POST'
+ set_content_data '_method=delete'
+
+ assert_equal :delete, @request.request_method
+ end
+end
+
class RackRequestNeedsRewoundTest < BaseRackTest
def test_body_should_be_rewound
data = 'foo'

0 comments on commit 1d002f6

Please sign in to comment.