mirror of
https://github.com/github/rails.git
synced 2026-01-30 00:38:00 -05:00
Added delete_via_redirect and put_via_redirect to integration testing (closes #10497) [philodespotos]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8429 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*2.0.2* (December 16th, 2007)
|
||||
|
||||
* Added delete_via_redirect and put_via_redirect to integration testing #10497 [philodespotos]
|
||||
|
||||
* Allow headers['Accept'] to be set by hand when calling xml_http_request #10461 [BMorearty]
|
||||
|
||||
* Added OPTIONS to list of default accepted HTTP methods #10449 [holoway]
|
||||
|
||||
@@ -121,23 +121,38 @@ module ActionController
|
||||
status
|
||||
end
|
||||
|
||||
# Performs a GET request, following any subsequent redirect. Note that
|
||||
# the redirects are followed until the response is not a redirect--this
|
||||
# means you may run into an infinite loop if your redirect loops back to
|
||||
# itself. Headers are treated in the same way as #get.
|
||||
def get_via_redirect(path, args={}, headers = {})
|
||||
get path, args, headers
|
||||
# Performs a request using the specified method, following any subsequent
|
||||
# redirect. Note that the redirects are followed until the response is
|
||||
# not a redirect--this means you may run into an infinite loop if your
|
||||
# redirect loops back to itself.
|
||||
def request_via_redirect(http_method, path, parameters = nil, headers = nil)
|
||||
send(http_method, path, parameters, headers)
|
||||
follow_redirect! while redirect?
|
||||
status
|
||||
end
|
||||
|
||||
# Performs a POST request, following any subsequent redirect. This is
|
||||
# vulnerable to infinite loops, the same as #get_via_redirect. Headers are
|
||||
# treated in the same way as #get.
|
||||
def post_via_redirect(path, args={}, headers = {})
|
||||
post path, args, headers
|
||||
follow_redirect! while redirect?
|
||||
status
|
||||
# Performs a GET request, following any subsequent redirect.
|
||||
# See #request_via_redirect() for more information.
|
||||
def get_via_redirect(path, parameters = nil, headers = nil)
|
||||
request_via_redirect(:get, path, parameters, headers)
|
||||
end
|
||||
|
||||
# Performs a POST request, following any subsequent redirect.
|
||||
# See #request_via_redirect() for more information.
|
||||
def post_via_redirect(path, parameters = nil, headers = nil)
|
||||
request_via_redirect(:post, path, parameters, headers)
|
||||
end
|
||||
|
||||
# Performs a PUT request, following any subsequent redirect.
|
||||
# See #request_via_redirect() for more information.
|
||||
def put_via_redirect(path, parameters = nil, headers = nil)
|
||||
request_via_redirect(:put, path, parameters, headers)
|
||||
end
|
||||
|
||||
# Performs a DELETE request, following any subsequent redirect.
|
||||
# See #request_via_redirect() for more information.
|
||||
def delete_via_redirect(path, parameters = nil, headers = nil)
|
||||
request_via_redirect(:delete, path, parameters, headers)
|
||||
end
|
||||
|
||||
# Returns +true+ if the last response was a redirect.
|
||||
|
||||
@@ -49,28 +49,49 @@ class SessionTest < Test::Unit::TestCase
|
||||
assert_equal 200, @session.follow_redirect!
|
||||
end
|
||||
|
||||
def test_get_via_redirect
|
||||
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
|
||||
|
||||
@session.expects(:get).with(path,args,headers)
|
||||
def test_request_via_redirect_uses_given_method
|
||||
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"}
|
||||
@session.expects(:put).with(path, args, headers)
|
||||
@session.stubs(:redirect?).returns(false)
|
||||
@session.request_via_redirect(:put, path, args, headers)
|
||||
end
|
||||
|
||||
def test_request_via_redirect_follows_redirects
|
||||
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"}
|
||||
@session.stubs(:redirect?).returns(true, true, false)
|
||||
@session.expects(:follow_redirect!).times(2)
|
||||
@session.request_via_redirect(:get, path, args, headers)
|
||||
end
|
||||
|
||||
def test_request_via_redirect_returns_status
|
||||
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"}
|
||||
@session.stubs(:redirect?).returns(false)
|
||||
@session.stubs(:status).returns(200)
|
||||
assert_equal 200, @session.get_via_redirect(path, args, headers)
|
||||
assert_equal 200, @session.request_via_redirect(:get, path, args, headers)
|
||||
end
|
||||
|
||||
def test_get_via_redirect
|
||||
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
|
||||
@session.expects(:request_via_redirect).with(:get, path, args, headers)
|
||||
@session.get_via_redirect(path, args, headers)
|
||||
end
|
||||
|
||||
def test_post_via_redirect
|
||||
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
|
||||
@session.expects(:request_via_redirect).with(:post, path, args, headers)
|
||||
@session.post_via_redirect(path, args, headers)
|
||||
end
|
||||
|
||||
@session.expects(:post).with(path,args,headers)
|
||||
def test_put_via_redirect
|
||||
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
|
||||
@session.expects(:request_via_redirect).with(:put, path, args, headers)
|
||||
@session.put_via_redirect(path, args, headers)
|
||||
end
|
||||
|
||||
@session.stubs(:redirect?).returns(true, true, false)
|
||||
@session.expects(:follow_redirect!).times(2)
|
||||
|
||||
@session.stubs(:status).returns(200)
|
||||
assert_equal 200, @session.post_via_redirect(path, args, headers)
|
||||
def test_delete_via_redirect
|
||||
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
|
||||
@session.expects(:request_via_redirect).with(:delete, path, args, headers)
|
||||
@session.delete_via_redirect(path, args, headers)
|
||||
end
|
||||
|
||||
def test_url_for_with_controller
|
||||
|
||||
Reference in New Issue
Block a user