diff options
-rw-r--r-- | app/controllers/wiki_controller.rb | 11 | ||||
-rw-r--r-- | app/models/wiki.rb | 11 | ||||
-rw-r--r-- | test/functional/wiki_controller_test.rb | 7 | ||||
-rw-r--r-- | test/unit/wiki_test.rb | 33 |
4 files changed, 55 insertions, 7 deletions
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 84fb16d2e..f11b21264 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -249,12 +249,21 @@ private # Finds the requested page or a new page if it doesn't exist def find_existing_or_new_page @page = @wiki.find_or_new_page(params[:id]) + if @wiki.page_found_with_redirect? + redirect_to params.update(:id => @page.title) + end end # Finds the requested page and returns a 404 error if it doesn't exist def find_existing_page @page = @wiki.find_page(params[:id]) - render_404 if @page.nil? + if @page.nil? + render_404 + return + end + if @wiki.page_found_with_redirect? + redirect_to params.update(:id => @page.title) + end end # Returns true if the current user is allowed to edit the page, otherwise false diff --git a/app/models/wiki.rb b/app/models/wiki.rb index eb521c99a..8c5ee0689 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -44,17 +44,26 @@ class Wiki < ActiveRecord::Base # find the page with the given title def find_page(title, options = {}) + @page_found_with_redirect = false title = start_page if title.blank? title = Wiki.titleize(title) page = pages.first(:conditions => ["LOWER(title) = LOWER(?)", title]) if !page && !(options[:with_redirect] == false) # search for a redirect redirect = redirects.first(:conditions => ["LOWER(title) = LOWER(?)", title]) - page = find_page(redirect.redirects_to, :with_redirect => false) if redirect + if redirect + page = find_page(redirect.redirects_to, :with_redirect => false) + @page_found_with_redirect = true + end end page end + # Returns true if the last page was found with a redirect + def page_found_with_redirect? + @page_found_with_redirect + end + # Finds a page by title # The given string can be of one of the forms: "title" or "project:title" # Examples: diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 397018f54..9303d23fe 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -55,6 +55,13 @@ class WikiControllerTest < ActionController::TestCase :alt => 'This is a logo' } end + def test_show_redirected_page + WikiRedirect.create!(:wiki_id => 1, :title => 'Old_title', :redirects_to => 'Another_page') + + get :show, :project_id => 'ecookbook', :id => 'Old_title' + assert_redirected_to '/projects/ecookbook/wiki/Another_page' + end + def test_show_with_sidebar page = Project.find(1).wiki.pages.new(:title => 'Sidebar') page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar') diff --git a/test/unit/wiki_test.rb b/test/unit/wiki_test.rb index 10c00820c..b248a7e7a 100644 --- a/test/unit/wiki_test.rb +++ b/test/unit/wiki_test.rb @@ -1,7 +1,7 @@ # encoding: utf-8 # -# redMine - project management software -# Copyright (C) 2006-2007 Jean-Philippe Lang +# Redmine - project management software +# Copyright (C) 2006-2011 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -39,21 +39,44 @@ class WikiTest < ActiveSupport::TestCase assert_equal "Another start page", @wiki.start_page end - def test_find_page + def test_find_page_should_not_be_case_sensitive wiki = Wiki.find(1) page = WikiPage.find(2) assert_equal page, wiki.find_page('Another_page') assert_equal page, wiki.find_page('Another page') assert_equal page, wiki.find_page('ANOTHER page') - + end + + def test_find_page_with_cyrillic_characters + wiki = Wiki.find(1) page = WikiPage.find(10) assert_equal page, wiki.find_page('Этика_менеджмента') - + end + + def test_find_page_with_backslashes + wiki = Wiki.find(1) page = WikiPage.generate!(:wiki => wiki, :title => '2009\\02\\09') assert_equal page, wiki.find_page('2009\\02\\09') end + def test_find_page_without_redirect + wiki = Wiki.find(1) + page = wiki.find_page('Another_page') + assert_not_nil page + assert_equal 'Another_page', page.title + assert_equal false, wiki.page_found_with_redirect? + end + + def test_find_page_with_redirect + wiki = Wiki.find(1) + WikiRedirect.create!(:wiki => wiki, :title => 'Old_title', :redirects_to => 'Another_page') + page = wiki.find_page('Old_title') + assert_not_nil page + assert_equal 'Another_page', page.title + assert_equal true, wiki.page_found_with_redirect? + end + def test_titleize assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES') assert_equal 'テスト', Wiki.titleize('テスト') |