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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Merge pull request #15244 from opf/fix/unset_old_total_p_complete
Christophe Bliardc139f9ebeee9
diff --cc spec/migrations/update_progress_calculation_spec.rbindex 1895179a257,298c045d718..bfded12c7f5--- a/spec/migrations/update_progress_calculation_spec.rb+++ b/spec/migrations/update_progress_calculation_spec.rb@@@ -689,48 -693,66 +697,109 @@@ RSpec.describe UpdateProgressCalculatio)endend++ context "when ∑ % complete has had some values (including wrong ones)" do+ let_work_packages(<<~TABLE)+ hierarchy | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete |+ wp zero | | | 0 | | | 0 |+ wp correct | 100h | 50h | 50 | 100h | 50h | 50 |+ wp wrong | | | 90 | 100h | 50h | 90 |+ wp wrong child | 100h | 50h | 20 | 10h | 10h | 20 |+ TABLE++ before do+ run_migration+ end++ it "fixes the total values and sets ∑ % complete to nil (not 0) but keeps % complete (unless wrong)" do+ expect_work_packages(WorkPackage.all, <<~TABLE)+ subject | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete |+ wp zero | | | 0 | | | |+ wp correct | 100h | 50h | 50 | 100h | 50h | 50 |+ wp wrong | | | 90 | 100h | 50h | 50 |+ wp wrong child | 100h | 50h | 50 | 100h | 50h | 50 |+ TABLE+ end++ it "creates no journal for the work package transitioning from 0 to nil and reworks the pre migration journals" do+ expect(wp_zero.journals.count).to eq(1)++ expect(wp_zero.journals.first.get_changes.keys)+ .not_to include("derived_done_ratio")+ end++ it "creates a journal for the correct work package as the old ∑ % complete value has been set to null during the job" do+ expect(wp_correct.journals.count).to eq(2)++ expect(wp_correct.journals.first.get_changes.keys)+ .not_to include("derived_done_ratio")++ expect(wp_correct.journals.last.get_changes["derived_done_ratio"])+ .to eql [nil, 50]+ end++ it "creates a journal for the work package transitioning from 90 to 50 and reworks the pre migration journals" do+ expect(wp_wrong.journals.count).to eq(2)++ expect(wp_wrong.journals.first.get_changes.keys)+ .not_to include("derived_done_ratio")++ expect(wp_wrong.journals.last.get_changes["derived_done_ratio"])+ .to eql [nil, 50]+ end++ it "creates a journal for the work package transitioning from 20 to 50 and reworks the pre migration journals" do+ expect(wp_wrong_child.journals.count).to eq(2)++ expect(wp_wrong_child.journals.first.get_changes.keys)+ .not_to include("derived_done_ratio")++ expect(wp_wrong_child.journals.last.get_changes["derived_done_ratio"])+ .to eql [nil, 50]+ end+ endend++ describe "error during job execution" do+ let_work_packages(<<~TABLE)+ subject | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete+ wp working | | 4h | 60% | 10h | 4h | 60%+ wp breaking | | 4h | 60% | 10h | 4h | 60%+ TABLE++ before do+ Setting.work_package_done_ratio = "field"++ allow(Journals::CreateService)+ .to receive(:new)+ .with(wp_working, User.system)+ .and_call_original++ allow(Journals::CreateService)+ .to receive(:new)+ .with(wp_breaking, User.system)+ .and_return(nil)++ ActiveRecord::Migration.suppress_messages { described_class.new.up }++ begin+ perform_enqueued_jobs+ rescue StandardError+ end+ end++ it "does not create a journal entry" do+ table_work_packages.each do |wp|+ expect(wp.journals.count).to eq(1)+ end+ end++ it "does not update the work packages" do+ expect_work_packages(WorkPackage.all, <<~TABLE)+ subject | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete+ wp working | | 4h | 60% | 10h | 4h | 60%+ wp breaking | | 4h | 60% | 10h | 4h | 60%+ TABLE+ end+ endend