1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 require File.dirname(__FILE__) + '/../test_helper'
20 class WikiRedirectTest < ActiveSupport::TestCase
21 fixtures :projects, :wikis
25 @original = WikiPage.create(:wiki => @wiki, :title => 'Original title')
28 def test_create_redirect
29 @original.title = 'New title'
33 assert_equal 'New_title', @original.title
34 assert @wiki.redirects.find_by_title('Original_title')
35 assert @wiki.find_page('Original title')
38 def test_update_redirect
39 # create a redirect that point to this page
40 assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
42 @original.title = 'New title'
44 # make sure the old page now points to the new page
45 assert_equal 'New_title', @wiki.find_page('An old page').title
48 def test_reverse_rename
49 # create a redirect that point to this page
50 assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
52 @original.title = 'An old page'
54 assert !@wiki.redirects.find_by_title_and_redirects_to('An_old_page', 'An_old_page')
55 assert @wiki.redirects.find_by_title_and_redirects_to('Original_title', 'An_old_page')
58 def test_rename_to_already_redirected
59 assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Other_page')
61 @original.title = 'An old page'
63 # this redirect have to be removed since 'An old page' page now exists
64 assert !@wiki.redirects.find_by_title_and_redirects_to('An_old_page', 'Other_page')
67 def test_redirects_removed_when_deleting_page
68 assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
71 assert !@wiki.redirects.find(:first)