aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-05-22 22:59:56 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-05-22 22:59:56 +0000
commit6ce3bf70a24c69d8e35e8ab84dfc823042172d91 (patch)
treeb6a74e5867d2f7a9f26878e11f632e6e9bea9569 /actionpack
parent3de8239a7c93aed5883aaa00e36086b0c3e1572f (diff)
downloadrails-6ce3bf70a24c69d8e35e8ab84dfc823042172d91.tar.gz
rails-6ce3bf70a24c69d8e35e8ab84dfc823042172d91.tar.bz2
rails-6ce3bf70a24c69d8e35e8ab84dfc823042172d91.zip
follow_redirect doesn't complain about being redirected to the same controller. Closes #5153.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4361 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/test_process.rb5
-rw-r--r--actionpack/test/controller/test_test.rb46
3 files changed, 44 insertions, 9 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index b3388a3773..0b535e0999 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* follow_redirect doesn't complain about being redirected to the same controller. #5153 [dymo@mk.ukrtelecom.ua]
+
* Add layout attribute to response object with the name of the layout that was rendered, or nil if none rendered. [Kevin Clark kevin.clark@gmail.com]
* Fix NoMethodError when parsing params like &&. [Adam Greenfield]
diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb
index b35439249d..c13fe82328 100644
--- a/actionpack/lib/action_controller/test_process.rb
+++ b/actionpack/lib/action_controller/test_process.rb
@@ -374,8 +374,9 @@ module ActionController #:nodoc:
alias xhr :xml_http_request
def follow_redirect
- if @response.redirected_to[:controller]
- raise "Can't follow redirects outside of current controller (#{@response.redirected_to[:controller]})"
+ redirected_controller = @response.redirected_to[:controller]
+ if redirected_controller && redirected_controller != @controller.controller_name
+ raise "Can't follow redirects outside of current controller (from #{@controller.controller_name} to #{redirected_controller})"
end
get(@response.redirected_to.delete(:action), @response.redirected_to.stringify_keys)
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index 2d33a3d9d4..2c341e751b 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -58,8 +58,15 @@ HTML
redirect_to :generate_url, :id => 5
end
+ def redirect_to_same_controller
+ redirect_to :controller => 'test', :action => 'test_uri', :id => 5
+ end
+
+ def redirect_to_different_controller
+ redirect_to :controller => 'fail', :id => 5
+ end
+
private
-
def rescue_action(e)
raise e
end
@@ -405,14 +412,39 @@ HTML
end
def test_assert_redirected_to_symbol
- with_routing do |set|
- set.draw do
- set.generate_url 'foo', :controller => 'test'
- set.connect ':controller/:action/:id'
- end
-
+ with_foo_routing do |set|
get :redirect_to_symbol
+ assert_response :redirect
assert_redirected_to :generate_url
end
end
+
+ def test_assert_follow_redirect_to_same_controller
+ with_foo_routing do |set|
+ get :redirect_to_same_controller
+ assert_response :redirect
+ assert_redirected_to :controller => 'test_test/test', :action => 'test_uri', :id => 5
+ assert_nothing_raised { follow_redirect }
+ end
+ end
+
+ def test_assert_follow_redirect_to_different_controller
+ with_foo_routing do |set|
+ get :redirect_to_different_controller
+ assert_response :redirect
+ assert_redirected_to :controller => 'fail', :id => 5
+ assert_raise(RuntimeError) { follow_redirect }
+ end
+ end
+
+ protected
+ def with_foo_routing
+ with_routing do |set|
+ set.draw do
+ set.generate_url 'foo', :controller => 'test'
+ set.connect ':controller/:action/:id'
+ end
+ yield set
+ end
+ end
end