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

[54646] Remove totals of childless work packages in a migration

Christophe Bliard708aaba38745
diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb
index 6fae2f9039b..74bd847206b 100644
--- a/app/controllers/statuses_controller.rb
+++ b/app/controllers/statuses_controller.rb
@@ -101,7 +101,7 @@ class StatusesController < ApplicationController
return unless WorkPackage.use_status_for_done_ratio?
return unless @status.default_done_ratio_previously_changed?
- WorkPackages::ApplyStatusesPCompleteJob
+ WorkPackages::Progress::ApplyStatusesPCompleteJob
.perform_later(cause_type: "status_p_complete_changed",
status_name: @status.name,
status_id: @status.id,
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 10c38d252fe..13e30211b33 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -68,6 +68,7 @@ class Journal < ApplicationRecord
store_accessor :cause,
%i[
type
+ feature
work_package_id
changed_days
status_name
diff --git a/app/services/settings/update_service.rb b/app/services/settings/update_service.rb
index b959f235453..836a7381ca2 100644
--- a/app/services/settings/update_service.rb
+++ b/app/services/settings/update_service.rb
@@ -46,7 +46,7 @@ class Settings::UpdateService < BaseServices::BaseContracted
new_value = derive_value(value)
Setting[name] = new_value
if name == :work_package_done_ratio && old_value != "status" && new_value == "status"
- WorkPackages::ApplyStatusesPCompleteJob.perform_later(cause_type: "progress_mode_changed_to_status_based")
+ WorkPackages::Progress::ApplyStatusesPCompleteJob.perform_later(cause_type: "progress_mode_changed_to_status_based")
end
end
diff --git a/app/workers/work_packages/apply_statuses_p_complete_job.rb b/app/workers/work_packages/progress/apply_statuses_p_complete_job.rb
similarity index 95%
rename from app/workers/work_packages/apply_statuses_p_complete_job.rb
rename to app/workers/work_packages/progress/apply_statuses_p_complete_job.rb
index 6182c167757..e85e3b0cca6 100644
--- a/app/workers/work_packages/apply_statuses_p_complete_job.rb
+++ b/app/workers/work_packages/progress/apply_statuses_p_complete_job.rb
@@ -28,11 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class WorkPackages::ApplyStatusesPCompleteJob < ApplicationJob
- queue_with_priority :default
-
- include WorkPackages::ProgressSqlCommands
-
+class WorkPackages::Progress::ApplyStatusesPCompleteJob < WorkPackages::Progress::Job
VALID_CAUSE_TYPES = %w[
progress_mode_changed_to_status_based
status_p_complete_changed
diff --git a/app/workers/work_packages/progress/job.rb b/app/workers/work_packages/progress/job.rb
new file mode 100644
index 00000000000..6356bfe6c57
--- /dev/null
+++ b/app/workers/work_packages/progress/job.rb
@@ -0,0 +1,42 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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.
+#++
+
+# Base class for jobs updating work packages progress values.
+#
+# Handles concurrency so that only one progress job is performed at a time.
+class WorkPackages::Progress::Job < ApplicationJob
+ include GoodJob::ActiveJobExtensions::Concurrency
+ include WorkPackages::Progress::SqlCommands
+
+ queue_with_priority :default
+
+ good_job_control_concurrency_with(
+ perform_limit: 1,
+ key: -> { "WorkPackagesProgressJob" }
+ )
+end
diff --git a/app/workers/work_packages/progress/migrate_remove_totals_from_childless_work_packages_job.rb b/app/workers/work_packages/progress/migrate_remove_totals_from_childless_work_packages_job.rb
new file mode 100644
index 00000000000..61a9a8e8d56
--- /dev/null
+++ b/app/workers/work_packages/progress/migrate_remove_totals_from_childless_work_packages_job.rb
@@ -0,0 +1,65 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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.
+#++
+
+class WorkPackages::Progress::MigrateRemoveTotalsFromChildlessWorkPackagesJob < WorkPackages::Progress::Job
+ def perform
+ updated_work_package_ids = remove_totals_from_childless_work_packages
+ create_journals_for_updated_work_packages(updated_work_package_ids, cause: journal_cause)
+ end
+
+ private
+
+ def journal_cause
+ { type: "system_update", feature: "totals_removed_from_childless_work_packages" }
+ end
+
+ def remove_totals_from_childless_work_packages
+ results = execute(<<~SQL.squish)
+ UPDATE work_packages
+ SET derived_estimated_hours = NULL,
+ derived_remaining_hours = NULL,
+ derived_done_ratio = NULL
+ FROM (
+ SELECT wp_tree.ancestor_id AS id,
+ MAX(generations) AS generations
+ FROM work_package_hierarchies wp_tree
+ LEFT JOIN work_packages ON wp_tree.descendant_id = work_packages.id
+ GROUP BY wp_tree.ancestor_id
+ ) hierarchy
+ WHERE work_packages.id = hierarchy.id
+ AND hierarchy.generations = 0
+ AND (
+ work_packages.derived_estimated_hours IS NOT NULL
+ OR work_packages.derived_remaining_hours IS NOT NULL
+ OR work_packages.derived_done_ratio IS NOT NULL
+ )
+ RETURNING work_packages.id
+ SQL
+ results.column_values(0)
+ end
+end
diff --git a/app/workers/work_packages/update_progress_job.rb b/app/workers/work_packages/progress/migrate_values_job.rb
similarity index 98%
rename from app/workers/work_packages/update_progress_job.rb
rename to app/workers/work_packages/progress/migrate_values_job.rb
index 053103400e3..6e77ee790e3 100644
--- a/app/workers/work_packages/update_progress_job.rb
+++ b/app/workers/work_packages/progress/migrate_values_job.rb
@@ -26,11 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class WorkPackages::UpdateProgressJob < ApplicationJob
- queue_with_priority :default
-
- include WorkPackages::ProgressSqlCommands
-
+class WorkPackages::Progress::MigrateValuesJob < WorkPackages::Progress::Job
attr_reader :current_mode, :previous_mode
def perform(current_mode:, previous_mode:)
diff --git a/app/workers/work_packages/progress_sql_commands.rb b/app/workers/work_packages/progress/sql_commands.rb
similarity index 99%
rename from app/workers/work_packages/progress_sql_commands.rb
rename to app/workers/work_packages/progress/sql_commands.rb
index c7b7ba67f4f..9ad890a1769 100644
--- a/app/workers/work_packages/progress_sql_commands.rb
+++ b/app/workers/work_packages/progress/sql_commands.rb
@@ -28,7 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module WorkPackages::ProgressSqlCommands
+module WorkPackages::Progress::SqlCommands
def with_temporary_progress_table
WorkPackage.transaction do
create_temporary_progress_table
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 30d245f1fb6..5011e2bef30 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1765,6 +1765,8 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}
Progress calculation automatically <a href="%{href}" target="_blank">set to work-based mode and adjusted with version update</a>.
progress_calculation_adjusted: >-
Progress calculation automatically <a href="%{href}" target="_blank">adjusted with version update</a>.
+ totals_removed_from_childless_work_packages: >-
+ Totals automatically removed from childless work packages with version update.
links:
configuration_guide: "Configuration guide"
diff --git a/db/migrate/20240402072213_update_progress_calculation.rb b/db/migrate/20240402072213_update_progress_calculation.rb
index bb24e8fef46..036cb97ef4a 100644
--- a/db/migrate/20240402072213_update_progress_calculation.rb
+++ b/db/migrate/20240402072213_update_progress_calculation.rb
@@ -9,7 +9,7 @@ class UpdateProgressCalculation < ActiveRecord::Migration[7.1]
end
perform_method = Rails.env.development? ? :perform_now : :perform_later
- WorkPackages::UpdateProgressJob.public_send(perform_method, current_mode:, previous_mode:)
+ WorkPackages::Progress::MigrateValuesJob.public_send(perform_method, current_mode:, previous_mode:)
end
def progress_calculation_mode
diff --git a/db/migrate/20240506091102_remove_totals_from_childless_work_packages.rb b/db/migrate/20240506091102_remove_totals_from_childless_work_packages.rb
new file mode 100644
index 00000000000..902d0985003
--- /dev/null
+++ b/db/migrate/20240506091102_remove_totals_from_childless_work_packages.rb
@@ -0,0 +1,6 @@
+class RemoveTotalsFromChildlessWorkPackages < ActiveRecord::Migration[7.1]
+ def up
+ perform_method = Rails.env.development? ? :perform_now : :perform_later
+ WorkPackages::Progress::MigrateRemoveTotalsFromChildlessWorkPackagesJob.public_send(perform_method)
+ end
+end
diff --git a/spec/controllers/admin/settings/work_packages_settings_controller_spec.rb b/spec/controllers/admin/settings/work_packages_settings_controller_spec.rb
index 6670c46c77b..93d9a06c282 100644
--- a/spec/controllers/admin/settings/work_packages_settings_controller_spec.rb
+++ b/spec/controllers/admin/settings/work_packages_settings_controller_spec.rb
@@ -54,7 +54,7 @@ RSpec.describe Admin::Settings::WorkPackagesSettingsController do
}
}
expect(Setting.work_package_done_ratio).to eq("status")
- expect(WorkPackages::ApplyStatusesPCompleteJob)
+ expect(WorkPackages::Progress::ApplyStatusesPCompleteJob)
.to have_been_enqueued.with(cause_type: "progress_mode_changed_to_status_based")
perform_enqueued_jobs
@@ -76,7 +76,7 @@ RSpec.describe Admin::Settings::WorkPackagesSettingsController do
work_package_done_ratio: "status"
}
}
- expect(WorkPackages::ApplyStatusesPCompleteJob)
+ expect(WorkPackages::Progress::ApplyStatusesPCompleteJob)
.not_to have_been_enqueued
end
end
@@ -93,7 +93,7 @@ RSpec.describe Admin::Settings::WorkPackagesSettingsController do
work_package_done_ratio: "field"
}
}
- expect(WorkPackages::ApplyStatusesPCompleteJob)
+ expect(WorkPackages::Progress::ApplyStatusesPCompleteJob)
.not_to have_been_enqueued
end
end
diff --git a/spec/controllers/statuses_controller_spec.rb b/spec/controllers/statuses_controller_spec.rb
index b4d271f588d..da8e941e2c8 100644
--- a/spec/controllers/statuses_controller_spec.rb
+++ b/spec/controllers/statuses_controller_spec.rb
@@ -143,7 +143,7 @@ RSpec.describe StatusesController do
it "does not start any jobs to update work packages % complete values" do
expect(status.reload).to have_attributes(default_done_ratio: new_default_done_ratio)
- expect(WorkPackages::ApplyStatusesPCompleteJob)
+ expect(WorkPackages::Progress::ApplyStatusesPCompleteJob)
.not_to have_been_enqueued
end
end
@@ -158,7 +158,7 @@ RSpec.describe StatusesController do
it "starts a job to update work packages % complete values" do
old_default_done_ratio = status.default_done_ratio
expect(status.reload).to have_attributes(default_done_ratio: new_default_done_ratio)
- expect(WorkPackages::ApplyStatusesPCompleteJob)
+ expect(WorkPackages::Progress::ApplyStatusesPCompleteJob)
.to have_been_enqueued.with(cause_type: "status_p_complete_changed",
status_name: status.name,
status_id: status.id,
@@ -175,7 +175,7 @@ RSpec.describe StatusesController do
let(:status_params) { { default_done_ratio: status.default_done_ratio } }
it "does not start any jobs" do
- expect(WorkPackages::ApplyStatusesPCompleteJob)
+ expect(WorkPackages::Progress::ApplyStatusesPCompleteJob)
.not_to have_been_enqueued
end
end
@@ -184,7 +184,7 @@ RSpec.describe StatusesController do
let(:status_params) { { name: "Another status name" } }
it "does not start any jobs" do
- expect(WorkPackages::ApplyStatusesPCompleteJob)
+ expect(WorkPackages::Progress::ApplyStatusesPCompleteJob)
.not_to have_been_enqueued
end
end
diff --git a/spec/migrations/remove_totals_from_childless_work_packages_spec.rb b/spec/migrations/remove_totals_from_childless_work_packages_spec.rb
new file mode 100644
index 00000000000..3c50e76627b
--- /dev/null
+++ b/spec/migrations/remove_totals_from_childless_work_packages_spec.rb
@@ -0,0 +1,99 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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 "spec_helper"
+require Rails.root.join("db/migrate/20240506091102_remove_totals_from_childless_work_packages.rb")
+
+RSpec.describe RemoveTotalsFromChildlessWorkPackages, type: :model do
+ # Silencing migration logs, since we are not interested in that during testing
+ subject(:run_migration) do
+ perform_enqueued_jobs do
+ ActiveRecord::Migration.suppress_messages { described_class.new.up }
+ end
+ end
+
+ shared_let(:author) { create(:user) }
+ shared_let(:priority) { create(:priority, name: "Normal") }
+ shared_let(:project) { create(:project, name: "Main project") }
+ shared_let(:status_new) { create(:status, name: "New") }
+
+ before_all do
+ set_factory_default(:user, author)
+ set_factory_default(:priority, priority)
+ set_factory_default(:project_with_types, project)
+ set_factory_default(:status, status_new)
+ end
+
+ describe "journal creation" do
+ before do
+ Setting.work_package_done_ratio = "field"
+ end
+
+ context "when the migration is run" do
+ let_work_packages(<<~TABLE)
+ hierarchy | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
+ wp totals set | 5h | 3h | 40% | 5h | 3h | 40%
+ wp only pc set | | | 60% | | |
+ wp parent consistent | 10h | 4h | 60% | 20h | 8h | 60%
+ wp all set consistent | 10h | 4h | 60% | | |
+ wp child totals set | 0h | 0h | | 0h | 0h |
+ TABLE
+
+ before do
+ run_migration
+ end
+
+ it "removes totals from childless work packages" do
+ expect_work_packages(table_work_packages.map(&:reload), <<~TABLE)
+ hierarchy | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
+ wp totals set | 5h | 3h | 40% | | |
+ wp only pc set | | | 60% | | |
+ wp parent consistent | 10h | 4h | 60% | 20h | 8h | 60%
+ wp all set consistent | 10h | 4h | 60% | | |
+ wp child totals set | 0h | 0h | | | |
+ TABLE
+ end
+
+ it "creates a journal entry only for each altered work package" do
+ expected_altered_work_packages = [wp_totals_set, wp_child_totals_set]
+ expected_altered_work_packages.each do |work_package|
+ expect(work_package.journals.count).to eq 2
+ last_journal = work_package.last_journal
+ expect(last_journal.user).to eq(User.system)
+ expect(last_journal.cause_type).to eq("system_update")
+ expect(last_journal.cause_feature).to eq("totals_removed_from_childless_work_packages")
+ end
+
+ expected_non_altered_work_packages = table_work_packages - expected_altered_work_packages
+ expected_non_altered_work_packages.each do |work_package|
+ expect(work_package.journals.count).to eq 1
+ end
+ end
+ end
+ end
+end
diff --git a/spec/workers/work_packages/apply_statuses_p_complete_job_spec.rb b/spec/workers/work_packages/progress/apply_statuses_p_complete_job_spec.rb
similarity index 99%
rename from spec/workers/work_packages/apply_statuses_p_complete_job_spec.rb
rename to spec/workers/work_packages/progress/apply_statuses_p_complete_job_spec.rb
index e1649fcdd11..185fead8735 100644
--- a/spec/workers/work_packages/apply_statuses_p_complete_job_spec.rb
+++ b/spec/workers/work_packages/progress/apply_statuses_p_complete_job_spec.rb
@@ -28,7 +28,7 @@
require "rails_helper"
-RSpec.describe WorkPackages::ApplyStatusesPCompleteJob do
+RSpec.describe WorkPackages::Progress::ApplyStatusesPCompleteJob do
shared_let(:author) { create(:user) }
shared_let(:priority) { create(:priority, name: "Normal") }
shared_let(:project) { create(:project, name: "Main project") }
diff --git a/spec/workers/work_packages/progress/migrate_remove_totals_from_childless_work_packages_job_spec.rb b/spec/workers/work_packages/progress/migrate_remove_totals_from_childless_work_packages_job_spec.rb
new file mode 100644
index 00000000000..99fb35f3b3e
--- /dev/null
+++ b/spec/workers/work_packages/progress/migrate_remove_totals_from_childless_work_packages_job_spec.rb
@@ -0,0 +1,149 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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 "rails_helper"
+
+RSpec.describe WorkPackages::Progress::MigrateRemoveTotalsFromChildlessWorkPackagesJob do
+ shared_let(:user) { create(:user) }
+ shared_let(:priority) { create(:priority, name: "Normal") }
+ shared_let(:project) { create(:project, name: "Main project") }
+ shared_let(:status_new) { create(:status, name: "New") }
+
+ before_all do
+ set_factory_default(:user, user)
+ set_factory_default(:priority, priority)
+ set_factory_default(:project_with_types, project)
+ set_factory_default(:status, status_new)
+ end
+
+ subject(:job) { described_class }
+
+ def expect_performing_job_changes(from:, to:)
+ table = create_table(from)
+ job.perform_now
+ expect_work_packages(table.work_packages.map(&:reload), to)
+ table.work_packages
+ end
+
+ context "when some work packages without children have total work, total remaining work or total % complete set" do
+ it "unsets totals and create a journal entry" do
+ work_packages = expect_performing_job_changes(
+ from: <<~TABLE,
+ subject | ∑ work | ∑ remaining work | ∑ % complete
+ wp tw set | 5h | |
+ wp trw set | | 2h |
+ wp tpc set | | | 60%
+ wp tall set | 5h | 2h | 60%
+ TABLE
+ to: <<~TABLE
+ subject | ∑ work | ∑ remaining work | ∑ % complete
+ wp tw set | | |
+ wp trw set | | |
+ wp tpc set | | |
+ wp tall set | | |
+ TABLE
+ )
+ work_packages.each do |work_package|
+ expect(work_package.journals.count).to eq 2
+ last_journal = work_package.last_journal
+ expect(last_journal.user).to eq(User.system)
+ expect(last_journal.cause_type).to eq("system_update")
+ expect(last_journal.cause_feature).to eq("totals_removed_from_childless_work_packages")
+ end
+ end
+ end
+
+ context "when some work packages without children have all totals unset" do
+ it "does not update them and does not create any new journal entries" do
+ work_packages = expect_performing_job_changes(
+ from: <<~TABLE,
+ subject | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
+ work package | 10h | 7h | 30% | | |
+ wp blank | | | | | |
+ TABLE
+ to: <<~TABLE
+ subject | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
+ work package | 10h | 7h | 30% | | |
+ wp blank | | | | | |
+ TABLE
+ )
+ work_packages.each do |work_package|
+ expect(work_package.journals.count).to eq 1
+ end
+ end
+ end
+
+ context "when some parent work packages have total work, total remaining work or total % complete set" do
+ # rubocop:disable RSpec/ExampleLength
+ it "does not update them and does not create any new journal entries" do
+ work_packages = expect_performing_job_changes(
+ from: <<~TABLE,
+ hierarchy | ∑ work | ∑ remaining work | ∑ % complete
+ wp tw set | 5h | |
+ child1 | | |
+ wp trw set | | 2h |
+ child2 | | |
+ wp tpc set | | | 60%
+ child3 | | |
+ wp tall set | 5h | 2h | 60%
+ child4 | | |
+ TABLE
+ to: <<~TABLE
+ subject | ∑ work | ∑ remaining work | ∑ % complete
+ wp tw set | 5h | |
+ child1 | | |
+ wp trw set | | 2h |
+ child2 | | |
+ wp tpc set | | | 60%
+ child3 | | |
+ wp tall set | 5h | 2h | 60%
+ child4 | | |
+ TABLE
+ )
+ work_packages.each do |work_package|
+ expect(work_package.journals.count).to eq 1
+ end
+ end
+ # rubocop:enable RSpec/ExampleLength
+
+ it "does not even try to recompute totals (not that job's business)" do
+ expect_performing_job_changes(
+ from: <<~TABLE,
+ hierarchy | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
+ parent | | | | | |
+ child | 10h | 7h | 30% | | |
+ TABLE
+ to: <<~TABLE
+ subject | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete
+ parent | | | | | |
+ child | 10h | 7h | 30% | | |
+ TABLE
+ )
+ end
+ end
+end