kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
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.
147 lines
4.5 KiB
147 lines
4.5 KiB
13 years ago
|
#-- encoding: UTF-8
|
||
14 years ago
|
#-- copyright
|
||
12 years ago
|
# OpenProject is a project management system.
|
||
10 years ago
|
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
14 years ago
|
#
|
||
18 years ago
|
# This program is free software; you can redistribute it and/or
|
||
12 years ago
|
# modify it under the terms of the GNU General Public License version 3.
|
||
14 years ago
|
#
|
||
11 years ago
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
#
|
||
14 years ago
|
# See doc/COPYRIGHT.rdoc for more details.
|
||
|
#++
|
||
10 years ago
|
require 'legacy_spec_helper'
|
||
18 years ago
|
|
||
11 years ago
|
describe WikiPage, type: :model do
|
||
12 years ago
|
fixtures :all
|
||
18 years ago
|
|
||
11 years ago
|
before do
|
||
18 years ago
|
@wiki = Wiki.find(1)
|
||
|
@page = @wiki.pages.first
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should create' do
|
||
10 years ago
|
page = WikiPage.new(wiki: @wiki)
|
||
18 years ago
|
assert !page.save
|
||
|
assert_equal 1, page.errors.count
|
||
14 years ago
|
|
||
10 years ago
|
page.title = 'Page'
|
||
18 years ago
|
assert page.save
|
||
|
page.reload
|
||
15 years ago
|
assert !page.protected?
|
||
14 years ago
|
|
||
18 years ago
|
@wiki.reload
|
||
15 years ago
|
assert @wiki.pages.include?(page)
|
||
18 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should sidebar should be protected by default' do
|
||
15 years ago
|
page = @wiki.find_or_new_page('sidebar')
|
||
|
assert page.new_record?
|
||
|
assert page.protected?
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should find or new page' do
|
||
10 years ago
|
page = @wiki.find_or_new_page('CookBook documentation')
|
||
18 years ago
|
assert_kind_of WikiPage, page
|
||
|
assert !page.new_record?
|
||
14 years ago
|
|
||
10 years ago
|
page = @wiki.find_or_new_page('Non existing page')
|
||
18 years ago
|
assert_kind_of WikiPage, page
|
||
|
assert page.new_record?
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should parent title' do
|
||
10 years ago
|
page = WikiPage.find_by(title: 'Another_page')
|
||
17 years ago
|
assert_nil page.parent_title
|
||
14 years ago
|
|
||
10 years ago
|
page = WikiPage.find_by(title: 'Page_with_an_inline_image')
|
||
17 years ago
|
assert_equal 'CookBook documentation', page.parent_title
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should assign parent' do
|
||
10 years ago
|
page = WikiPage.find_by(title: 'Another_page')
|
||
17 years ago
|
page.parent_title = 'CookBook documentation'
|
||
|
assert page.save
|
||
|
page.reload
|
||
10 years ago
|
assert_equal WikiPage.find_by(title: 'CookBook_documentation'), page.parent
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should unassign parent' do
|
||
10 years ago
|
page = WikiPage.find_by(title: 'Page_with_an_inline_image')
|
||
17 years ago
|
page.parent_title = ''
|
||
|
assert page.save
|
||
|
page.reload
|
||
|
assert_nil page.parent
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should parent validation' do
|
||
10 years ago
|
page = WikiPage.find_by(title: 'CookBook_documentation')
|
||
14 years ago
|
|
||
17 years ago
|
# A page that doesn't exist
|
||
|
page.parent_title = 'Unknown title'
|
||
|
assert !page.save
|
||
10 years ago
|
assert_includes page.errors[:parent_title], I18n.translate('activerecord.errors.messages.invalid')
|
||
17 years ago
|
# A child page
|
||
|
page.parent_title = 'Page_with_an_inline_image'
|
||
|
assert !page.save
|
||
10 years ago
|
assert_includes page.errors[:parent_title], I18n.translate('activerecord.errors.messages.circular_dependency')
|
||
17 years ago
|
# The page itself
|
||
|
page.parent_title = 'CookBook_documentation'
|
||
|
assert !page.save
|
||
10 years ago
|
assert_includes page.errors[:parent_title], I18n.translate('activerecord.errors.messages.circular_dependency')
|
||
17 years ago
|
|
||
|
page.parent_title = 'Another_page'
|
||
|
assert page.save
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should destroy' do
|
||
18 years ago
|
page = WikiPage.find(1)
|
||
10 years ago
|
content_ids = WikiContent.where(page_id: 1).map(&:id)
|
||
18 years ago
|
page.destroy
|
||
10 years ago
|
assert_nil WikiPage.find_by(id: 1)
|
||
18 years ago
|
# make sure that page content and its history are deleted
|
||
10 years ago
|
assert WikiContent.where(page_id: 1).empty?
|
||
14 years ago
|
content_ids.each do |wiki_content_id|
|
||
10 years ago
|
assert Journal.where(journable_type: WikiContent,
|
||
|
journable_id: wiki_content_id)
|
||
14 years ago
|
end
|
||
18 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should destroy should not nullify children' do
|
||
16 years ago
|
page = WikiPage.find(2)
|
||
|
child_ids = page.child_ids
|
||
|
assert child_ids.any?
|
||
|
page.destroy
|
||
10 years ago
|
assert_nil WikiPage.find_by(id: 2)
|
||
14 years ago
|
|
||
10 years ago
|
children = WikiPage.where(id: child_ids)
|
||
16 years ago
|
assert_equal child_ids.size, children.size
|
||
|
children.each do |child|
|
||
|
assert_nil child.parent_id
|
||
|
end
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should updated on eager load' do
|
||
14 years ago
|
page = WikiPage.with_updated_on.first
|
||
|
assert page.is_a?(WikiPage)
|
||
9 years ago
|
refute_nil page.read_attribute(:updated_on)
|
||
14 years ago
|
assert_equal page.content.updated_on, page.updated_on
|
||
|
end
|
||
18 years ago
|
end
|