Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

replace legacy spec

ulfertsb71245d5b768
diff --git a/spec/models/issue_priority_spec.rb b/spec/models/issue_priority_spec.rb
index 1f69bacaf7c..385408ccbb7 100644
--- a/spec/models/issue_priority_spec.rb
+++ b/spec/models/issue_priority_spec.rb
@@ -28,8 +28,10 @@
require 'spec_helper'
describe IssuePriority, type: :model do
+ shared_let(:priority) { create(:priority) }
+ shared_let(:default_priority) { create(:default_priority) }
+
let(:stubbed_priority) { build_stubbed(:priority) }
- let(:priority) { create(:priority) }
describe '.ancestors' do
it 'is an enumeration' do
@@ -90,4 +92,96 @@ describe IssuePriority, type: :model do
.to match_array [work_package3, work_package1]
end
end
+
+ describe '#in_use?' do
+ context 'with a work package that uses the priority' do
+ let!(:work_package) { create(:work_package, priority:) }
+
+ it 'is true' do
+ expect(priority)
+ .to be_in_use
+ end
+ end
+
+ context 'without a work package that uses the priority' do
+ it 'is false' do
+ expect(priority)
+ .not_to be_in_use
+ end
+ end
+ end
+
+ describe '.default' do
+ it 'returns the default priority' do
+ expect(described_class.default)
+ .to eq default_priority
+ end
+
+ it 'changes if a new default priority is created' do
+ new_default = described_class.create(name: 'New default', is_default: true)
+
+ expect(described_class.default)
+ .to eq new_default
+ end
+
+ it 'does not change if a new non default priority is created' do
+ described_class.create(name: 'New default', is_default: false)
+
+ expect(described_class.default)
+ .to eq default_priority
+ end
+
+ it 'is nil if the default priority looses the default flag' do
+ default_priority.update(is_default: false)
+
+ expect(described_class.default)
+ .to be_nil
+ end
+ end
+
+ describe '#default?' do
+ it 'is true for a default priority' do
+ expect(default_priority)
+ .to be_is_default
+ end
+
+ it 'is false for a non default priority' do
+ expect(priority)
+ .not_to be_is_default
+ end
+
+ it 'changes if a new default priority is created' do
+ described_class.create(name: 'New default', is_default: true)
+
+ expect(default_priority)
+ .not_to be_is_default
+ end
+
+ it 'changes if an existing priority is assigned default' do
+ priority.update(is_default: true)
+
+ expect(default_priority)
+ .not_to be_is_default
+ end
+ end
+
+ describe '.destroy' do
+ let!(:work_package) { create(:work_package, priority:) }
+
+ context 'with reassign' do
+ it 'reassigns the work packages' do
+ priority.destroy(default_priority)
+
+ expect(WorkPackage.where(priority: default_priority))
+ .to eq [work_package]
+ end
+ end
+
+ context 'without reassign' do
+ it 'raises an error as it is in use' do
+ expect { priority.destroy }
+ .to raise_error RuntimeError
+ end
+ end
+ end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index ab07920592e..604c6be52d7 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -227,4 +227,98 @@ describe Project, type: :model do
include_examples 'creates an audit trail on destroy' do
subject { create(:attachment) }
end
+
+ describe '#close_completed_versions' do
+ let!(:completed_version) do
+ create(:version, project:, effective_date: Date.parse('2000-01-01')).tap do |v|
+ create(:work_package, version: v, status: create(:closed_status))
+ end
+ end
+ let!(:ineffective_version) do
+ create(:version, project:, effective_date: Date.current + 1.day).tap do |v|
+ create(:work_package, version: v, status: create(:closed_status))
+ end
+ end
+ let!(:version_with_open_wps) do
+ create(:version, project:, effective_date: Date.parse('2000-01-01')).tap do |v|
+ create(:work_package, version: v)
+ end
+ end
+
+ before do
+ project.close_completed_versions
+ end
+
+ it 'closes the completed version' do
+ expect(completed_version.reload.status)
+ .to eq 'closed'
+ end
+
+ it 'keeps the version with the not yet reached date open' do
+ expect(ineffective_version.reload.status)
+ .to eq 'open'
+ end
+
+ it 'keeps the version with open work packages open' do
+ expect(version_with_open_wps.reload.status)
+ .to eq 'open'
+ end
+ end
+
+ describe 'hierarchy methods' do
+ shared_let(:root_project) { create(:project) }
+ shared_let(:parent_project) { create(:project, parent: root_project) }
+ shared_let(:child_project1) { create(:project, parent: parent_project) }
+ shared_let(:child_project2) { create(:project, parent: parent_project) }
+
+ describe '#parent' do
+ it 'returns the parent' do
+ expect(parent_project.parent)
+ .to eq root_project
+ end
+ end
+
+ describe '#root' do
+ it 'returns the root of the hierarchy' do
+ expect(child_project1.root)
+ .to eq root_project
+ end
+ end
+
+ describe '#ancestors' do
+ it 'returns the ancestors of the work package' do
+ expect(child_project1.ancestors)
+ .to eq [root_project, parent_project]
+ end
+
+ it 'returns empty array if there are no ancestors' do
+ expect(root_project.ancestors)
+ .to be_empty
+ end
+ end
+
+ describe '#desendants' do
+ it 'returns the descendants of the work package' do
+ expect(root_project.descendants)
+ .to eq [parent_project, child_project1, child_project2]
+ end
+
+ it 'returns empty array if there are no descendants' do
+ expect(child_project2.descendants)
+ .to be_empty
+ end
+ end
+
+ describe '#children' do
+ it 'returns the children of the work package' do
+ expect(parent_project.children)
+ .to eq [child_project1, child_project2]
+ end
+
+ it 'returns empty array if there are no descendants' do
+ expect(child_project2.children)
+ .to be_empty
+ end
+ end
+ end
end
diff --git a/spec/models/version_spec.rb b/spec/models/version_spec.rb
index da9b3f6aae4..12a6be0e3ab 100644
--- a/spec/models/version_spec.rb
+++ b/spec/models/version_spec.rb
@@ -371,4 +371,134 @@ describe Version, type: :model do
end
end
end
+
+ describe '#completed_percent and #closed_percent' do
+ create_shared_association_defaults_for_work_package_factory
+
+ let(:project) { create(:project) }
+ let(:version) { create(:version, project:) }
+ let(:closed_status) { create(:status, is_closed: true) }
+
+ context 'without a work package' do
+ it 'is 0 for completed_percent' do
+ expect(version.completed_percent)
+ .to eq 0
+ end
+
+ it 'is 0 for closed_percent' do
+ expect(version.closed_percent)
+ .to eq 0
+ end
+ end
+
+ context 'with assigned work packages that are not begun' do
+ before do
+ create(:work_package, version:)
+ create(:work_package, version:, done_ratio: 0)
+ end
+
+ it 'is 0 for completed_percent' do
+ expect(version.completed_percent)
+ .to eq 0
+ end
+
+ it 'is 0 for closed_percent' do
+ expect(version.closed_percent)
+ .to eq 0
+ end
+ end
+
+ context 'with assigned work packages that are closed' do
+ before do
+ create(:work_package, status: closed_status, version:)
+ create(:work_package, status: closed_status, version:, done_ratio: 20)
+ create(:work_package, status: closed_status, version:, done_ratio: 70, estimated_hours: 25)
+ create(:work_package, status: closed_status, version:, estimated_hours: 15)
+ end
+
+ it 'is 100 for completed_percent' do
+ expect(version.completed_percent)
+ .to eq 100
+ end
+
+ it 'is 100 for closed_percent' do
+ expect(version.closed_percent)
+ .to eq 100
+ end
+ end
+
+ context 'with assigned work packages that have only done ratio' do
+ before do
+ create(:work_package, version:)
+ create(:work_package, version:, done_ratio: 20)
+ create(:work_package, version:, done_ratio: 70)
+ end
+
+ it 'considers the done ratio of open work packages' do
+ expect(version.completed_percent)
+ .to eq (0.0 + 20.0 + 70.0) / 3
+ end
+
+ it 'is 0 for closed_percent' do
+ expect(version.closed_percent)
+ .to eq 0
+ end
+ end
+
+ context 'with assigned work packages that have only done ratio with one being closed' do
+ before do
+ create(:work_package, version:)
+ create(:work_package, version:, done_ratio: 20)
+ create(:work_package, status: closed_status, version:)
+ end
+
+ it 'considers the done ratio of open work packages' do
+ expect(version.completed_percent)
+ .to eq (0.0 + 20.0 + 100.0) / 3
+ end
+
+ it 'is 33 for closed_percent' do
+ expect(version.closed_percent)
+ .to eq 100.0 / 3
+ end
+ end
+
+ context 'with assigned work packages that have weighted done ratio' do
+ before do
+ create(:work_package, version:, estimated_hours: 10)
+ create(:work_package, version:, done_ratio: 30, estimated_hours: 20)
+ create(:work_package, version:, done_ratio: 10, estimated_hours: 40)
+ create(:work_package, status: closed_status, version:, estimated_hours: 25)
+ end
+
+ it 'considers the weighted done ratio of open work packages' do
+ expect(version.completed_percent)
+ .to eq ((10.0 * 0) + (20.0 * 0.3) + (40 * 0.1) + (25.0 * 1)) / 95.0 * 100
+ end
+
+ it 'is considers the weighted closed_percent' do
+ expect(version.closed_percent)
+ .to eq 25.0 / 95.0 * 100
+ end
+ end
+
+ context 'with assigned work packages that have partly weighted done ratio' do
+ before do
+ create(:work_package, version:, done_ratio: 20)
+ create(:work_package, version:, done_ratio: 30, estimated_hours: 10)
+ create(:work_package, version:, done_ratio: 10, estimated_hours: 40)
+ create(:work_package, status: closed_status, version:)
+ end
+
+ it 'considers the weighted done ratio of open work packages and uses default weighting if unset' do
+ expect(version.completed_percent)
+ .to eq ((25.0 * 0.2) + (25.0 * 1) + (10.0 * 0.3) + (40.0 * 0.1)) / 100.0 * 100
+ end
+
+ it 'is considers the weighted closed_percent using average for the estimated hours' do
+ expect(version.closed_percent)
+ .to eq 25.0 / 100.0 * 100
+ end
+ end
+ end
end
diff --git a/spec_legacy/fixtures/versions.yml b/spec_legacy/fixtures/versions.yml
deleted file mode 100644
index 69b5e308608..00000000000
--- a/spec_legacy/fixtures/versions.yml
+++ /dev/null
@@ -1,99 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# 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.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
----
-versions_001:
- created_at: 2006-07-19 21:00:07 +02:00
- name: "0.1"
- project_id: 1
- updated_at: 2006-07-19 21:00:07 +02:00
- id: 1
- description: Beta
- effective_date: 2006-07-01
- status: closed
- sharing: 'none'
-versions_002:
- created_at: 2006-07-19 21:00:33 +02:00
- name: "1.0"
- project_id: 1
- updated_at: 2006-07-19 21:00:33 +02:00
- id: 2
- description: Stable release
- effective_date: <%= 20.day.from_now.to_date.to_fs(:db) %>
- status: locked
- sharing: 'none'
-versions_003:
- created_at: 2006-07-19 21:00:33 +02:00
- name: "2.0"
- project_id: 1
- updated_at: 2006-07-19 21:00:33 +02:00
- id: 3
- description: Future version
- effective_date:
- status: open
- sharing: 'none'
-versions_004:
- created_at: 2006-07-19 21:00:33 +02:00
- name: "2.0"
- project_id: 3
- updated_at: 2006-07-19 21:00:33 +02:00
- id: 4
- description: Future version on subproject
- effective_date:
- status: open
- sharing: 'tree'
-versions_005:
- created_at: 2006-07-19 21:00:07 +02:00
- name: "Alpha"
- project_id: 2
- updated_at: 2006-07-19 21:00:07 +02:00
- id: 5
- description: Private Alpha
- effective_date: 2006-07-01
- status: open
- sharing: 'none'
-versions_006:
- created_at: 2006-07-19 21:00:07 +02:00
- name: "Private Version of public subproject"
- project_id: 5
- updated_at: 2006-07-19 21:00:07 +02:00
- id: 6
- description: "Should be done any day now..."
- effective_date:
- status: open
- sharing: 'tree'
-versions_007:
- created_at: 2006-07-19 21:00:07 +02:00
- name: "Systemwide visible version"
- project_id: 2
- updated_at: 2006-07-19 21:00:07 +02:00
- id: 7
- description:
- effective_date:
- status: open
- sharing: 'system'
diff --git a/spec_legacy/legacy_spec_helper.rb b/spec_legacy/legacy_spec_helper.rb
index 1cbf0a49c01..4bc6b40d7cc 100644
--- a/spec_legacy/legacy_spec_helper.rb
+++ b/spec_legacy/legacy_spec_helper.rb
@@ -34,7 +34,6 @@ require 'fileutils'
require 'rspec/mocks'
require 'factory_bot_rails'
-require_relative './support/legacy_file_helpers'
require_relative './support/legacy_assertions'
require 'rspec/rails'
diff --git a/spec_legacy/support/legacy_file_helpers.rb b/spec_legacy/support/legacy_file_helpers.rb
deleted file mode 100644
index a656fe70d2f..00000000000
--- a/spec_legacy/support/legacy_file_helpers.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# 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.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-module LegacyFileHelpers
- module_function
-
- def mock_uploaded_file(name: 'test.txt',
- content_type: 'text/plain',
- content: 'test content',
- binary: false)
-
- tmp = ::OpenProject::Files.create_temp_file name: name, content: content, binary: binary
- Rack::Test::UploadedFile.new tmp.path, content_type, binary
- end
-end
diff --git a/spec_legacy/unit/enumeration_spec.rb b/spec_legacy/unit/enumeration_spec.rb
deleted file mode 100644
index 110b2b539c3..00000000000
--- a/spec_legacy/unit/enumeration_spec.rb
+++ /dev/null
@@ -1,97 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# 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.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-require_relative './../legacy_spec_helper'
-
-describe Enumeration, type: :model do
- before do
- WorkPackage.delete_all
- @low_priority = create :priority_low
- @issues = create_list :work_package, 6, priority: @low_priority
- @default_enumeration = create :default_enumeration
- end
-
- it 'ins use' do
- assert @low_priority.in_use?
- assert !create(:priority).in_use?
- end
-
- it 'defaults' do
- e = Enumeration.default
- assert e.is_a?(Enumeration)
- assert e.is_default?
- assert_equal 'Default Enumeration', e.name
- end
-
- it 'creates' do
- e = Enumeration.new(name: 'Not default', is_default: false)
- e.type = 'Enumeration'
- assert e.save
- assert_equal @default_enumeration.name, Enumeration.default.name
- end
-
- it 'creates as default' do
- e = Enumeration.new(name: 'Very urgent', is_default: true)
- e.type = 'Enumeration'
- assert e.save
- assert_equal e, Enumeration.default
- end
-
- it 'updates default' do
- @default_enumeration.update(name: 'Changed', is_default: true)
- assert_equal @default_enumeration, Enumeration.default
- end
-
- it 'updates default to non default' do
- @default_enumeration.update(name: 'Changed', is_default: false)
- assert_nil Enumeration.default
- end
-
- it 'changes default' do
- e = Enumeration.find_by(name: @default_enumeration.name)
- e.update(name: 'Changed Enumeration', is_default: true)
- assert_equal e, Enumeration.default
- end
-
- it 'destroys with reassign' do
- new_priority = create :priority
- Enumeration.find(@low_priority.id).destroy(new_priority)
- assert_nil WorkPackage.find_by(priority_id: @low_priority.id)
- assert_equal @issues.size, new_priority.objects_count
- end
-
- it 'belongs to a project' do
- association = Enumeration.reflect_on_association(:project)
- assert association, 'No Project association found'
- assert_equal :belongs_to, association.macro
- end
-
- it 'acts as tree' do
- assert @low_priority.respond_to?(:parent)
- assert @low_priority.respond_to?(:children)
- end
-end
diff --git a/spec_legacy/unit/project_spec.rb b/spec_legacy/unit/project_spec.rb
index 5f476171b84..d6d0c99c1c2 100644
--- a/spec_legacy/unit/project_spec.rb
+++ b/spec_legacy/unit/project_spec.rb
@@ -34,37 +34,6 @@ describe Project, type: :model do
User.current = nil
end
- it 'parents' do
- p = Project.find(6).parent
- assert p.is_a?(Project)
- assert_equal 5, p.id
- end
-
- it 'ancestorses' do
- a = Project.find(6).ancestors
- assert a.first.is_a?(Project)
- assert_equal [1, 5], a.map(&:id).sort
- end
-
- it 'roots' do
- r = Project.find(6).root
- assert r.is_a?(Project)
- assert_equal 1, r.id
- end
-
- it 'childrens' do
- c = Project.find(1).children
- assert c.first.is_a?(Project)
- # ignore ordering, since it depends on database collation configuration
- # and may order lowercase/uppercase chars in a different order
- assert_equal [3, 4, 5], c.map(&:id).sort!
- end
-
- it 'descendantses' do
- d = Project.find(1).descendants.pluck(:id)
- assert_equal [3, 4, 5, 6], d.sort
- end
-
it 'userses by role' do
users_by_role = Project.find(1).users_by_role
assert_kind_of Hash, users_by_role
@@ -124,15 +93,4 @@ describe Project, type: :model do
# Ids should be preserved
assert_equal project.enabled_module_ids.sort, modules.map(&:id).sort
end
-
- it 'closes completed versions' do
- Version.update_all("status = 'open'")
- project = Project.find(1)
- refute_nil project.versions.detect { |v| v.completed? && v.status == 'open' }
- refute_nil project.versions.detect { |v| !v.completed? && v.status == 'open' }
- project.close_completed_versions
- project.reload
- assert_nil project.versions.detect { |v| v.completed? && v.status != 'closed' }
- refute_nil project.versions.detect { |v| !v.completed? && v.status == 'open' }
- end
end
diff --git a/spec_legacy/unit/version_spec.rb b/spec_legacy/unit/version_spec.rb
deleted file mode 100644
index 8f1ab58c6bd..00000000000
--- a/spec_legacy/unit/version_spec.rb
+++ /dev/null
@@ -1,132 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2022 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# 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.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-require_relative '../legacy_spec_helper'
-
-describe Version, type: :model do
- fixtures :all
-
- it 'progresses should be 0 with no assigned issues' do
- project = Project.find(1)
- (v = Version.new.tap do |v|
- v.attributes = { project:, name: 'Progress' }
- end).save!
- assert_equal 0, v.completed_percent
- assert_equal 0, v.closed_percent
- end
-
- it 'progresses should be 0 with unbegun assigned issues' do
- project = Project.find(1)
- (v = Version.new.tap do |v|
- v.attributes = { project:, name: 'Progress' }
- end).save!
- add_work_package(v)
- add_work_package(v, done_ratio: 0)
- assert_progress_equal 0, v.completed_percent
- assert_progress_equal 0, v.closed_percent
- end
-
- it 'progresses should be 100 with closed assigned issues' do
- project = Project.find(1)
- status = Status.where(is_closed: true).first
- (v = Version.new.tap do |v|
- v.attributes = { project:, name: 'Progress' }
- end).save!
- add_work_package(v, status:)
- add_work_package(v, status:, done_ratio: 20)
- add_work_package(v, status:, done_ratio: 70, estimated_hours: 25)
- add_work_package(v, status:, estimated_hours: 15)
- assert_progress_equal 100.0, v.completed_percent
- assert_progress_equal 100.0, v.closed_percent
- end
-
- it 'progresses should consider done ratio of open assigned issues' do
- project = Project.find(1)
- (v = Version.new.tap do |v|
- v.attributes = { project:, name: 'Progress' }
- end).save!
- add_work_package(v)
- add_work_package(v, done_ratio: 20)
- add_work_package(v, done_ratio: 70)
- assert_progress_equal (0.0 + 20.0 + 70.0) / 3, v.completed_percent
- assert_progress_equal 0, v.closed_percent
- end
-
- it 'progresses should consider closed issues as completed' do
- project = Project.find(1)
- (v = Version.new.tap do |v|
- v.attributes = { project:, name: 'Progress' }
- end).save!
- add_work_package(v)
- add_work_package(v, done_ratio: 20)
- add_work_package(v, status: Status.where(is_closed: true).first)
- assert_progress_equal (0.0 + 20.0 + 100.0) / 3, v.completed_percent
- assert_progress_equal 100.0 / 3, v.closed_percent
- end
-
- it 'progresses should consider estimated hours to weight issues' do
- project = Project.find(1)
- (v = Version.new.tap do |v|
- v.attributes = { project:, name: 'Progress' }
- end).save!
- 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)
- add_work_package(v, estimated_hours: 25, status: Status.where(is_closed: true).first)
- 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
- end
-
- it 'progresses should consider average estimated hours to weight unestimated issues' do
- project = Project.find(1)
- (v = Version.new.tap do |v|
- v.attributes = { project:, name: 'Progress' }
- end).save!
- add_work_package(v, done_ratio: 20)
- add_work_package(v, status: Status.where(is_closed: true).first)
- add_work_package(v, estimated_hours: 10, done_ratio: 30)
- add_work_package(v, estimated_hours: 40, done_ratio: 10)
- 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
- end
-
- private
-
- def add_work_package(version, attributes = {})
- WorkPackage.create!({ project: version.project,
- priority_id: 5,
- status_id: 1,
- version:,
- subject: 'Test',
- author: User.first,
- type: version.project.types.first }.merge(attributes))
- end
-
- def assert_progress_equal(expected_float, actual_float, _message = '')
- assert_in_delta(expected_float, actual_float, 0.000001, '')
- end
-end