diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-10-09 23:07:36 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-10-09 23:07:36 +0000 |
commit | 4aabe46341dd6db9bf9bbbbc27c32f467a7c55b7 (patch) | |
tree | 30a7dc0bf2b0e3756caba87556ef340071769a5b /actionpack/test | |
parent | 19c9c7fafbc7c808c080317a1326c4fbc6068bea (diff) | |
download | rails-4aabe46341dd6db9bf9bbbbc27c32f467a7c55b7.tar.gz rails-4aabe46341dd6db9bf9bbbbc27c32f467a7c55b7.tar.bz2 rails-4aabe46341dd6db9bf9bbbbc27c32f467a7c55b7.zip |
Add :status to redirect_to allowing users to choose their own response code without manually setting headers. Closes #8297 [codahale, chasgrundy]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7820 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test')
-rwxr-xr-x | actionpack/test/controller/redirect_test.rb | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index c7e4c19a0a..7ab1ddde0c 100755 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -24,6 +24,34 @@ class RedirectController < ActionController::Base redirect_to :action => "hello_world" end + def redirect_with_status + redirect_to({:action => "hello_world", :status => 301}) + end + + def redirect_with_status_hash + redirect_to({:action => "hello_world"}, {:status => 301}) + end + + def url_redirect_with_status + redirect_to("http://www.example.com", :status => :moved_permanently) + end + + def url_redirect_with_status_hash + redirect_to("http://www.example.com", {:status => 301}) + end + + def relative_url_redirect_with_status + redirect_to("/things/stuff", :status => :found) + end + + def relative_url_redirect_with_status_hash + redirect_to("/things/stuff", {:status => 301}) + end + + def redirect_to_back_with_status + redirect_to :back, :status => 307 + end + def host_redirect redirect_to :action => "other_host", :only_path => false, :host => 'other.test.host' end @@ -72,6 +100,56 @@ class RedirectTest < Test::Unit::TestCase assert_equal "http://test.host/redirect/hello_world", redirect_to_url end + def test_redirect_with_no_status + get :simple_redirect + assert_response 302 + assert_equal "http://test.host/redirect/hello_world", redirect_to_url + end + + def test_redirect_with_status + get :redirect_with_status + assert_response 301 + assert_equal "http://test.host/redirect/hello_world", redirect_to_url + end + + def test_redirect_with_status_hash + get :redirect_with_status_hash + assert_response 301 + assert_equal "http://test.host/redirect/hello_world", redirect_to_url + end + + def test_url_redirect_with_status + get :url_redirect_with_status + assert_response 301 + assert_equal "http://www.example.com", redirect_to_url + end + + def test_url_redirect_with_status_hash + get :url_redirect_with_status_hash + assert_response 301 + assert_equal "http://www.example.com", redirect_to_url + end + + + def test_relative_url_redirect_with_status + get :relative_url_redirect_with_status + assert_response 302 + assert_equal "http://test.host/things/stuff", redirect_to_url + end + + def test_relative_url_redirect_with_status_hash + get :relative_url_redirect_with_status_hash + assert_response 301 + assert_equal "http://test.host/things/stuff", redirect_to_url + end + + def test_redirect_to_back_with_status + @request.env["HTTP_REFERER"] = "http://www.example.com/coming/from" + get :redirect_to_back_with_status + assert_response 307 + assert_equal "http://www.example.com/coming/from", redirect_to_url + end + def test_simple_redirect_using_options get :host_redirect assert_response :redirect |