annotate test/unit/wiki_test.rb @ 1082:997f6d7738f7 bug_531

In repo controller entry action, show the page for the file even if it's binary (so user still has access to history etc links). This makes it possible to use the entry action as the default when a file is clicked on
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 22 Nov 2012 18:04:17 +0000
parents 753f1380d6bc
children bb32da3bea34
rev   line source
Chris@0 1 # encoding: utf-8
Chris@0 2 #
Chris@441 3 # Redmine - project management software
Chris@441 4 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@0 5 #
Chris@0 6 # This program is free software; you can redistribute it and/or
Chris@0 7 # modify it under the terms of the GNU General Public License
Chris@0 8 # as published by the Free Software Foundation; either version 2
Chris@0 9 # of the License, or (at your option) any later version.
Chris@441 10 #
Chris@0 11 # This program is distributed in the hope that it will be useful,
Chris@0 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 14 # GNU General Public License for more details.
Chris@441 15 #
Chris@0 16 # You should have received a copy of the GNU General Public License
Chris@0 17 # along with this program; if not, write to the Free Software
Chris@0 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 19
Chris@119 20 require File.expand_path('../../test_helper', __FILE__)
Chris@0 21
Chris@0 22 class WikiTest < ActiveSupport::TestCase
Chris@441 23 fixtures :projects, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
Chris@441 24
Chris@0 25 def test_create
Chris@0 26 wiki = Wiki.new(:project => Project.find(2))
Chris@0 27 assert !wiki.save
Chris@0 28 assert_equal 1, wiki.errors.count
Chris@441 29
Chris@0 30 wiki.start_page = "Start page"
Chris@0 31 assert wiki.save
Chris@0 32 end
Chris@0 33
Chris@0 34 def test_update
Chris@0 35 @wiki = Wiki.find(1)
Chris@0 36 @wiki.start_page = "Another start page"
Chris@0 37 assert @wiki.save
Chris@0 38 @wiki.reload
Chris@0 39 assert_equal "Another start page", @wiki.start_page
Chris@0 40 end
Chris@441 41
Chris@441 42 def test_find_page_should_not_be_case_sensitive
Chris@119 43 wiki = Wiki.find(1)
Chris@119 44 page = WikiPage.find(2)
Chris@441 45
Chris@119 46 assert_equal page, wiki.find_page('Another_page')
Chris@119 47 assert_equal page, wiki.find_page('Another page')
Chris@119 48 assert_equal page, wiki.find_page('ANOTHER page')
Chris@441 49 end
Chris@441 50
Chris@441 51 def test_find_page_with_cyrillic_characters
Chris@441 52 wiki = Wiki.find(1)
Chris@119 53 page = WikiPage.find(10)
Chris@119 54 assert_equal page, wiki.find_page('Этика_менеджмента')
Chris@119 55 end
Chris@441 56
Chris@441 57 def test_find_page_with_backslashes
Chris@441 58 wiki = Wiki.find(1)
Chris@441 59 page = WikiPage.generate!(:wiki => wiki, :title => '2009\\02\\09')
Chris@441 60 assert_equal page, wiki.find_page('2009\\02\\09')
Chris@441 61 end
Chris@441 62
Chris@441 63 def test_find_page_without_redirect
Chris@441 64 wiki = Wiki.find(1)
Chris@441 65 page = wiki.find_page('Another_page')
Chris@441 66 assert_not_nil page
Chris@441 67 assert_equal 'Another_page', page.title
Chris@441 68 assert_equal false, wiki.page_found_with_redirect?
Chris@441 69 end
Chris@441 70
Chris@441 71 def test_find_page_with_redirect
Chris@441 72 wiki = Wiki.find(1)
Chris@441 73 WikiRedirect.create!(:wiki => wiki, :title => 'Old_title', :redirects_to => 'Another_page')
Chris@441 74 page = wiki.find_page('Old_title')
Chris@441 75 assert_not_nil page
Chris@441 76 assert_equal 'Another_page', page.title
Chris@441 77 assert_equal true, wiki.page_found_with_redirect?
Chris@441 78 end
Chris@441 79
Chris@0 80 def test_titleize
Chris@0 81 assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
Chris@0 82 assert_equal 'テスト', Wiki.titleize('テスト')
Chris@0 83 end
Chris@441 84
Chris@0 85 context "#sidebar" do
Chris@0 86 setup do
Chris@0 87 @wiki = Wiki.find(1)
Chris@0 88 end
Chris@441 89
Chris@0 90 should "return nil if undefined" do
Chris@0 91 assert_nil @wiki.sidebar
Chris@0 92 end
Chris@441 93
Chris@0 94 should "return a WikiPage if defined" do
Chris@0 95 page = @wiki.pages.new(:title => 'Sidebar')
Chris@0 96 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
Chris@0 97 page.save!
Chris@441 98
Chris@0 99 assert_kind_of WikiPage, @wiki.sidebar
Chris@0 100 assert_equal 'Sidebar', @wiki.sidebar.title
Chris@0 101 end
Chris@0 102 end
Chris@0 103 end