;]
[askyou.git] / test / unit / wiki_redirect_test.rb
blob7e80638b2c235b4ccb7ea28cacf49edb274ec450
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.
8
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.
13
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
23   def setup
24     @wiki = Wiki.find(1)
25     @original = WikiPage.create(:wiki => @wiki, :title => 'Original title')
26   end
27   
28   def test_create_redirect
29     @original.title = 'New title'
30     assert @original.save
31     @original.reload
32     
33     assert_equal 'New_title', @original.title
34     assert @wiki.redirects.find_by_title('Original_title')
35     assert @wiki.find_page('Original title')
36   end
37   
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')
41     
42     @original.title = 'New title'
43     @original.save
44     # make sure the old page now points to the new page
45     assert_equal 'New_title', @wiki.find_page('An old page').title
46   end
47   
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'
53     @original.save
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')
56   end
57   
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'
62     @original.save
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')
65   end
66   
67   def test_redirects_removed_when_deleting_page
68     assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
69     
70     @original.destroy
71     assert !@wiki.redirects.find(:first)
72   end
73 end