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

Ensure duration is computed correctly

Christophe Bliard341c8f5c3dbd
diff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rb
index 4020d95cd7c..b30ac7e986a 100644
--- a/spec/services/work_packages/set_attributes_service_spec.rb
+++ b/spec/services/work_packages/set_attributes_service_spec.rb
@@ -1017,6 +1017,55 @@ describe WorkPackages::SetAttributesService,
end
end
end
+
+ context 'with non-working days' do
+ shared_let(:week_days) { create(:week_days) }
+ let(:monday) { Time.zone.today.beginning_of_week }
+ let(:wednesday) { monday + 2.days }
+ let(:next_monday) { monday + 7.days }
+
+ context 'when start date changes' do
+ let(:work_package) { build_stubbed(:work_package, start_date: monday, due_date: next_monday) }
+ let(:call_attributes) { { start_date: wednesday } }
+
+ it_behaves_like 'service call' do
+ it "updates the duration without including non-working days" do
+ expect { subject }
+ .to change(work_package, :duration)
+ .from(6)
+ .to(4)
+ end
+ end
+ end
+
+ context 'when due date changes' do
+ let(:work_package) { build_stubbed(:work_package, start_date: monday, due_date: next_monday) }
+ let(:call_attributes) { { due_date: monday + 14.days } }
+
+ it_behaves_like 'service call' do
+ it "updates the duration without including non-working days" do
+ expect { subject }
+ .to change(work_package, :duration)
+ .from(6)
+ .to(11)
+ end
+ end
+ end
+
+ context 'when duration changes' do
+ let(:work_package) { build_stubbed(:work_package, start_date: monday, due_date: next_monday) }
+ let(:call_attributes) { { duration: "13" } }
+
+ it_behaves_like 'service call' do
+ it "updates the due date from start date and duration and skips the non-working days" do
+ expect { subject }
+ .to change(work_package, :due_date)
+ .from(next_monday)
+ .to(wednesday + 14.days)
+ end
+ end
+ end
+ end
end
context 'for priority' do