1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
Jeremy Kemper 2006-05-22 22:59:56 +00:00
parent 3de8239a7c
commit 6ce3bf70a2
3 changed files with 44 additions and 9 deletions

View file

@ -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 file

@ -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)

View file

@ -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