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
[44900] Set due date to start date for new milestone work packages (#11650)
Christophe Bliard41673971c618
diff --git a/.rubocop.yml b/.rubocop.ymlindex 668407da28e..4016ed01383 100644--- a/.rubocop.yml+++ b/.rubocop.yml@@ -222,13 +222,14 @@ RSpec/NamedSubject:RSpec/ContextWording:Prefixes:- as+ - for+ - if- 'on'+ - to+ - unless- when- with- without- - if- - unless- - forRSpec/FactoryBot/SyntaxMethods:Enabled: truediff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rbindex d29b08fab1d..9d7aab4b1b8 100644--- a/app/services/work_packages/set_attributes_service.rb+++ b/app/services/work_packages/set_attributes_service.rb@@ -53,6 +53,7 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributesdef set_calculated_attributes(attributes)if work_package.new_record?set_default_attributes(attributes)+ unify_milestone_dateselseupdate_datesend@@ -172,9 +173,9 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributesenddef set_default_start_date(attributes)- work_package.start_date ||= if attributes.has_key?(:start_date)- nil- elsif parent_start_earlier_than_due?+ return if attributes.has_key?(:start_date)++ work_package.start_date ||= if parent_start_earlier_than_due?work_package.parent.start_dateelsif Setting.work_package_startdate_is_adddate?Time.zone.today@@ -182,9 +183,9 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributesenddef set_default_due_date(attributes)- work_package.due_date ||= if attributes.has_key?(:due_date)- nil- elsif parent_due_later_than_start?+ return if attributes.has_key?(:due_date)++ work_package.due_date ||= if parent_due_later_than_start?work_package.parent.due_dateendend@@ -249,7 +250,7 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributesenddef update_dates- unify_dates if work_package_now_milestone?+ unify_milestone_datesmin_start = new_start_date@@ -259,7 +260,9 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributeswork_package.start_date = min_startend- def unify_dates+ def unify_milestone_dates+ return unless work_package_now_milestone?+unified_date = work_package.due_date || work_package.start_datework_package.start_date = work_package.due_date = unified_dateenddiff --git a/modules/team_planner/spec/support/pages/team_planner.rb b/modules/team_planner/spec/support/pages/team_planner.rbindex cb8763461c4..cf066d8a751 100644--- a/modules/team_planner/spec/support/pages/team_planner.rb+++ b/modules/team_planner/spec/support/pages/team_planner.rb@@ -86,8 +86,10 @@ module Pagesdef switch_view_mode(text)find('[data-qa-selector="op-team-planner--view-select-dropdown"]').click- within('#op-team-planner--view-select-dropdown') do- click_button(text)+ retry_block do+ within('#op-team-planner--view-select-dropdown') do+ click_button(text)+ endendexpect_view_mode(text)diff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rbindex 73c621c2398..7b28f4867a3 100644--- a/spec/services/work_packages/set_attributes_service_spec.rb+++ b/spec/services/work_packages/set_attributes_service_spec.rb@@ -1295,17 +1295,13 @@ describe WorkPackages::SetAttributesService,endcontext 'when switching the type' do- let(:target_type) { build_stubbed(:type) }+ let(:target_type) { build_stubbed(:type, is_milestone:) }let(:work_package) dobuild_stubbed(:work_package, start_date: Time.zone.today - 6.days, due_date: Time.zone.today)end- context 'with a type that is no milestone' do- before do- allow(target_type)- .to receive(:is_milestone?)- .and_return(false)- end+ context 'to a non-milestone type' do+ let(:is_milestone) { false }it 'keeps the start date' doinstance.call(type: target_type)@@ -1328,59 +1324,74 @@ describe WorkPackages::SetAttributesService,endend- context 'with a type that is a milestone and with both dates set' do- before do- allow(target_type)- .to receive(:is_milestone?)- .and_return(true)- end+ context 'to a milestone type' do+ let(:is_milestone) { true }- it 'sets the start date to the due date' do- instance.call(type: target_type)+ context 'with both dates set' do+ it 'sets the start date to the due date' do+ instance.call(type: target_type)- expect(work_package.start_date).to eql Time.zone.today- end+ expect(work_package.start_date).to eq work_package.due_date+ end- it 'keeps the due date' do- instance.call(type: target_type)+ it 'keeps the due date' do+ instance.call(type: target_type)- expect(work_package.due_date).to eql Time.zone.today- end+ expect(work_package.due_date).to eql Time.zone.today+ end- it 'sets the duration to 1 (to be changed to 0 later on)' do- instance.call(type: target_type)+ it 'sets the duration to 1 (to be changed to 0 later on)' do+ instance.call(type: target_type)- expect(work_package.duration).to eq 1+ expect(work_package.duration).to eq 1+ endend- end- context 'with a type that is a milestone and with only the start date set' do- let(:work_package) do- build_stubbed(:work_package, start_date: Time.zone.today - 6.days)- end+ context 'with only the start date set' do+ let(:work_package) do+ build_stubbed(:work_package, start_date: Time.zone.today - 6.days)+ end- before do- allow(target_type)- .to receive(:is_milestone?)- .and_return(true)- end+ it 'keeps the start date' do+ instance.call(type: target_type)- it 'keeps the start date' do- instance.call(type: target_type)+ expect(work_package.start_date).to eql Time.zone.today - 6.days+ end- expect(work_package.start_date).to eql Time.zone.today - 6.days- end+ it 'set the due date to the start date' do+ instance.call(type: target_type)- it 'set the due date to the start date' do- instance.call(type: target_type)+ expect(work_package.due_date).to eql work_package.start_date+ end- expect(work_package.due_date).to eql Time.zone.today - 6.days- end+ it 'keeps the duration at 1 (to be changed to 0 later on)' do+ instance.call(type: target_type)- it 'keeps the duration at 1 (to be changed to 0 later on)' do- instance.call(type: target_type)+ expect(work_package.duration).to eq 1+ end- expect(work_package.duration).to eq 1+ context 'with a new work package' do+ let(:work_package) do+ build(:work_package, start_date: Time.zone.today - 6.days)+ end+ let(:call_attributes) { { type: target_type, start_date: Time.zone.today - 6.days, due_date: nil, duration: nil } }++ before do+ instance.call(call_attributes)+ end++ it 'keeps the start date' do+ expect(work_package.start_date).to eq Time.zone.today - 6.days+ end++ it 'set the due date to the start date' do+ expect(work_package.due_date).to eq work_package.start_date+ end++ it 'keeps the duration at 1 (to be changed to 0 later on)' do+ expect(work_package.duration).to eq 1+ end+ endendendend