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

Do not set a default date in the Phase::SetAttributesService because now the scheduler takes care of default dates.

Dombi Attilaa21f72a8d807
diff --git a/app/models/project/phase.rb b/app/models/project/phase.rb
index 949bacfce8a..efaec980752 100644
--- a/app/models/project/phase.rb
+++ b/app/models/project/phase.rb
@@ -92,7 +92,7 @@ class Project::Phase < ApplicationRecord
def default_start_date
return @default_start_date if defined?(@default_start_date)
- previous_finish_date = previous_phase&.finish_date
+ previous_finish_date = previous_phase.finish_date if follows_previous_phase?
@default_start_date = previous_finish_date && Day.next_working(from: previous_finish_date).date
end
diff --git a/app/services/project_phases/set_attributes_service.rb b/app/services/project_phases/set_attributes_service.rb
index bd50bab6bbc..dd5f47dacad 100644
--- a/app/services/project_phases/set_attributes_service.rb
+++ b/app/services/project_phases/set_attributes_service.rb
@@ -35,14 +35,6 @@ module ProjectPhases
end
private
-
- def ensure_default_attributes(params)
- # Set default start date only when there is no user provided value.
- if params[:start_date].nil? && model.default_start_date.present?
- model.start_date ||= model.default_start_date
- end
- end
-
def set_calculated_duration
model.duration = model.calculate_duration
end
diff --git a/spec/models/project/phase_spec.rb b/spec/models/project/phase_spec.rb
index 6ee1bea270f..ddec300062c 100644
--- a/spec/models/project/phase_spec.rb
+++ b/spec/models/project/phase_spec.rb
@@ -186,16 +186,16 @@ RSpec.describe Project::Phase do
describe "#default_start_date" do
include_context "with project phases"
- context "when the previous phase has a finish date" do
+ context "when the previous phase has a complete date range" do
it "returns the next working day after the previous phase finish date" do
expected = Day.next_working(from: phase1.finish_date).date
expect(phase2.default_start_date).to eq(expected)
end
end
- context "when the previous phase does not have a finish date" do
+ context "when the previous phase has an incomplete date range" do
before do
- phase1.update(finish_date: nil)
+ phase1.update(start_date: nil)
end
it "returns nil" do
diff --git a/spec/services/project_phases/set_attributes_service_spec.rb b/spec/services/project_phases/set_attributes_service_spec.rb
index 7a5bea3ae02..a85c9504c30 100644
--- a/spec/services/project_phases/set_attributes_service_spec.rb
+++ b/spec/services/project_phases/set_attributes_service_spec.rb
@@ -97,53 +97,5 @@ RSpec.describe ProjectPhases::SetAttributesService, type: :model do
end
end
end
-
- describe "setting default start date" do
- let(:phase) do
- build_stubbed(:project_phase, project:, start_date: previous_date)
- end
-
- context "when there is a default_start_date on the phase" do
- before do
- allow(phase).to receive(:default_start_date).and_return(date)
- end
-
- context "and the previous start date is not set" do
- let(:previous_date) { nil }
-
- it "sets the model's start_date to the default_start_date" do
- expect { subject }.to change(phase, :start_date).from(nil).to(date)
- end
- end
-
- context "and the previous start date is set" do
- let(:previous_date) { Time.zone.yesterday }
-
- it "does not sets the model's start_date to the default_start_date" do
- expect { subject }.not_to change(phase, :start_date)
- end
-
- context "and the current start date is cleared" do
- let(:call_attributes) { { start_date: "", finish_date: date + 27 } }
-
- it "sets the model's start_date to nil" do
- expect { subject }.to change(phase, :start_date).from(previous_date).to(nil)
- end
- end
- end
- end
-
- context "when there is no default_start_date on the phase" do
- let(:previous_date) { date }
-
- before do
- allow(phase).to receive(:default_start_date).and_return(nil)
- end
-
- it "does not set the model's start_date" do
- expect { subject }.not_to change(phase, :start_date).from(date)
- end
- end
- end
end
end