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.
296 lines
11 KiB
296 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
|
#
|
||
16 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'
|
||
16 years ago
|
|
||
11 years ago
|
describe Version, type: :model do
|
||
12 years ago
|
fixtures :all
|
||
16 years ago
|
|
||
11 years ago
|
it 'should create' do
|
||
13 years ago
|
(v = Version.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project: Project.find(1), name: '1.1', effective_date: '2011-03-25' }
|
||
13 years ago
|
end)
|
||
16 years ago
|
assert v.save
|
||
15 years ago
|
assert_equal 'open', v.status
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should invalid effective date validation' do
|
||
13 years ago
|
(v = Version.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project: Project.find(1), name: '1.1', effective_date: '99999-01-01' }
|
||
13 years ago
|
end)
|
||
16 years ago
|
assert !v.save
|
||
10 years ago
|
assert_includes v.errors[:effective_date], I18n.translate('activerecord.errors.messages.not_a_date')
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context '#start_date' do
|
||
|
context 'with no value saved' do
|
||
11 years ago
|
it 'should be the date of the earlist issue' do
|
||
14 years ago
|
project = Project.find(1)
|
||
13 years ago
|
(v = Version.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project: project, name: 'Progress' }
|
||
13 years ago
|
end).save!
|
||
10 years ago
|
add_work_package(v, estimated_hours: 10, start_date: '2010-03-01')
|
||
|
FactoryGirl.create(:work_package, project: project, subject: 'not assigned', start_date: '2010-01-01')
|
||
14 years ago
|
|
||
|
assert_equal '2010-03-01', v.start_date.to_s
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
context 'with a value saved' do
|
||
11 years ago
|
it 'should be the value' do
|
||
14 years ago
|
project = Project.find(1)
|
||
13 years ago
|
(v = Version.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project: project, name: 'Progress', start_date: '2010-01-05' }
|
||
13 years ago
|
end).save!
|
||
|
|
||
10 years ago
|
add_work_package(v, estimated_hours: 10, start_date: '2010-03-01')
|
||
14 years ago
|
|
||
|
assert_equal '2010-01-05', v.start_date.to_s
|
||
|
end
|
||
|
end
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should progress should be 0 with no assigned issues' do
|
||
16 years ago
|
project = Project.find(1)
|
||
13 years ago
|
(v = Version.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project: project, name: 'Progress' }
|
||
13 years ago
|
end).save!
|
||
11 years ago
|
assert_equal 0, v.completed_percent
|
||
|
assert_equal 0, v.closed_percent
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should progress should be 0 with unbegun assigned issues' do
|
||
16 years ago
|
project = Project.find(1)
|
||
13 years ago
|
(v = Version.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project: project, name: 'Progress' }
|
||
13 years ago
|
end).save!
|
||
11 years ago
|
add_work_package(v)
|
||
10 years ago
|
add_work_package(v, done_ratio: 0)
|
||
11 years ago
|
assert_progress_equal 0, v.completed_percent
|
||
|
assert_progress_equal 0, v.closed_percent
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should progress should be 100 with closed assigned issues' do
|
||
16 years ago
|
project = Project.find(1)
|
||
10 years ago
|
status = Status.where(is_closed: true).first
|
||
13 years ago
|
(v = Version.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project: project, name: 'Progress' }
|
||
13 years ago
|
end).save!
|
||
10 years ago
|
add_work_package(v, status: status)
|
||
|
add_work_package(v, status: status, done_ratio: 20)
|
||
|
add_work_package(v, status: status, done_ratio: 70, estimated_hours: 25)
|
||
|
add_work_package(v, status: status, estimated_hours: 15)
|
||
11 years ago
|
assert_progress_equal 100.0, v.completed_percent
|
||
|
assert_progress_equal 100.0, v.closed_percent
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should progress should consider done ratio of open assigned issues' do
|
||
16 years ago
|
project = Project.find(1)
|
||
13 years ago
|
(v = Version.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project: project, name: 'Progress' }
|
||
13 years ago
|
end).save!
|
||
11 years ago
|
add_work_package(v)
|
||
10 years ago
|
add_work_package(v, done_ratio: 20)
|
||
|
add_work_package(v, done_ratio: 70)
|
||
10 years ago
|
assert_progress_equal (0.0 + 20.0 + 70.0) / 3, v.completed_percent
|
||
11 years ago
|
assert_progress_equal 0, v.closed_percent
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should progress should consider closed issues as completed' do
|
||
16 years ago
|
project = Project.find(1)
|
||
13 years ago
|
(v = Version.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project: project, name: 'Progress' }
|
||
13 years ago
|
end).save!
|
||
11 years ago
|
add_work_package(v)
|
||
10 years ago
|
add_work_package(v, done_ratio: 20)
|
||
10 years ago
|
add_work_package(v, status: Status.where(is_closed: true).first)
|
||
10 years ago
|
assert_progress_equal (0.0 + 20.0 + 100.0) / 3, v.completed_percent
|
||
|
assert_progress_equal (100.0) / 3, v.closed_percent
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should progress should consider estimated hours to weigth issues' do
|
||
16 years ago
|
project = Project.find(1)
|
||
13 years ago
|
(v = Version.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project: project, name: 'Progress' }
|
||
13 years ago
|
end).save!
|
||
10 years ago
|
add_work_package(v, estimated_hours: 10)
|
||
|
add_work_package(v, estimated_hours: 20, done_ratio: 30)
|
||
|
add_work_package(v, estimated_hours: 40, done_ratio: 10)
|
||
10 years ago
|
add_work_package(v, estimated_hours: 25, status: Status.where(is_closed: true).first)
|
||
10 years ago
|
assert_progress_equal (10.0 * 0 + 20.0 * 0.3 + 40 * 0.1 + 25.0 * 1) / 95.0 * 100, v.completed_percent
|
||
|
assert_progress_equal 25.0 / 95.0 * 100, v.closed_percent
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should progress should consider average estimated hours to weigth unestimated issues' do
|
||
16 years ago
|
project = Project.find(1)
|
||
13 years ago
|
(v = Version.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project: project, name: 'Progress' }
|
||
13 years ago
|
end).save!
|
||
10 years ago
|
add_work_package(v, done_ratio: 20)
|
||
10 years ago
|
add_work_package(v, status: Status.where(is_closed: true).first)
|
||
10 years ago
|
add_work_package(v, estimated_hours: 10, done_ratio: 30)
|
||
|
add_work_package(v, estimated_hours: 40, done_ratio: 10)
|
||
10 years ago
|
assert_progress_equal (25.0 * 0.2 + 25.0 * 1 + 10.0 * 0.3 + 40.0 * 0.1) / 100.0 * 100, v.completed_percent
|
||
|
assert_progress_equal 25.0 / 100.0 * 100, v.closed_percent
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context '#behind_schedule?' do
|
||
11 years ago
|
before do
|
||
14 years ago
|
ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
|
||
9 years ago
|
@project = FactoryGirl.create(:project, identifier: 'test0')
|
||
|
@project.types << FactoryGirl.create(:type)
|
||
14 years ago
|
|
||
13 years ago
|
(@version = Version.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project: @project, effective_date: nil, name: 'test' }
|
||
13 years ago
|
end).save!
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should be false if there are no issues assigned' do
|
||
14 years ago
|
@version.update_attribute(:effective_date, Date.yesterday)
|
||
|
assert_equal false, @version.behind_schedule?
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should be false if there is no effective_date' do
|
||
14 years ago
|
assert_equal false, @version.behind_schedule?
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should be false if all of the issues are ahead of schedule' do
|
||
14 years ago
|
@version.update_attribute(:effective_date, 7.days.from_now.to_date)
|
||
|
@version.fixed_issues = [
|
||
10 years ago
|
FactoryGirl.create(:work_package, project: @project, start_date: 7.days.ago, done_ratio: 60), # 14 day span, 60% done, 50% time left
|
||
|
FactoryGirl.create(:work_package, project: @project, start_date: 7.days.ago, done_ratio: 60) # 14 day span, 60% done, 50% time left
|
||
|
]
|
||
11 years ago
|
assert_equal 60, @version.completed_percent
|
||
14 years ago
|
assert_equal false, @version.behind_schedule?
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should be true if any of the issues are behind schedule' do
|
||
14 years ago
|
@version.update_attribute(:effective_date, 7.days.from_now.to_date)
|
||
|
@version.fixed_issues = [
|
||
10 years ago
|
FactoryGirl.create(:work_package, project: @project, start_date: 7.days.ago, done_ratio: 60), # 14 day span, 60% done, 50% time left
|
||
|
FactoryGirl.create(:work_package, project: @project, start_date: 7.days.ago, done_ratio: 20) # 14 day span, 20% done, 50% time left
|
||
|
]
|
||
11 years ago
|
assert_equal 40, @version.completed_percent
|
||
14 years ago
|
assert_equal true, @version.behind_schedule?
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should be false if all of the issues are complete' do
|
||
14 years ago
|
@version.update_attribute(:effective_date, 7.days.from_now.to_date)
|
||
|
@version.fixed_issues = [
|
||
10 years ago
|
FactoryGirl.create(:work_package, project: @project, start_date: 14.days.ago, done_ratio: 100, status: Status.find(5)), # 7 day span
|
||
|
FactoryGirl.create(:work_package, project: @project, start_date: 14.days.ago, done_ratio: 100, status: Status.find(5)) # 7 day span
|
||
|
]
|
||
11 years ago
|
assert_equal 100, @version.completed_percent
|
||
14 years ago
|
assert_equal false, @version.behind_schedule?
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
context '#estimated_hours' do
|
||
11 years ago
|
before do
|
||
13 years ago
|
(@version = Version.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project_id: 1, name: '#estimated_hours' }
|
||
13 years ago
|
end).save!
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should return 0 with no assigned issues' do
|
||
15 years ago
|
assert_equal 0, @version.estimated_hours
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should return 0 with no estimated hours' do
|
||
11 years ago
|
add_work_package(@version)
|
||
15 years ago
|
assert_equal 0, @version.estimated_hours
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should return the sum of estimated hours' do
|
||
10 years ago
|
add_work_package(@version, estimated_hours: 2.5)
|
||
|
add_work_package(@version, estimated_hours: 5)
|
||
15 years ago
|
assert_equal 7.5, @version.estimated_hours
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should return the sum of leaves estimated hours' do
|
||
11 years ago
|
parent = add_work_package(@version)
|
||
10 years ago
|
add_work_package(@version, estimated_hours: 2.5, parent_id: parent.id)
|
||
|
add_work_package(@version, estimated_hours: 5, parent_id: parent.id)
|
||
15 years ago
|
assert_equal 7.5, @version.estimated_hours
|
||
|
end
|
||
|
end
|
||
15 years ago
|
|
||
11 years ago
|
it "should update all issue's fixed_version associations in case the hierarchy changed XXX" do
|
||
15 years ago
|
User.current = User.find(1) # Need the admin's permissions
|
||
14 years ago
|
|
||
15 years ago
|
@version = Version.find(7)
|
||
|
# Separate hierarchy
|
||
11 years ago
|
project_1_issue = WorkPackage.find(1)
|
||
15 years ago
|
project_1_issue.fixed_version = @version
|
||
14 years ago
|
assert project_1_issue.save, project_1_issue.errors.full_messages.to_s
|
||
14 years ago
|
|
||
11 years ago
|
project_5_issue = WorkPackage.find(6)
|
||
15 years ago
|
project_5_issue.fixed_version = @version
|
||
|
assert project_5_issue.save
|
||
14 years ago
|
|
||
15 years ago
|
# Project
|
||
11 years ago
|
project_2_issue = WorkPackage.find(4)
|
||
15 years ago
|
project_2_issue.fixed_version = @version
|
||
|
assert project_2_issue.save
|
||
|
|
||
|
# Update the sharing
|
||
|
@version.sharing = 'none'
|
||
|
assert @version.save
|
||
|
|
||
|
# Project 1 now out of the shared scope
|
||
|
project_1_issue.reload
|
||
|
assert_equal nil, project_1_issue.fixed_version, "Fixed version is still set after changing the Version's sharing"
|
||
14 years ago
|
|
||
15 years ago
|
# Project 5 now out of the shared scope
|
||
|
project_5_issue.reload
|
||
|
assert_equal nil, project_5_issue.fixed_version, "Fixed version is still set after changing the Version's sharing"
|
||
|
|
||
|
# Project 2 issue remains
|
||
|
project_2_issue.reload
|
||
|
assert_equal @version, project_2_issue.fixed_version
|
||
|
end
|
||
14 years ago
|
|
||
16 years ago
|
private
|
||
14 years ago
|
|
||
10 years ago
|
def add_work_package(version, attributes = {})
|
||
11 years ago
|
(v = WorkPackage.new.tap do |v|
|
||
10 years ago
|
v.force_attributes = { project: version.project,
|
||
|
fixed_version: version,
|
||
|
subject: 'Test',
|
||
|
author: User.first,
|
||
|
type: version.project.types.first }.merge(attributes)
|
||
13 years ago
|
end).save!
|
||
|
|
||
|
v
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
def assert_progress_equal(expected_float, actual_float, _message = '')
|
||
|
assert_in_delta(expected_float, actual_float, 0.000001, message = '')
|
||
16 years ago
|
end
|
||
16 years ago
|
end
|