You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wiki_redirect_test.rb 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 Jean-Philippe Lang
  3. #
  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.
  17. require File.expand_path('../../test_helper', __FILE__)
  18. class WikiRedirectTest < ActiveSupport::TestCase
  19. fixtures :projects, :wikis, :wiki_pages
  20. def setup
  21. @wiki = Wiki.find(1)
  22. @original = WikiPage.create(:wiki => @wiki, :title => 'Original title')
  23. end
  24. def test_create_redirect
  25. @original.title = 'New title'
  26. assert @original.save
  27. @original.reload
  28. assert_equal 'New_title', @original.title
  29. assert @wiki.redirects.find_by_title('Original_title')
  30. assert @wiki.find_page('Original title')
  31. assert @wiki.find_page('ORIGINAL title')
  32. end
  33. def test_update_redirect
  34. # create a redirect that point to this page
  35. assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
  36. @original.title = 'New title'
  37. @original.save
  38. # make sure the old page now points to the new page
  39. assert_equal 'New_title', @wiki.find_page('An old page').title
  40. end
  41. def test_reverse_rename
  42. # create a redirect that point to this page
  43. assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
  44. @original.title = 'An old page'
  45. @original.save
  46. assert !@wiki.redirects.find_by_title_and_redirects_to('An_old_page', 'An_old_page')
  47. assert @wiki.redirects.find_by_title_and_redirects_to('Original_title', 'An_old_page')
  48. end
  49. def test_rename_to_already_redirected
  50. assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Other_page')
  51. @original.title = 'An old page'
  52. @original.save
  53. # this redirect have to be removed since 'An old page' page now exists
  54. assert !@wiki.redirects.find_by_title_and_redirects_to('An_old_page', 'Other_page')
  55. end
  56. def test_redirects_removed_when_deleting_page
  57. assert WikiRedirect.create(:wiki => @wiki, :title => 'An_old_page', :redirects_to => 'Original_title')
  58. @original.destroy
  59. assert_nil @wiki.redirects.first
  60. end
  61. end