annotate .svn/pristine/97/97c4e61eb96a430bca8ac46188b3b83b65ee3992.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1517 19
Chris@1517 20 class WikiPageTest < ActiveSupport::TestCase
Chris@1517 21 fixtures :projects, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
Chris@1517 22
Chris@1517 23 def setup
Chris@1517 24 @wiki = Wiki.find(1)
Chris@1517 25 @page = @wiki.pages.first
Chris@1517 26 end
Chris@1517 27
Chris@1517 28 def test_create
Chris@1517 29 page = WikiPage.new(:wiki => @wiki)
Chris@1517 30 assert !page.save
Chris@1517 31 assert_equal 1, page.errors.count
Chris@1517 32
Chris@1517 33 page.title = "Page"
Chris@1517 34 assert page.save
Chris@1517 35 page.reload
Chris@1517 36 assert !page.protected?
Chris@1517 37
Chris@1517 38 @wiki.reload
Chris@1517 39 assert @wiki.pages.include?(page)
Chris@1517 40 end
Chris@1517 41
Chris@1517 42 def test_sidebar_should_be_protected_by_default
Chris@1517 43 page = @wiki.find_or_new_page('sidebar')
Chris@1517 44 assert page.new_record?
Chris@1517 45 assert page.protected?
Chris@1517 46 end
Chris@1517 47
Chris@1517 48 def test_find_or_new_page
Chris@1517 49 page = @wiki.find_or_new_page("CookBook documentation")
Chris@1517 50 assert_kind_of WikiPage, page
Chris@1517 51 assert !page.new_record?
Chris@1517 52
Chris@1517 53 page = @wiki.find_or_new_page("Non existing page")
Chris@1517 54 assert_kind_of WikiPage, page
Chris@1517 55 assert page.new_record?
Chris@1517 56 end
Chris@1517 57
Chris@1517 58 def test_parent_title
Chris@1517 59 page = WikiPage.find_by_title('Another_page')
Chris@1517 60 assert_nil page.parent_title
Chris@1517 61
Chris@1517 62 page = WikiPage.find_by_title('Page_with_an_inline_image')
Chris@1517 63 assert_equal 'CookBook documentation', page.parent_title
Chris@1517 64 end
Chris@1517 65
Chris@1517 66 def test_assign_parent
Chris@1517 67 page = WikiPage.find_by_title('Another_page')
Chris@1517 68 page.parent_title = 'CookBook documentation'
Chris@1517 69 assert page.save
Chris@1517 70 page.reload
Chris@1517 71 assert_equal WikiPage.find_by_title('CookBook_documentation'), page.parent
Chris@1517 72 end
Chris@1517 73
Chris@1517 74 def test_unassign_parent
Chris@1517 75 page = WikiPage.find_by_title('Page_with_an_inline_image')
Chris@1517 76 page.parent_title = ''
Chris@1517 77 assert page.save
Chris@1517 78 page.reload
Chris@1517 79 assert_nil page.parent
Chris@1517 80 end
Chris@1517 81
Chris@1517 82 def test_parent_validation
Chris@1517 83 page = WikiPage.find_by_title('CookBook_documentation')
Chris@1517 84
Chris@1517 85 # A page that doesn't exist
Chris@1517 86 page.parent_title = 'Unknown title'
Chris@1517 87 assert !page.save
Chris@1517 88 assert_include I18n.translate('activerecord.errors.messages.invalid'),
Chris@1517 89 page.errors[:parent_title]
Chris@1517 90 # A child page
Chris@1517 91 page.parent_title = 'Page_with_an_inline_image'
Chris@1517 92 assert !page.save
Chris@1517 93 assert_include I18n.translate('activerecord.errors.messages.circular_dependency'),
Chris@1517 94 page.errors[:parent_title]
Chris@1517 95 # The page itself
Chris@1517 96 page.parent_title = 'CookBook_documentation'
Chris@1517 97 assert !page.save
Chris@1517 98 assert_include I18n.translate('activerecord.errors.messages.circular_dependency'),
Chris@1517 99 page.errors[:parent_title]
Chris@1517 100 page.parent_title = 'Another_page'
Chris@1517 101 assert page.save
Chris@1517 102 end
Chris@1517 103
Chris@1517 104 def test_destroy
Chris@1517 105 page = WikiPage.find(1)
Chris@1517 106 page.destroy
Chris@1517 107 assert_nil WikiPage.find_by_id(1)
Chris@1517 108 # make sure that page content and its history are deleted
Chris@1517 109 assert_equal 0, WikiContent.where(:page_id => 1).count
Chris@1517 110 assert_equal 0, WikiContent.versioned_class.where(:page_id => 1).count
Chris@1517 111 end
Chris@1517 112
Chris@1517 113 def test_destroy_should_not_nullify_children
Chris@1517 114 page = WikiPage.find(2)
Chris@1517 115 child_ids = page.child_ids
Chris@1517 116 assert child_ids.any?
Chris@1517 117 page.destroy
Chris@1517 118 assert_nil WikiPage.find_by_id(2)
Chris@1517 119
Chris@1517 120 children = WikiPage.where(:id => child_ids)
Chris@1517 121 assert_equal child_ids.size, children.count
Chris@1517 122 children.each do |child|
Chris@1517 123 assert_nil child.parent_id
Chris@1517 124 end
Chris@1517 125 end
Chris@1517 126
Chris@1517 127 def test_updated_on_eager_load
Chris@1517 128 page = WikiPage.with_updated_on.order('id').first
Chris@1517 129 assert page.is_a?(WikiPage)
Chris@1517 130 assert_not_nil page.read_attribute(:updated_on)
Chris@1517 131 assert_equal Time.gm(2007, 3, 6, 23, 10, 51), page.content.updated_on
Chris@1517 132 assert_equal page.content.updated_on, page.updated_on
Chris@1517 133 assert_not_nil page.read_attribute(:version)
Chris@1517 134 end
Chris@1517 135
Chris@1517 136 def test_descendants
Chris@1517 137 page = WikiPage.create!(:wiki => @wiki, :title => 'Parent')
Chris@1517 138 child1 = WikiPage.create!(:wiki => @wiki, :title => 'Child1', :parent => page)
Chris@1517 139 child11 = WikiPage.create!(:wiki => @wiki, :title => 'Child11', :parent => child1)
Chris@1517 140 child111 = WikiPage.create!(:wiki => @wiki, :title => 'Child111', :parent => child11)
Chris@1517 141 child2 = WikiPage.create!(:wiki => @wiki, :title => 'Child2', :parent => page)
Chris@1517 142
Chris@1517 143 assert_equal %w(Child1 Child11 Child111 Child2), page.descendants.map(&:title).sort
Chris@1517 144 assert_equal %w(Child1 Child11 Child111 Child2), page.descendants(nil).map(&:title).sort
Chris@1517 145 assert_equal %w(Child1 Child11 Child2), page.descendants(2).map(&:title).sort
Chris@1517 146 assert_equal %w(Child1 Child2), page.descendants(1).map(&:title).sort
Chris@1517 147
Chris@1517 148 assert_equal %w(Child1 Child11 Child111 Child2 Parent), page.self_and_descendants.map(&:title).sort
Chris@1517 149 assert_equal %w(Child1 Child11 Child111 Child2 Parent), page.self_and_descendants(nil).map(&:title).sort
Chris@1517 150 assert_equal %w(Child1 Child11 Child2 Parent), page.self_and_descendants(2).map(&:title).sort
Chris@1517 151 assert_equal %w(Child1 Child2 Parent), page.self_and_descendants(1).map(&:title).sort
Chris@1517 152 end
Chris@1517 153
Chris@1517 154 def test_diff_for_page_with_deleted_version_should_pick_the_previous_available_version
Chris@1517 155 WikiContent::Version.find_by_page_id_and_version(1, 2).destroy
Chris@1517 156
Chris@1517 157 page = WikiPage.find(1)
Chris@1517 158 diff = page.diff(3)
Chris@1517 159 assert_not_nil diff
Chris@1517 160 assert_equal 3, diff.content_to.version
Chris@1517 161 assert_equal 1, diff.content_from.version
Chris@1517 162 end
Chris@1517 163 end