aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-12-17 00:39:19 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-12-17 00:39:19 +0000
commit0f6c86ff40d0b0efe672ae76f2b5b536feaf7255 (patch)
tree61bc174fe871cfccf8d8af39e664959918896b12 /actionpack
parentbe0c45365c912240b4979150f8c1284916007bca (diff)
downloadrails-0f6c86ff40d0b0efe672ae76f2b5b536feaf7255.tar.gz
rails-0f6c86ff40d0b0efe672ae76f2b5b536feaf7255.tar.bz2
rails-0f6c86ff40d0b0efe672ae76f2b5b536feaf7255.zip
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
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/integration.rb41
-rw-r--r--actionpack/test/controller/integration_test.rb43
3 files changed, 62 insertions, 24 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 5730d897a2..d8a1cc752c 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -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]
diff --git a/actionpack/lib/action_controller/integration.rb b/actionpack/lib/action_controller/integration.rb
index 75e6796dc9..25fb1b93af 100644
--- a/actionpack/lib/action_controller/integration.rb
+++ b/actionpack/lib/action_controller/integration.rb
@@ -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.
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index 771e243b00..4213bb4afa 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -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_post_via_redirect
+ 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
- @session.expects(:post).with(path,args,headers)
+ 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.stubs(:redirect?).returns(true, true, false)
- @session.expects(:follow_redirect!).times(2)
+ 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(: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