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.
304 lines
11 KiB
304 lines
11 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
|
#
|
||
15 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'
|
||
15 years ago
|
|
||
11 years ago
|
describe 'IssueNestedSet', type: :model do
|
||
12 years ago
|
include MiniTest::Assertions # refute
|
||
|
|
||
12 years ago
|
fixtures :all
|
||
15 years ago
|
|
||
|
self.use_transactional_fixtures = false
|
||
14 years ago
|
|
||
11 years ago
|
before do
|
||
11 years ago
|
WorkPackage.delete_all
|
||
12 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should creating a child in different project should not validate unless allowed' do
|
||
10 years ago
|
Setting.cross_project_work_package_relations = '0'
|
||
15 years ago
|
issue = create_issue!
|
||
11 years ago
|
child = WorkPackage.new.tap do |i|
|
||
10 years ago
|
i.force_attributes = { project_id: 2,
|
||
|
type_id: 1,
|
||
|
author_id: 1,
|
||
|
subject: 'child',
|
||
|
parent_id: issue.id }
|
||
13 years ago
|
end
|
||
15 years ago
|
assert !child.save
|
||
11 years ago
|
refute_empty child.errors[:parent_id]
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should creating a child in different project should validate if allowed' do
|
||
10 years ago
|
Setting.cross_project_work_package_relations = '1'
|
||
13 years ago
|
issue = create_issue!
|
||
11 years ago
|
child = WorkPackage.new.tap do |i|
|
||
10 years ago
|
i.force_attributes = { project_id: 2,
|
||
|
type_id: 1,
|
||
|
author_id: 1,
|
||
|
subject: 'child',
|
||
|
parent_id: issue.id }
|
||
13 years ago
|
end
|
||
|
assert child.save
|
||
11 years ago
|
assert_empty child.errors[:parent_id]
|
||
13 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should invalid move to another project' do
|
||
15 years ago
|
parent1 = create_issue!
|
||
10 years ago
|
child = create_issue!(parent_id: parent1.id)
|
||
|
grandchild = create_issue!(parent_id: child.id, type_id: 2)
|
||
11 years ago
|
Project.find(2).type_ids = [1]
|
||
14 years ago
|
|
||
15 years ago
|
parent1.reload
|
||
14 years ago
|
assert_equal [1, parent1.id, 5], [parent1.project_id, parent1.root_id, parent1.nested_set_span]
|
||
14 years ago
|
|
||
11 years ago
|
# child can not be moved to Project 2 because its child is on a disabled type
|
||
9 years ago
|
service = MoveWorkPackageService.new(child, User.current)
|
||
|
assert_equal false, service.call(Project.find(2))
|
||
15 years ago
|
child.reload
|
||
|
grandchild.reload
|
||
|
parent1.reload
|
||
14 years ago
|
|
||
15 years ago
|
# no change
|
||
14 years ago
|
assert_equal [1, parent1.id, 5], [parent1.project_id, parent1.root_id, parent1.nested_set_span]
|
||
|
assert_equal [1, parent1.id, 3], [child.project_id, child.root_id, child.nested_set_span]
|
||
|
assert_equal [1, parent1.id, 1], [grandchild.project_id, grandchild.root_id, grandchild.nested_set_span]
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should moving an to a descendant should not validate' do
|
||
15 years ago
|
parent1 = create_issue!
|
||
|
parent2 = create_issue!
|
||
10 years ago
|
child = create_issue!(parent_id: parent1.id)
|
||
|
grandchild = create_issue!(parent_id: child.id)
|
||
14 years ago
|
|
||
15 years ago
|
child.reload
|
||
11 years ago
|
child.parent_id = grandchild.id
|
||
15 years ago
|
assert !child.save
|
||
11 years ago
|
refute_empty child.errors[:parent_id]
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should moving an issue should keep valid relations only' do
|
||
15 years ago
|
issue1 = create_issue!
|
||
|
issue2 = create_issue!
|
||
10 years ago
|
issue3 = create_issue!(parent_id: issue2.id)
|
||
15 years ago
|
issue4 = create_issue!
|
||
11 years ago
|
(r1 = Relation.new.tap do |i|
|
||
10 years ago
|
i.force_attributes = { from: issue1,
|
||
|
to: issue2,
|
||
|
relation_type: Relation::TYPE_PRECEDES }
|
||
13 years ago
|
end).save!
|
||
11 years ago
|
(r2 = Relation.new.tap do |i|
|
||
10 years ago
|
i.force_attributes = { from: issue1,
|
||
|
to: issue3,
|
||
|
relation_type: Relation::TYPE_PRECEDES }
|
||
13 years ago
|
end).save!
|
||
11 years ago
|
(r3 = Relation.new.tap do |i|
|
||
10 years ago
|
i.force_attributes = { from: issue2,
|
||
|
to: issue4,
|
||
|
relation_type: Relation::TYPE_PRECEDES }
|
||
13 years ago
|
end).save!
|
||
15 years ago
|
issue2.reload
|
||
11 years ago
|
issue2.parent_id = issue1.id
|
||
15 years ago
|
issue2.save!
|
||
11 years ago
|
assert !Relation.exists?(r1.id)
|
||
|
assert !Relation.exists?(r2.id)
|
||
|
assert Relation.exists?(r3.id)
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should destroy should destroy children' do
|
||
15 years ago
|
issue1 = create_issue!
|
||
|
issue2 = create_issue!
|
||
10 years ago
|
issue3 = create_issue!(parent_id: issue2.id)
|
||
|
issue4 = create_issue!(parent_id: issue1.id)
|
||
14 years ago
|
|
||
11 years ago
|
issue3.add_journal(User.find(2))
|
||
14 years ago
|
issue3.subject = 'child with journal'
|
||
|
issue3.save!
|
||
14 years ago
|
|
||
11 years ago
|
assert_difference 'WorkPackage.count', -2 do
|
||
10 years ago
|
# FIXME: wrong result returned for Journal.count
|
||
|
# assert_difference 'Journal.count', -3 do
|
||
|
WorkPackage.find(issue2.id).destroy
|
||
|
# end
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
15 years ago
|
issue1.reload
|
||
|
issue4.reload
|
||
11 years ago
|
assert !WorkPackage.exists?(issue2.id)
|
||
|
assert !WorkPackage.exists?(issue3.id)
|
||
14 years ago
|
assert_equal [issue1.id, 3], [issue1.root_id, issue1.nested_set_span]
|
||
|
assert_equal [issue1.id, 1], [issue4.root_id, issue4.nested_set_span]
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should destroy parent work package updated during children destroy' do
|
||
14 years ago
|
parent = create_issue!
|
||
10 years ago
|
create_issue!(start_date: Date.today, parent_id: parent.id)
|
||
|
create_issue!(start_date: 2.days.from_now, parent_id: parent.id)
|
||
14 years ago
|
|
||
11 years ago
|
assert_difference 'WorkPackage.count', -3 do
|
||
|
WorkPackage.find(parent.id).destroy
|
||
14 years ago
|
end
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should destroy child issue with children' do
|
||
10 years ago
|
root = create_issue!(project_id: 1, author_id: 2, type_id: 1, subject: 'root').reload
|
||
|
child = create_issue!(project_id: 1, author_id: 2, type_id: 1, subject: 'child', parent_id: root.id).reload
|
||
|
leaf = create_issue!(project_id: 1, author_id: 2, type_id: 1, subject: 'leaf', parent_id: child.id).reload
|
||
11 years ago
|
leaf.add_journal(User.find(2))
|
||
14 years ago
|
leaf.subject = 'leaf with journal'
|
||
|
leaf.save!
|
||
14 years ago
|
|
||
14 years ago
|
total_journals_on_children = leaf.reload.journals.count + child.reload.journals.count
|
||
11 years ago
|
assert_difference 'WorkPackage.count', -2 do
|
||
11 years ago
|
assert_difference 'Journal.count', -total_journals_on_children do
|
||
11 years ago
|
WorkPackage.find(child.id).destroy
|
||
14 years ago
|
end
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
root = WorkPackage.find(root.id)
|
||
14 years ago
|
assert root.leaf?, "Root issue is not a leaf (lft: #{root.lft}, rgt: #{root.rgt})"
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should destroy issue with grand child' do
|
||
13 years ago
|
parent = create_issue!
|
||
10 years ago
|
issue = create_issue!(parent_id: parent.id)
|
||
|
child = create_issue!(parent_id: issue.id)
|
||
|
grandchild1 = create_issue!(parent_id: child.id)
|
||
|
grandchild2 = create_issue!(parent_id: child.id)
|
||
13 years ago
|
|
||
11 years ago
|
assert_difference 'WorkPackage.count', -4 do
|
||
|
WorkPackage.find(issue.id).destroy
|
||
13 years ago
|
parent.reload
|
||
12 years ago
|
assert_equal [1, 2], [parent.lft, parent.rgt], 'parent should not have children'
|
||
13 years ago
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should parent priority should be the highest child priority' do
|
||
10 years ago
|
parent = create_issue!(priority: IssuePriority.find_by(name: 'Normal'))
|
||
15 years ago
|
# Create children
|
||
10 years ago
|
child1 = create_issue!(priority: IssuePriority.find_by(name: 'High'), parent_id: parent.id)
|
||
15 years ago
|
assert_equal 'High', parent.reload.priority.name
|
||
10 years ago
|
child2 = create_issue!(priority: IssuePriority.find_by(name: 'Immediate'), parent_id: child1.id)
|
||
15 years ago
|
assert_equal 'Immediate', child1.reload.priority.name
|
||
|
assert_equal 'Immediate', parent.reload.priority.name
|
||
10 years ago
|
child3 = create_issue!(priority: IssuePriority.find_by(name: 'Low'), parent_id: parent.id)
|
||
15 years ago
|
assert_equal 'Immediate', parent.reload.priority.name
|
||
|
# Destroy a child
|
||
|
child1.destroy
|
||
|
assert_equal 'Low', parent.reload.priority.name
|
||
|
# Update a child
|
||
10 years ago
|
child3.reload.priority = IssuePriority.find_by(name: 'Normal')
|
||
15 years ago
|
child3.save!
|
||
|
assert_equal 'Normal', parent.reload.priority.name
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should parent dates should be lowest start and highest due dates' do
|
||
15 years ago
|
parent = create_issue!
|
||
10 years ago
|
create_issue!(start_date: '2010-01-25', due_date: '2010-02-15', parent_id: parent.id)
|
||
10 years ago
|
create_issue!(due_date: '2010-02-13', parent_id: parent.id)
|
||
10 years ago
|
create_issue!(start_date: '2010-02-01', due_date: '2010-02-22', parent_id: parent.id)
|
||
15 years ago
|
parent.reload
|
||
|
assert_equal Date.parse('2010-01-25'), parent.start_date
|
||
|
assert_equal Date.parse('2010-02-22'), parent.due_date
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should parent done ratio should be average done ratio of leaves' do
|
||
15 years ago
|
parent = create_issue!
|
||
10 years ago
|
create_issue!(done_ratio: 20, parent_id: parent.id)
|
||
15 years ago
|
assert_equal 20, parent.reload.done_ratio
|
||
10 years ago
|
create_issue!(done_ratio: 70, parent_id: parent.id)
|
||
15 years ago
|
assert_equal 45, parent.reload.done_ratio
|
||
14 years ago
|
|
||
10 years ago
|
child = create_issue!(done_ratio: 0, parent_id: parent.id)
|
||
15 years ago
|
assert_equal 30, parent.reload.done_ratio
|
||
14 years ago
|
|
||
10 years ago
|
create_issue!(done_ratio: 30, parent_id: child.id)
|
||
15 years ago
|
assert_equal 30, child.reload.done_ratio
|
||
|
assert_equal 40, parent.reload.done_ratio
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should parent done ratio should be weighted by estimated times if any' do
|
||
15 years ago
|
parent = create_issue!
|
||
10 years ago
|
create_issue!(estimated_hours: 10, done_ratio: 20, parent_id: parent.id)
|
||
15 years ago
|
assert_equal 20, parent.reload.done_ratio
|
||
10 years ago
|
create_issue!(estimated_hours: 20, done_ratio: 50, parent_id: parent.id)
|
||
15 years ago
|
assert_equal (50 * 20 + 20 * 10) / 30, parent.reload.done_ratio
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should parent estimate should be sum of leaves' do
|
||
15 years ago
|
parent = create_issue!
|
||
10 years ago
|
create_issue!(estimated_hours: nil, parent_id: parent.id)
|
||
15 years ago
|
assert_equal nil, parent.reload.estimated_hours
|
||
10 years ago
|
create_issue!(estimated_hours: 5, parent_id: parent.id)
|
||
15 years ago
|
assert_equal 5, parent.reload.estimated_hours
|
||
10 years ago
|
create_issue!(estimated_hours: 7, parent_id: parent.id)
|
||
15 years ago
|
assert_equal 12, parent.reload.estimated_hours
|
||
|
end
|
||
15 years ago
|
|
||
11 years ago
|
it 'should move parent updates old parent attributes' do
|
||
15 years ago
|
first_parent = create_issue!
|
||
|
second_parent = create_issue!
|
||
10 years ago
|
child = create_issue!(estimated_hours: 5,
|
||
|
parent_id: first_parent.id)
|
||
15 years ago
|
assert_equal 5, first_parent.reload.estimated_hours
|
||
10 years ago
|
child.update_attributes(estimated_hours: 7,
|
||
|
parent_id: second_parent.id)
|
||
15 years ago
|
assert_equal 7, second_parent.reload.estimated_hours
|
||
|
assert_nil first_parent.reload.estimated_hours
|
||
|
end
|
||
15 years ago
|
|
||
11 years ago
|
it 'should project copy should copy issue tree' do
|
||
12 years ago
|
Project.delete_all # make sure unqiue identifiers
|
||
10 years ago
|
p = Project.create!(name: 'Tree copy', identifier: 'tree-copy', type_ids: [1, 2])
|
||
|
i1 = create_issue!(project_id: p.id, subject: 'i1')
|
||
|
i2 = create_issue!(project_id: p.id, subject: 'i2', parent_id: i1.id)
|
||
|
i3 = create_issue!(project_id: p.id, subject: 'i3', parent_id: i1.id)
|
||
|
i4 = create_issue!(project_id: p.id, subject: 'i4', parent_id: i2.id)
|
||
|
i5 = create_issue!(project_id: p.id, subject: 'i5')
|
||
|
c = Project.new(name: 'Copy', identifier: 'copy', type_ids: [1, 2])
|
||
|
c.copy(p, only: 'work_packages')
|
||
15 years ago
|
c.reload
|
||
14 years ago
|
|
||
12 years ago
|
assert_equal 5, c.work_packages.count
|
||
|
ic1, ic2, ic3, ic4, ic5 = c.work_packages.reorder('subject')
|
||
15 years ago
|
assert ic1.root?
|
||
|
assert_equal ic1, ic2.parent
|
||
|
assert_equal ic1, ic3.parent
|
||
|
assert_equal ic2, ic4.parent
|
||
|
assert ic5.root?
|
||
|
end
|
||
14 years ago
|
|
||
15 years ago
|
# Helper that creates an issue with default attributes
|
||
10 years ago
|
def create_issue!(attributes = {})
|
||
11 years ago
|
(i = WorkPackage.new.tap do |i|
|
||
10 years ago
|
attr = { project_id: 1, type_id: 1, author_id: 1, subject: 'test' }.merge(attributes)
|
||
13 years ago
|
i.force_attributes = attr
|
||
|
end).save!
|
||
13 years ago
|
i
|
||
15 years ago
|
end
|
||
|
end
|