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
Statuses can no longer have a NULL default done ratio
Christophe Bliard19198a802ab4
diff --git a/db/migrate/20240328154805_change_status_default_done_ratio_to_zero.rb b/db/migrate/20240328154805_change_status_default_done_ratio_to_zero.rbnew file mode 100644index 00000000000..b430e096694--- /dev/null+++ b/db/migrate/20240328154805_change_status_default_done_ratio_to_zero.rb@@ -0,0 +1,11 @@+class ChangeStatusDefaultDoneRatioToZero < ActiveRecord::Migration[7.1]+ def change+ change_column_default :statuses, :default_done_ratio, from: nil, to: 0+ reversible do |dir|+ dir.up do+ execute "UPDATE statuses SET default_done_ratio = 0 WHERE default_done_ratio IS NULL"+ end+ end+ change_column_null :statuses, :default_done_ratio, false+ end+enddiff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rbindex 0d1f36d5f95..7ce6c30b859 100644--- a/spec/services/work_packages/set_attributes_service_spec.rb+++ b/spec/services/work_packages/set_attributes_service_spec.rb@@ -30,7 +30,7 @@ require "spec_helper"RSpec.describe WorkPackages::SetAttributesService,type: :model do- shared_let(:status_no_pct_complete) { create(:status, default_done_ratio: nil, name: "no % complete") }+ shared_let(:status_0_pct_complete) { create(:status, default_done_ratio: 0, name: "0% complete") }shared_let(:status_50_pct_complete) { create(:status, default_done_ratio: 50, name: "50% complete") }shared_let(:status_70_pct_complete) { create(:status, default_done_ratio: 70, name: "70% complete") }@@ -43,7 +43,7 @@ RSpec.describe WorkPackages::SetAttributesService,pendlet(:work_package) do- wp = build_stubbed(:work_package, project:, status: status_no_pct_complete)+ wp = build_stubbed(:work_package, project:, status: status_0_pct_complete)wp.type = initial_typewp.send(:clear_changes_information)@@ -184,33 +184,25 @@ RSpec.describe WorkPackages::SetAttributesService,it_behaves_like "service call", description: "recomputes remaining work accordingly"end- context "when another status with a default % complete value is set" do+ context "when another status is set" dolet(:call_attributes) { { status: status_70_pct_complete } }let(:expected_attributes) { { remaining_hours: 3.0 } }it_behaves_like "service call",description: "recomputes remaining work according to the % complete value of the new status"end-- context "when another status without any default % complete value is set" do- let(:call_attributes) { { status: status_no_pct_complete } }- let(:expected_attributes) { { remaining_hours: nil } }-- it_behaves_like "service call",- description: "unsets remaining work"- endend- context "given a work package with work and remaining work unset, and a status with no % complete" do+ context "given a work package with work and remaining work unset, and a status with 0% complete" dobefore do- work_package.status = status_no_pct_complete+ work_package.status = status_0_pct_completework_package.done_ratio = work_package.status.default_done_ratiowork_package.estimated_hours = nilwork_package.remaining_hours = nilwork_package.send(:clear_changes_information)end- context "when another status with a default % complete value is set" do+ context "when another status with another % complete value is set" dolet(:call_attributes) { { status: status_70_pct_complete } }let(:expected_attributes) { { remaining_hours: nil } }@@ -220,10 +212,10 @@ RSpec.describe WorkPackages::SetAttributesService,context "when work is set" dolet(:call_attributes) { { estimated_hours: 10.0 } }- let(:expected_attributes) { { remaining_hours: nil } }+ let(:expected_attributes) { { remaining_hours: 10.0 } }it_behaves_like "service call",- description: "remaining work remains unset"+ description: "remaining work is updated accordingly from work and % complete value of the status"endendend@@ -246,13 +238,6 @@ RSpec.describe WorkPackages::SetAttributesService,it_behaves_like "service call", description: "sets the % complete value to the status default % complete value"end-- context "when another status with no % complete value is set" do- let(:call_attributes) { { status: status_no_pct_complete } }- let(:expected_attributes) { { done_ratio: nil } }-- it_behaves_like "service call", description: "unsets the % complete value"- endendenddiff --git a/spec/services/work_packages/update_ancestors_service_spec.rb b/spec/services/work_packages/update_ancestors_service_spec.rbindex 33ed8bf1675..05c495d178f 100644--- a/spec/services/work_packages/update_ancestors_service_spec.rb+++ b/spec/services/work_packages/update_ancestors_service_spec.rb@@ -56,9 +56,8 @@ RSpec.describe WorkPackages::UpdateAncestorsService, type: :model dodescribe "done_ratio/estimated_hours/remaining_hours propagation" docontext "when setting the status of a work package" do- shared_let(:open_status) { create(:status) }- shared_let(:new_status_with_done_ratio) { create(:status, default_done_ratio: 100) }- shared_let(:new_status_without_done_ratio) { create(:status, default_done_ratio: nil) }+ shared_let(:open_status) { create(:status, name: "open", default_done_ratio: 0) }+ shared_let(:complete_status_with_100p_done_ratio) { create(:status, name: "complete", default_done_ratio: 100) }context 'when using the "status-based" % complete mode',with_settings: { work_package_done_ratio: "status" } do@@ -92,8 +91,8 @@ RSpec.describe WorkPackages::UpdateAncestorsService, type: :model doit "recomputes child remaining work and update ancestors total % complete accordingly" dovalue =case field- when :status then new_status_with_done_ratio- when :status_id then new_status_with_done_ratio.id+ when :status then complete_status_with_100p_done_ratio+ when :status_id then complete_status_with_100p_done_ratio.idendset_attributes_on(child, field => value)call_update_ancestors_service(child)@@ -107,28 +106,6 @@ RSpec.describe WorkPackages::UpdateAncestorsService, type: :model doendendend-- context "when changing child status to a status without any default done ratio" do- %i[status status_id].each do |field|- context "with the #{field} field" do- it "unsets child remaining work and update ancestors total % complete accordingly" do- value =- case field- when :status then new_status_without_done_ratio- when :status_id then new_status_without_done_ratio.id- end- set_attributes_on(child, field => value)- call_update_ancestors_service(child)-- expect_work_packages([parent, child], <<~TABLE)- | subject | work | total work | remaining work | total remaining work | % complete | total % complete |- | parent | 10h | 15h | 10h | 10h | 0% | 33% |- | child | 5h | 5h | | | | |- TABLE- end- end- end- endendendend