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
Do not try to set invalid duration for deriving due date
Oliver Günther7e20e0628884
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rbindex a2cabd2b3da..6e9fa9fd7d9 100644--- a/app/services/work_packages/set_attributes_service.rb+++ b/app/services/work_packages/set_attributes_service.rb@@ -419,11 +419,15 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributeselsif reuse_current_due_date?# if due date is before start date, then start is used as due date.[min_start, work_package.due_date].max- elsif work_package.duration+ elsif duration_assignable?days.due_date(min_start, work_package.duration)endend+ def duration_assignable?+ work_package&.duration.is_a?(Integer) && work_package.duration > 0+ end+def reuse_current_due_date?return false if work_package.due_date.nil?return true if work_package.ignore_non_working_days_came_from_user?diff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rbindex 781d27f7267..b3bc0b32424 100644--- a/spec/services/work_packages/set_attributes_service_spec.rb+++ b/spec/services/work_packages/set_attributes_service_spec.rb@@ -1058,6 +1058,46 @@ RSpec.describe WorkPackages::SetAttributesService,endend+ context "with zero duration" do+ let(:work_package) do+ build_stubbed(:work_package, start_date: Time.zone.today, due_date: Time.zone.today + 5.days)+ end+ let(:call_attributes) { { duration: 0 } }+ let(:expected_attributes) { {} }++ it_behaves_like "service call" do+ it "keeps the dates and duration values (error to be detected by contract)" do+ subject++ expect(work_package.start_date)+ .to eq(Time.zone.today)+ expect(work_package.due_date)+ .to eq(Time.zone.today + 5.days)+ expect(work_package.duration)+ .to eq(0)+ end+ end++ context "when the work package has a soonest_start from a predecessor (Regression #63598)" do+ before do+ allow(instance).to receive(:new_start_date).and_return(Time.zone.yesterday)+ end++ it_behaves_like "service call" do+ it "keeps the dates and duration values (error to be detected by contract)" do+ subject++ expect(work_package.start_date)+ .to eq(Time.zone.yesterday)+ expect(work_package.due_date)+ .to be_nil+ expect(work_package.duration)+ .to eq(0)+ end+ end+ end+ end+context "with invalid duration (when the duration is text)" dolet(:work_package) dobuild_stubbed(:work_package, start_date: Time.zone.today, due_date: Time.zone.today + 5.days)diff --git a/spec/services/work_packages/update_service_integration_spec.rb b/spec/services/work_packages/update_service_integration_spec.rbindex 4ba40e7efae..948e3b8194f 100644--- a/spec/services/work_packages/update_service_integration_spec.rb+++ b/spec/services/work_packages/update_service_integration_spec.rb@@ -717,6 +717,43 @@ RSpec.describe WorkPackages::UpdateService, "integration", type: :model doendend+ describe "setting duration of a work_package with a predecessor to zero (Regression #63598)" do+ let_work_packages(<<~TABLE)+ hierarchy | MTWTFSS | scheduling mode | predecessors+ predecessor | X | manual |+ follower | X | automatic | predecessor+ TABLE+ let(:attributes) do+ {+ duration: 0+ }+ end++ it "rejects the change" do+ expect(subject)+ .to be_success++ # Returns changed work packages+ expect(subject.all_results)+ .to contain_exactly(work_package,+ following_parent_work_package, following_work_package,+ following2_parent_work_package, following2_work_package,+ following3_parent_work_package, following3_work_package)++ expect_work_packages(subject.all_results + [following3_sibling_work_package], <<~TABLE)+ subject | MTWTFSS |+ work_package | XXXXXX |+ following_parent_work_package | XXXXXXXXXXXXXXX |+ following_work_package | XXXXXXXXXXXXXXX |+ following2_parent_work_package | XXXXX |+ following2_work_package | XXXXX |+ following3_parent_work_package | XXXXXX |+ following3_work_package | XXXXX |+ following3_sibling_work_package | XXXXX |+ TABLE+ end+ end+describe "rescheduling work packages with a parent having a follows relation (Regression #43220)" dolet(:predecessor_attributes) do{