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

few more tests of activation service to ensure using the correct preceding phase

Ivan Kuchincbb010c56869
diff --git a/spec/services/project_life_cycle_steps/activation_service_spec.rb b/spec/services/project_life_cycle_steps/activation_service_spec.rb
index 42175fbf02a..ff995d5bf08 100644
--- a/spec/services/project_life_cycle_steps/activation_service_spec.rb
+++ b/spec/services/project_life_cycle_steps/activation_service_spec.rb
@@ -198,6 +198,68 @@ RSpec.describe ProjectLifeCycleSteps::ActivationService, type: :model do
end
end
+ context "having multiple preceding phases with date range" do
+ let!(:phase0) { create_phase(definition: definitions[0], date_range: date - 1..date - 1, active: true) }
+ let!(:phase1) { create_phase(definition: definitions[1], date_range: date + 2..date + 3, active: true) }
+
+ let(:service) { described_class.new(user:, project:, definitions: [definitions[2]]) }
+
+ context "with date range" do
+ let!(:phase2) { create_phase(definition: definitions[2], date_range: date + 7..date + 9, active: false) }
+
+ it "reschedules starting from last preceding phase" do
+ service.call(active: true)
+
+ expect(phase0.reload).to have_attributes(start_date: date - 1, finish_date: date - 1, active: true)
+ expect(phase1.reload).to have_attributes(start_date: date + 2, finish_date: date + 3, active: true)
+ expect(phase2.reload).to have_attributes(start_date: date + 4, finish_date: date + 6, active: true)
+ end
+ end
+
+ context "when already activated" do
+ let!(:phase2) { create_phase(definition: definitions[2], date_range: date + 7..date + 9, active: true) }
+
+ it "reschedules starting from last preceding phase" do
+ service.call(active: true)
+
+ expect(phase0.reload).to have_attributes(start_date: date - 1, finish_date: date - 1, active: true)
+ expect(phase1.reload).to have_attributes(start_date: date + 2, finish_date: date + 3, active: true)
+ expect(phase2.reload).to have_attributes(start_date: date + 4, finish_date: date + 6, active: true)
+ end
+ end
+ end
+
+ context "having multiple preceding phases with date range, some inactive" do
+ let!(:phase0) { create_phase(definition: definitions[0], date_range: date - 1..date - 1, active: true) }
+ let!(:phase1) { create_phase(definition: definitions[1], date_range: date + 2..date + 3, active: false) }
+
+ let(:service) { described_class.new(user:, project:, definitions: [definitions[2]]) }
+
+ context "with date range" do
+ let!(:phase2) { create_phase(definition: definitions[2], date_range: date + 7..date + 9, active: false) }
+
+ it "reschedules starting from last preceding phase" do
+ service.call(active: true)
+
+ expect(phase0.reload).to have_attributes(start_date: date - 1, finish_date: date - 1, active: true)
+ expect(phase1.reload).to have_attributes(start_date: date + 2, finish_date: date + 3, active: false)
+ expect(phase2.reload).to have_attributes(start_date: date, finish_date: date + 2, active: true)
+ end
+ end
+
+ context "when already activated" do
+ let!(:phase2) { create_phase(definition: definitions[2], date_range: date + 7..date + 9, active: true) }
+
+ it "reschedules starting from last preceding phase" do
+ service.call(active: true)
+
+ expect(phase0.reload).to have_attributes(start_date: date - 1, finish_date: date - 1, active: true)
+ expect(phase1.reload).to have_attributes(start_date: date + 2, finish_date: date + 3, active: false)
+ expect(phase2.reload).to have_attributes(start_date: date, finish_date: date + 2, active: true)
+ end
+ end
+ end
+
context "having inactive preceding phases with date range" do
let!(:phase0) { create_phase(definition: definitions[0], date_range: date - 1..date - 1, active: false) }
let!(:phase2) { create_phase(definition: definitions[2], date_range: date + 7..date + 9, active: true) }