Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

follow_redirect doesn't complain about being redirected to the same c…

…ontroller. Closes #5153.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4361 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 6ce3bf70a24c69d8e35e8ab84dfc823042172d91 1 parent 3de8239
@jeremy jeremy authored
View
2  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]
View
5 actionpack/lib/action_controller/test_process.rb
@@ -374,8 +374,9 @@ def xml_http_request(request_method, action, parameters = nil, session = nil, fl
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)
View
46 actionpack/test/controller/test_test.rb
@@ -58,8 +58,15 @@ def redirect_to_symbol
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 @@ def test_test_uploaded_file_exception_when_file_doesnt_exist
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
Please sign in to comment.
Something went wrong with that request. Please try again.