annotate .svn/pristine/62/62d25b06b15c0b260279da71be5d88bfab79f61e.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19
Chris@909 20 class WikiPageTest < ActiveSupport::TestCase
Chris@909 21 fixtures :projects, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
Chris@909 22
Chris@909 23 def setup
Chris@909 24 @wiki = Wiki.find(1)
Chris@909 25 @page = @wiki.pages.first
Chris@909 26 end
Chris@909 27
Chris@909 28 def test_create
Chris@909 29 page = WikiPage.new(:wiki => @wiki)
Chris@909 30 assert !page.save
Chris@909 31 assert_equal 1, page.errors.count
Chris@909 32
Chris@909 33 page.title = "Page"
Chris@909 34 assert page.save
Chris@909 35 page.reload
Chris@909 36 assert !page.protected?
Chris@909 37
Chris@909 38 @wiki.reload
Chris@909 39 assert @wiki.pages.include?(page)
Chris@909 40 end
Chris@909 41
Chris@909 42 def test_sidebar_should_be_protected_by_default
Chris@909 43 page = @wiki.find_or_new_page('sidebar')
Chris@909 44 assert page.new_record?
Chris@909 45 assert page.protected?
Chris@909 46 end
Chris@909 47
Chris@909 48 def test_find_or_new_page
Chris@909 49 page = @wiki.find_or_new_page("CookBook documentation")
Chris@909 50 assert_kind_of WikiPage, page
Chris@909 51 assert !page.new_record?
Chris@909 52
Chris@909 53 page = @wiki.find_or_new_page("Non existing page")
Chris@909 54 assert_kind_of WikiPage, page
Chris@909 55 assert page.new_record?
Chris@909 56 end
Chris@909 57
Chris@909 58 def test_parent_title
Chris@909 59 page = WikiPage.find_by_title('Another_page')
Chris@909 60 assert_nil page.parent_title
Chris@909 61
Chris@909 62 page = WikiPage.find_by_title('Page_with_an_inline_image')
Chris@909 63 assert_equal 'CookBook documentation', page.parent_title
Chris@909 64 end
Chris@909 65
Chris@909 66 def test_assign_parent
Chris@909 67 page = WikiPage.find_by_title('Another_page')
Chris@909 68 page.parent_title = 'CookBook documentation'
Chris@909 69 assert page.save
Chris@909 70 page.reload
Chris@909 71 assert_equal WikiPage.find_by_title('CookBook_documentation'), page.parent
Chris@909 72 end
Chris@909 73
Chris@909 74 def test_unassign_parent
Chris@909 75 page = WikiPage.find_by_title('Page_with_an_inline_image')
Chris@909 76 page.parent_title = ''
Chris@909 77 assert page.save
Chris@909 78 page.reload
Chris@909 79 assert_nil page.parent
Chris@909 80 end
Chris@909 81
Chris@909 82 def test_parent_validation
Chris@909 83 page = WikiPage.find_by_title('CookBook_documentation')
Chris@909 84
Chris@909 85 # A page that doesn't exist
Chris@909 86 page.parent_title = 'Unknown title'
Chris@909 87 assert !page.save
Chris@909 88 assert_equal I18n.translate('activerecord.errors.messages.invalid'), page.errors.on(:parent_title)
Chris@909 89 # A child page
Chris@909 90 page.parent_title = 'Page_with_an_inline_image'
Chris@909 91 assert !page.save
Chris@909 92 assert_equal I18n.translate('activerecord.errors.messages.circular_dependency'), page.errors.on(:parent_title)
Chris@909 93 # The page itself
Chris@909 94 page.parent_title = 'CookBook_documentation'
Chris@909 95 assert !page.save
Chris@909 96 assert_equal I18n.translate('activerecord.errors.messages.circular_dependency'), page.errors.on(:parent_title)
Chris@909 97
Chris@909 98 page.parent_title = 'Another_page'
Chris@909 99 assert page.save
Chris@909 100 end
Chris@909 101
Chris@909 102 def test_destroy
Chris@909 103 page = WikiPage.find(1)
Chris@909 104 page.destroy
Chris@909 105 assert_nil WikiPage.find_by_id(1)
Chris@909 106 # make sure that page content and its history are deleted
Chris@909 107 assert WikiContent.find_all_by_page_id(1).empty?
Chris@909 108 assert WikiContent.versioned_class.find_all_by_page_id(1).empty?
Chris@909 109 end
Chris@909 110
Chris@909 111 def test_destroy_should_not_nullify_children
Chris@909 112 page = WikiPage.find(2)
Chris@909 113 child_ids = page.child_ids
Chris@909 114 assert child_ids.any?
Chris@909 115 page.destroy
Chris@909 116 assert_nil WikiPage.find_by_id(2)
Chris@909 117
Chris@909 118 children = WikiPage.find_all_by_id(child_ids)
Chris@909 119 assert_equal child_ids.size, children.size
Chris@909 120 children.each do |child|
Chris@909 121 assert_nil child.parent_id
Chris@909 122 end
Chris@909 123 end
Chris@909 124
Chris@909 125 def test_updated_on_eager_load
Chris@909 126 page = WikiPage.with_updated_on.first
Chris@909 127 assert page.is_a?(WikiPage)
Chris@909 128 assert_not_nil page.read_attribute(:updated_on)
Chris@909 129 assert_equal page.content.updated_on, page.updated_on
Chris@909 130 end
Chris@909 131 end