From c2b9b48536810ddf24b79c799acf9071c3788c25 Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Mon, 9 May 2005 05:53:47 +0000 Subject: [PATCH] redirect_to_last_remembered raises an error when it fails to redirect to home - instead of trying retrying endlessly --- app/controllers/application.rb | 16 +++++++++++++--- test/functional/file_controller_test.rb | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 6058e699..1e2af4e6 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -88,7 +88,11 @@ class ApplicationController < ActionController::Base end def redirect_home(web = @web_name) - redirect_to_page('HomePage', web) + if web + redirect_to_page('HomePage', web) + else + redirect_to_url '/' + end end def redirect_to_page(page_name = @page_name, web = @web_name) @@ -120,10 +124,16 @@ class ApplicationController < ActionController::Base def return_to_last_remembered # Forget the redirect location redirect_target, @session[:return_to] = @session[:return_to], nil + tried_home, @session[:tried_home] = @session[:tried_home], false + # then try to redirect to it if redirect_target.nil? - logger.debug("Session ##{session.object_id}: no remembered redirect location, trying /") - redirect_to_url '/' + if tried_home + raise 'Application could not render the index page' + else + logger.debug("Session ##{session.object_id}: no remembered redirect location, trying home") + redirect_home + end else logger.debug("Session ##{session.object_id}: " + "redirect to the last remembered URL #{redirect_target}") diff --git a/test/functional/file_controller_test.rb b/test/functional/file_controller_test.rb index 32f0ca8f..23f18c42 100755 --- a/test/functional/file_controller_test.rb +++ b/test/functional/file_controller_test.rb @@ -104,7 +104,7 @@ class FileControllerTest < Test::Unit::TestCase # User uploads the picture file = "abcdefgh\n123" r = process 'file', 'web' => 'wiki1', 'id' => 'instiki-e2e.txt', 'file' => StringIO.new(file) - assert_redirect_url '/' + assert_redirected_to :controller => 'wiki', :action => 'show', :web => 'wiki1', :id => 'HomePage' assert @wiki.file_yard(@web).has_file?('instiki-e2e.txt') assert_equal(file, File.read("#{RAILS_ROOT}/storage/test/wiki1/instiki-e2e.txt"))