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
[62891][63152] Recalculate start date when toggling "Working days only"
Christophe Bliard7661671465c8
diff --git a/app/components/work_package_relations_tab/closest_relation.rb b/app/components/work_package_relations_tab/closest_relation.rbindex aca6408807b..8c9f0646ae4 100644--- a/app/components/work_package_relations_tab/closest_relation.rb+++ b/app/components/work_package_relations_tab/closest_relation.rb@@ -57,7 +57,7 @@ module WorkPackageRelationsTabdef soonest_startreturn @soonest_start if defined?(@soonest_start)- @soonest_start = relation.successor_soonest_start(gap: 0.days)+ @soonest_start = relation.successor_soonest_startenddef inspectdiff --git a/app/components/work_packages/date_picker/form_component.html.erb b/app/components/work_packages/date_picker/form_component.html.erbindex 1dc490678e9..e3cd37f7df1 100644--- a/app/components/work_packages/date_picker/form_component.html.erb+++ b/app/components/work_packages/date_picker/form_component.html.erb@@ -105,7 +105,6 @@ignore_non_working_days: work_package.ignore_non_working_days,schedule_manually:,is_schedulable: !disabled?,- minimal_scheduling_date:,is_milestone: milestone?,date_mode:,start_date_field_id: "work_package_start_date",diff --git a/app/components/work_packages/date_picker/form_component.rb b/app/components/work_packages/date_picker/form_component.rbindex 63fc7f0299c..c47030dde85 100644--- a/app/components/work_packages/date_picker/form_component.rb+++ b/app/components/work_packages/date_picker/form_component.rb@@ -95,10 +95,6 @@ module WorkPackagesdef disabled_checkbox?!schedule_manually && work_package.children.any?end-- def minimal_scheduling_date- schedule_manually ? nil : work_package.start_date- endendendenddiff --git a/app/models/relation.rb b/app/models/relation.rbindex 015e0be9ec7..9cf62abcd81 100644--- a/app/models/relation.rb+++ b/app/models/relation.rb@@ -173,11 +173,10 @@ class Relation < ApplicationRecordsuccessor.start_date || successor.due_dateend- def successor_soonest_start(gap: 1.day)+ def successor_soonest_startif follows? && predecessor_date- days = WorkPackages::Shared::Days.for(from)- relation_start_date = predecessor_date + gap- days.soonest_working_day(relation_start_date, lag:)+ days = WorkPackages::Shared::WorkingDays.new+ days.add_lag(predecessor_date, lag)endenddiff --git a/app/models/work_package/scheduling_rules.rb b/app/models/work_package/scheduling_rules.rbindex 9254e040329..fea115a96a2 100644--- a/app/models/work_package/scheduling_rules.rb+++ b/app/models/work_package/scheduling_rules.rb@@ -33,32 +33,40 @@ module WorkPackage::SchedulingRules!schedule_manually?end- # TODO: move into work package contract (possibly a module included into the contract)- # Calculates the minimum date that- # will not violate the precedes relations (max(finish date, start date) + relation lag)- # of this work package or its ancestors- # e.g.- # AP(due_date: 2017/07/25)-precedes(lag: 0)-A- # |+ # Calculates the minimum date that will not violate the precedes relations+ # (max(finish date, start date) + relation lag) of this work package or its+ # ancestors+ #+ # Lag is the number of non working days between 2 work packages of a+ # follows/precedes relation.+ #+ # For instance:+ # AP -------------- precedes ----- A+ # (due_date: 2017/07/25) (lag: 0) |# parent# |- # BP(due_date: 2017/07/22)-precedes(lag: 2)-B- # |+ # BP -------------- precedes ----- B+ # (due_date: 2017/07/22) (lag: 2) |# parent# |- # CP(due_date: 2017/07/25)-precedes(lag: 2)-C+ # CP -------------- precedes ----- C+ # (due_date: 2017/07/25) (lag: 2)+ #+ # Then successor_soonest_start for each relation is:+ # A is 2017/07/26 (AP due date: 25, no lag => 26)+ # B is 2017/07/27 (BP due date: 22, 23 and 24 are non-working days, 25 and 26 is the 2 days lag => 27)+ # C is 2017/07/28 (CP due date: 25, 26 and 27 is the 2 days lag => 28)#- # Then soonest_start for:- # C is 2017/07/28- # B is 2017/07/26- # A is 2017/07/26+ # The soonest start for this work package is the maximum of these values: 2017/07/28.def soonest_start- # eager load `to` and `from` to avoid n+1 on successor_soonest_start- @soonest_start ||=+ # eager load `to` to avoid n+1 in #successor_soonest_start+ @scheduling_relations_soonest_start ||=Relation.used_for_scheduling_of(self)- .includes(:to, :from)+ .includes(:to).filter_map(&:successor_soonest_start).max+ WorkPackages::Shared::Days.for(self)+ .soonest_working_day(@scheduling_relations_soonest_start)endenddiff --git a/app/services/work_packages/schedule_dependency/dependency.rb b/app/services/work_packages/schedule_dependency/dependency.rbindex 67b4c59deec..3edb25a340e 100644--- a/app/services/work_packages/schedule_dependency/dependency.rb+++ b/app/services/work_packages/schedule_dependency/dependency.rb@@ -56,6 +56,7 @@ class WorkPackages::ScheduleDependency::Dependencyfollows_relations.filter_map(&:successor_soonest_start).max+ .then { days.soonest_working_day(it) }enddef start_date@@ -91,4 +92,8 @@ class WorkPackages::ScheduleDependency::Dependencydef alive_descendants_datesalive_descendants.filter_map(&:due_date) + alive_descendants.filter_map(&:start_date)end++ def days+ WorkPackages::Shared::Days.for(work_package)+ endenddiff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rbindex b5971262e7e..7713b0b7be7 100644--- a/app/services/work_packages/set_attributes_service.rb+++ b/app/services/work_packages/set_attributes_service.rb@@ -293,6 +293,7 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributesenddef update_dates_from_self+ # this method is only called by #update_dates when there are no childrenmin_start = new_start_datereturn unless min_start@@ -388,6 +389,7 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributesenddef new_start_date+ # this method is only called by #update_dates_from_self when there are no childrenif work_package.schedule_manually?# Weird rule from SetScheduleService: if the work package does not have a# start date, it inherits it from the parent soonest start, regardless of@@ -409,24 +411,22 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributesenddef new_start_date_from_self- return unless work_package.schedule_manually_changed?+ # this method is only called by #new_start_date when there are no children+ return unless work_package.schedule_manually_changed? || work_package.ignore_non_working_days_changed?- [min_child_date, work_package.soonest_start].compact.max+ work_package.soonest_startenddef new_due_date(min_start)- duration = children_duration || work_package.duration- return unless work_package.due_date || duration-- due_date =- if duration- days.due_date(min_start, duration)- else- work_package.due_date- end-- # if due date is before start date, then start is used as due date.- [min_start, due_date].max+ # this method is only called by #update_dates_from_self when there are no children+ if work_package.due_date_came_from_user?+ work_package.due_date+ elsif work_package.duration+ days.due_date(min_start, work_package.duration)+ elsif work_package.due_date+ # if due date is before start date, then start is used as due date.+ [min_start, work_package.due_date].max+ endenddef work_packagediff --git a/app/services/work_packages/shared/all_days.rb b/app/services/work_packages/shared/all_days.rbindex 0824e79c354..6c66221440f 100644--- a/app/services/work_packages/shared/all_days.rb+++ b/app/services/work_packages/shared/all_days.rb@@ -43,6 +43,11 @@ module WorkPackagesWorkingDays.new.lag(predecessor_date, successor_date)end+ def add_lag(date, lag)+ # lag is *always* excluding non-working days (at least for now)+ WorkingDays.new.add_lag(date, lag)+ end+def start_date(due_date, duration)return nil unless due_date && durationraise ArgumentError, "duration must be strictly positive" if duration.is_a?(Integer) && duration <= 0@@ -57,9 +62,8 @@ module WorkPackagesstart_date + duration - 1end- def soonest_working_day(date, lag: nil)- lag ||= 0- date + lag.days if date+ def soonest_working_day(date)+ dateenddef working?(_date)diff --git a/app/services/work_packages/shared/working_days.rb b/app/services/work_packages/shared/working_days.rbindex cdf007b285d..4335b81c9b4 100644--- a/app/services/work_packages/shared/working_days.rb+++ b/app/services/work_packages/shared/working_days.rb@@ -40,7 +40,7 @@ module WorkPackagesdef duration(start_date, due_date)return nil unless start_date && due_date- (start_date..due_date).count { working?(_1) }+ (start_date..due_date).count { working?(it) }end# Returns the number of working days between a predecessor date and@@ -51,6 +51,18 @@ module WorkPackagesduration(predecessor_date + 1.day, successor_date - 1.day)end+ def add_lag(date, lag)+ return nil unless date++ date_after_lag = date + 1.day+ lag ||= 0+ while lag > 0+ lag -= 1 if working?(date_after_lag)+ date_after_lag += 1+ end+ date_after_lag+ end+def start_date(due_date, duration)assert_strictly_positive_duration(duration)return nil unless due_date && duration@@ -75,16 +87,9 @@ module WorkPackagesdue_dateend- def soonest_working_day(date, lag: nil)+ def soonest_working_day(date)return unless date- lag ||= 0-- while lag > 0- lag -= 1 if working?(date)- date += 1- end-until working?(date)date += 1end@@ -127,7 +132,7 @@ module WorkPackagesdef assert_some_working_week_days_existreturn if @working_week_days_exist- if working_week_days.all? { |working| working == false }+ if working_week_days.all?(false)raise "cannot have all week days as non-working days"enddiff --git a/frontend/src/app/core/datetime/timezone.service.ts b/frontend/src/app/core/datetime/timezone.service.tsindex ff6714bc718..9ae12ed8e4b 100644--- a/frontend/src/app/core/datetime/timezone.service.ts+++ b/frontend/src/app/core/datetime/timezone.service.ts@@ -132,6 +132,10 @@ export class TimezoneService {return moment.duration(input, unit).toISOString();}+ public utcDateToLocalDate(date:Date):Date {+ return new Date(date.getTime() + date.getTimezoneOffset() * 60 * 1000);+ }+public utcDateToISODateString(date:Date):string {return moment.utc(date).format('YYYY-MM-DD');}diff --git a/frontend/src/app/shared/components/datepicker/wp-date-picker-modal/wp-date-picker-instance.component.ts b/frontend/src/app/shared/components/datepicker/wp-date-picker-modal/wp-date-picker-instance.component.tsindex f276283f6e8..83e2bb6238b 100644--- a/frontend/src/app/shared/components/datepicker/wp-date-picker-modal/wp-date-picker-instance.component.ts+++ b/frontend/src/app/shared/components/datepicker/wp-date-picker-modal/wp-date-picker-instance.component.ts@@ -71,7 +71,6 @@ export class OpWpDatePickerInstanceComponent extends UntilDestroyedMixin impleme@Input() public dueDate:string|null;@Input() public isSchedulable:boolean = true;- @Input() public minimalSchedulingDate:Date|null;@Input() public dateMode:DateMode;@Input() startDateFieldId:string;@@ -85,6 +84,7 @@ export class OpWpDatePickerInstanceComponent extends UntilDestroyedMixin implemeprivate datePickerInstance:DatePicker;private startDateValue:Date|null;private dueDateValue:Date|null;+ private minimalSchedulingDate:Date|null;private onFlatpickrSetValuesBound = this.onFlatpickrSetValues.bind(this);constructor(@@ -101,6 +101,7 @@ export class OpWpDatePickerInstanceComponent extends UntilDestroyedMixin implemepopulateInputsFromDataset(this);this.startDateValue = this.toDate(this.startDate);this.dueDateValue = this.toDate(this.dueDate);+ this.computeMinimalSchedulingDate();}ngAfterViewInit():void {@@ -130,6 +131,7 @@ export class OpWpDatePickerInstanceComponent extends UntilDestroyedMixin impleme// that date if it's not visible.const dateToJumpTo = this.findDateToJumpTo(details.dates);[this.startDateValue, this.dueDateValue] = details.dates;+ this.computeMinimalSchedulingDate();this.setDatePickerDates(details.dates, dateToJumpTo);this.datePickerInstance.setOption('mode', details.mode);@@ -145,6 +147,10 @@ export class OpWpDatePickerInstanceComponent extends UntilDestroyedMixin impleme}}+ private computeMinimalSchedulingDate() {+ this.minimalSchedulingDate = this.startDateValue && this.timezoneService.utcDateToLocalDate(this.startDateValue);+ }+private findDateToJumpTo(dates:Date[]):Date|null {const [start, end] = dates;if (start && start?.getTime() !== this.startDateValue?.getTime()) {@@ -250,11 +256,10 @@ export class OpWpDatePickerInstanceComponent extends UntilDestroyedMixin impleme}private isDayDisabled(dayElement:DayElement):boolean {- const minimalDate = this.minimalSchedulingDate || null;return !this.isSchedulable|| (!this.scheduleManually- && !!minimalDate- && dayElement.dateObj.setHours(0, 0, 0, 0) < new Date(minimalDate).setHours(0, 0, 0, 0));+ && !!this.minimalSchedulingDate+ && dayElement.dateObj < this.minimalSchedulingDate);}/**diff --git a/spec/components/work_package_relations_tab/closest_relation_spec.rb b/spec/components/work_package_relations_tab/closest_relation_spec.rbindex 795514e5ac5..4c4ccc9ee4e 100644--- a/spec/components/work_package_relations_tab/closest_relation_spec.rb+++ b/spec/components/work_package_relations_tab/closest_relation_spec.rb@@ -215,21 +215,21 @@ RSpec.describe WorkPackageRelationsTab::ClosestRelation dolet(:due_date) { Date.new(2020, 7, 14) }context "without a lag" do- it "returns the due date" do- expect(closest_relation(due_date:).soonest_start).to eq(Date.new(2020, 7, 14))+ it "returns the day after the due date" do+ expect(closest_relation(due_date:).soonest_start).to eq(Date.new(2020, 7, 15))endendcontext "with a positive lag" do- it "returns the combined due date and lag" do- expect(closest_relation(lag: 11, due_date:).soonest_start).to eq(Date.new(2020, 7, 25))+ it "returns the day after the due date plus the lag" do+ expect(closest_relation(lag: 3, due_date:).soonest_start).to eq(Date.new(2020, 7, 18))endendcontext "with a negative lag" doit "returns the combined due date and lag" dopending "negative lags are not yet implemented"- expect(closest_relation(lag: -2, due_date:).soonest_start).to eq(Date.new(2020, 7, 12))+ expect(closest_relation(lag: -2, due_date:).soonest_start).to eq(Date.new(2020, 7, 13))endendend@@ -238,21 +238,21 @@ RSpec.describe WorkPackageRelationsTab::ClosestRelation dolet(:start_date) { Date.new(2020, 7, 14) }context "with a zero lag" do- it "returns the start date" do- expect(closest_relation(start_date:).soonest_start).to eq(Date.new(2020, 7, 14))+ it "returns the day after the start date" do+ expect(closest_relation(start_date:).soonest_start).to eq(Date.new(2020, 7, 15))endendcontext "with a positive lag" do- it "returns the combined start date and lag" do- expect(closest_relation(lag: 11, start_date:).soonest_start).to eq(Date.new(2020, 7, 25))+ it "returns the day after the start date plus the lag" do+ expect(closest_relation(lag: 3, start_date:).soonest_start).to eq(Date.new(2020, 7, 18))endendcontext "with a negative lag" doit "returns the combined start date and lag" dopending "negative lags are not yet implemented (Feature OP#38606)"- expect(closest_relation(lag: -2, start_date:).soonest_start).to eq(Date.new(2020, 7, 12))+ expect(closest_relation(lag: -2, start_date:).soonest_start).to eq(Date.new(2020, 7, 13))endendend@@ -263,7 +263,7 @@ RSpec.describe WorkPackageRelationsTab::ClosestRelation doit "outputs object for debugging" doexpect(subject.inspect)- .to start_with("#<WorkPackageRelationsTab::ClosestRelation soonest_start: 2022-07-07")+ .to start_with("#<WorkPackageRelationsTab::ClosestRelation soonest_start: 2022-07-08").and include(subject.relation.inspect)endenddiff --git a/spec/features/work_packages/datepicker/datepicker_follows_relation_spec.rb b/spec/features/work_packages/datepicker/datepicker_follows_relation_spec.rbindex 717714add73..f84f70eedfc 100644--- a/spec/features/work_packages/datepicker/datepicker_follows_relation_spec.rb+++ b/spec/features/work_packages/datepicker/datepicker_follows_relation_spec.rb@@ -39,8 +39,8 @@ RSpec.describe "Datepicker logic on follow relationships", :js, with_settings: {create(:work_package,type:,project:,- start_date: Date.parse("2024-02-01"),- due_date: Date.parse("2024-02-01"))+ start_date: Date.parse("2024-02-02"),+ due_date: Date.parse("2024-02-02"))end# assume sat+sun are non-working daysshared_let(:week_days) { week_with_saturday_and_sunday_as_weekend }@@ -61,70 +61,86 @@ RSpec.describe "Datepicker logic on follow relationships", :js, with_settings: {datepicker.expect_visibleend- context "if the follower is a task" do- let!(:follower) do- create(:work_package,- type:,- project:,- schedule_manually: false,- start_date: Date.parse("2024-02-02"),- due_date: Date.parse("2024-02-06"))- end- let!(:relation) { create(:follows_relation, from: follower, to: predecessor) }- let(:date_field) { work_packages_page.edit_field(:combinedDate) }-- it "keeps the minimum dates disabled" do- datepicker.expect_working_days_only true- datepicker.expect_automatic_scheduling_mode-- datepicker.show_date "2024-02-01"- datepicker.expect_disabled Date.parse("2024-02-01") # predecessor's due date- datepicker.expect_not_disabled Date.parse("2024-02-02")- datepicker.expect_disabled Date.parse("2024-02-03") # Saturday is non-working day- datepicker.expect_disabled Date.parse("2024-02-04") # Sunday is non-working day- datepicker.expect_not_disabled Date.parse("2024-02-05")- datepicker.expect_not_disabled Date.parse("2024-02-06")- datepicker.expect_not_disabled Date.parse("2024-02-07")-- datepicker.toggle_working_days_only- datepicker.expect_working_days_only false-- datepicker.expect_disabled Date.parse("2024-02-01") # predecessor's due date- datepicker.expect_not_disabled Date.parse("2024-02-02")- datepicker.expect_not_disabled Date.parse("2024-02-03") # Saturday is non-working day but ignored- datepicker.expect_not_disabled Date.parse("2024-02-04") # Sunday is non-working day but ignored- datepicker.expect_not_disabled Date.parse("2024-02-05")- datepicker.expect_not_disabled Date.parse("2024-02-06")- datepicker.expect_not_disabled Date.parse("2024-02-07")+ for_each_context "with default browser timezone",+ "with a negative browser timezone (New York)" do+ context "if the follower is a task" do+ let!(:follower) do+ create(:work_package,+ type:,+ project:,+ schedule_manually: false,+ start_date: Date.parse("2024-02-05"),+ due_date: Date.parse("2024-02-08"))+ end+ let!(:relation) { create(:follows_relation, from: follower, to: predecessor) }+ let(:date_field) { work_packages_page.edit_field(:combinedDate) }++ it "keeps the minimum dates disabled" do+ datepicker.expect_working_days_only true+ datepicker.expect_automatic_scheduling_mode++ datepicker.show_date "2024-02-01"+ datepicker.expect_disabled Date.parse("2024-02-01")+ datepicker.expect_disabled Date.parse("2024-02-02") # predecessor's due date+ datepicker.expect_disabled Date.parse("2024-02-03") # Saturday is non-working day+ datepicker.expect_disabled Date.parse("2024-02-04") # Sunday is non-working day+ datepicker.expect_not_disabled Date.parse("2024-02-05")+ datepicker.expect_not_disabled Date.parse("2024-02-06")+ datepicker.expect_not_disabled Date.parse("2024-02-07")++ datepicker.toggle_working_days_only+ datepicker.expect_working_days_only false++ datepicker.expect_start_date "2024-02-03", disabled: true+ datepicker.expect_due_date "2024-02-06"+ datepicker.expect_disabled Date.parse("2024-02-01")+ datepicker.expect_disabled Date.parse("2024-02-02") # predecessor's due date+ datepicker.expect_not_disabled Date.parse("2024-02-03") # Saturday is non-working day but ignored+ datepicker.expect_not_disabled Date.parse("2024-02-04") # Sunday is non-working day but ignored+ datepicker.expect_not_disabled Date.parse("2024-02-05")+ datepicker.expect_not_disabled Date.parse("2024-02-06")+ datepicker.expect_not_disabled Date.parse("2024-02-07")++ datepicker.toggle_working_days_only+ datepicker.expect_working_days_only true++ datepicker.expect_start_date "2024-02-05", disabled: true+ datepicker.expect_due_date "2024-02-08"+ datepicker.expect_disabled Date.parse("2024-02-02") # predecessor's due date+ datepicker.expect_disabled Date.parse("2024-02-03") # Saturday is non-working day+ datepicker.expect_disabled Date.parse("2024-02-04") # Sunday is non-working day+ datepicker.expect_not_disabled Date.parse("2024-02-05")+ endend- end- context "if the follower is a milestone" do- let!(:follower) do- create(:work_package,- type: milestone_type,- project:,- schedule_manually: false,- start_date: Date.parse("2024-02-02"),- due_date: Date.parse("2024-02-02"))- end- let!(:relation) { create(:follows_relation, from: follower, to: predecessor) }- let(:date_field) { work_packages_page.edit_field(:date) }+ context "if the follower is a milestone" do+ let!(:follower) do+ create(:work_package,+ type: milestone_type,+ project:,+ schedule_manually: false,+ start_date: Date.parse("2024-02-05"),+ due_date: Date.parse("2024-02-05"))+ end+ let!(:relation) { create(:follows_relation, from: follower, to: predecessor) }+ let(:date_field) { work_packages_page.edit_field(:date) }- it "disables the whole date picker" do- datepicker.expect_working_days_only true- datepicker.expect_automatic_scheduling_mode+ it "disables the whole date picker" do+ datepicker.expect_working_days_only true+ datepicker.expect_automatic_scheduling_mode- datepicker.show_date "2024-02-02"- 1.upto(29) do |day|- datepicker.expect_disabled Date.parse("2024-02-%02d" % day)- end+ datepicker.show_date "2024-02-02"+ 1.upto(29) do |day|+ datepicker.expect_disabled Date.parse("2024-02-%02d" % day)+ end- datepicker.toggle_working_days_only- datepicker.expect_working_days_only false+ datepicker.toggle_working_days_only+ datepicker.expect_working_days_only false- 1.upto(29) do |day|- datepicker.expect_disabled Date.parse("2024-02-%02d" % day)+ datepicker.expect_start_date "2024-02-03", disabled: true+ 1.upto(29) do |day|+ datepicker.expect_disabled Date.parse("2024-02-%02d" % day)+ endendendenddiff --git a/spec/features/work_packages/datepicker/datepicker_logic_spec.rb b/spec/features/work_packages/datepicker/datepicker_logic_spec.rbindex c7bebb0eb5a..64aa28e34bb 100644--- a/spec/features/work_packages/datepicker/datepicker_logic_spec.rb+++ b/spec/features/work_packages/datepicker/datepicker_logic_spec.rb@@ -54,20 +54,6 @@ RSpec.describe "Datepicker modal logic test cases (WP #43539)", :js, with_settinlet(:current_user) { user }let(:work_package) { bug_wp }- shared_context "with default browser timezone" do- let(:_comment) do- "This context does not try to override the browser timezone. " \- "It will be the same as the system (positive offset for European devs, UTC for CI)."- end- end-- shared_context "with a negative browser timezone (New York)", driver: :chrome_new_york_time_zone do- let(:_comment) do- "This context overrides browser timezone to be America/New_York. " \- "Timezone offset is -4/-5 hours (EDT/EST)."- end- end-def apply_and_expect_saved(attributes)date_field.save!diff --git a/spec/models/relation_spec.rb b/spec/models/relation_spec.rbindex 1b72156acb1..2d46c559f96 100644--- a/spec/models/relation_spec.rb+++ b/spec/models/relation_spec.rb@@ -160,12 +160,6 @@ RSpec.describe Relation doenddescribe "#successor_soonest_start" do- let(:monday) { Date.current.next_occurring(:monday) }- let(:tuesday) { monday + 1.day }- let(:wednesday) { monday + 2.days }- let(:thursday) { monday + 3.days }- let(:friday) { monday + 4.days }-context "with a follows relation" dolet_work_packages(<<~TABLE)subject | MTWTFSS | predecessors@@ -175,7 +169,7 @@ RSpec.describe Relation doit "returns predecessor due_date + 1" dorelation = _table.relation(successor: "follower")- expect(relation.successor_soonest_start).to eq(tuesday)+ expect(relation.successor_soonest_start).to eq(_table.tuesday)endend@@ -188,7 +182,7 @@ RSpec.describe Relation doit "returns predecessor start_date + 1" dorelation = _table.relation(successor: "follower")- expect(relation.successor_soonest_start).to eq(tuesday)+ expect(relation.successor_soonest_start).to eq(_table.tuesday)endend@@ -216,13 +210,13 @@ RSpec.describe Relation doit "returns predecessor due_date + lag + 1" dorelation_a = _table.relation(successor: "follower_a")- expect(relation_a.successor_soonest_start).to eq(tuesday)+ expect(relation_a.successor_soonest_start).to eq(_table.tuesday)relation_b = _table.relation(successor: "follower_b")- expect(relation_b.successor_soonest_start).to eq(wednesday)+ expect(relation_b.successor_soonest_start).to eq(_table.wednesday)relation_c = _table.relation(successor: "follower_c")- expect(relation_c.successor_soonest_start).to eq(friday)+ expect(relation_c.successor_soonest_start).to eq(_table.friday)endend@@ -234,22 +228,27 @@ RSpec.describe Relation dofollower_lag1 | ░ ░ ░░ ░ | follows main with lag 1follower_lag2 | ░ ░ ░░ ░ | follows main with lag 2follower_lag3 | ░ ░ ░░ ░ | follows main with lag 3+ follower_lag4 | ░ ░ ░░ ░ | follows main with lag 4TABLE- it "returns a date such as the number of working days between both work package is equal to the lag" do+ it "returns the soonest date for which the number of working days between " \+ "both work packages is equal to the lag" doset_work_week("monday", "wednesday", "friday")relation_lag0 = _table.relation(successor: "follower_lag0")- expect(relation_lag0.successor_soonest_start).to eq(wednesday)+ expect(relation_lag0.successor_soonest_start).to eq(_table.tuesday)relation_lag1 = _table.relation(successor: "follower_lag1")- expect(relation_lag1.successor_soonest_start).to eq(friday)+ expect(relation_lag1.successor_soonest_start).to eq(_table.thursday) # working day in between is Wednesdayrelation_lag2 = _table.relation(successor: "follower_lag2")- expect(relation_lag2.successor_soonest_start).to eq(monday + 7.days)+ expect(relation_lag2.successor_soonest_start).to eq(_table.saturday) # working days in between are Wednesday and Fridayrelation_lag3 = _table.relation(successor: "follower_lag3")- expect(relation_lag3.successor_soonest_start).to eq(wednesday + 7.days)+ expect(relation_lag3.successor_soonest_start).to eq(_table.next_tuesday) # Wednesday, Friday, next Monday++ relation_lag4 = _table.relation(successor: "follower_lag4")+ expect(relation_lag4.successor_soonest_start).to eq(_table.next_thursday) # Wednesday, Friday, next Monday, next Wednesdayendend@@ -261,22 +260,28 @@ RSpec.describe Relation dofollower_lag1 | ░ ░ ░░ ░ | all days | follows main with lag 1follower_lag2 | ░ ░ ░░ ░ | all days | follows main with lag 2follower_lag3 | ░ ░ ░░ ░ | all days | follows main with lag 3+ follower_lag4 | ░ ░ ░░ ░ | all days | follows main with lag 4TABLE- it "returns predecessor due_date + lag + 1 (like without non-working days)" do+ it "returns the soonest date for which the number of working days between " \+ "both work packages is equal to the lag (saying it another way: it is the same " \+ "regardless of followers ignoring non-working days or not)" doset_work_week("monday", "wednesday", "friday")relation_lag0 = _table.relation(successor: "follower_lag0")- expect(relation_lag0.successor_soonest_start).to eq(tuesday)+ expect(relation_lag0.successor_soonest_start).to eq(_table.tuesday)relation_lag1 = _table.relation(successor: "follower_lag1")- expect(relation_lag1.successor_soonest_start).to eq(wednesday)+ expect(relation_lag1.successor_soonest_start).to eq(_table.thursday) # working day in between is Wednesdayrelation_lag2 = _table.relation(successor: "follower_lag2")- expect(relation_lag2.successor_soonest_start).to eq(thursday)+ expect(relation_lag2.successor_soonest_start).to eq(_table.saturday) # working days in between are Wednesday and Fridayrelation_lag3 = _table.relation(successor: "follower_lag3")- expect(relation_lag3.successor_soonest_start).to eq(friday)+ expect(relation_lag3.successor_soonest_start).to eq(_table.next_tuesday) # Wednesday, Friday, next Monday++ relation_lag4 = _table.relation(successor: "follower_lag4")+ expect(relation_lag4.successor_soonest_start).to eq(_table.next_thursday) # Wednesday, Friday, next Monday, next Wednesdayendendenddiff --git a/spec/models/work_package/work_package_relations_spec.rb b/spec/models/work_package/work_package_relations_spec.rbindex ca3a9a1ec2b..85fba2b194e 100644--- a/spec/models/work_package/work_package_relations_spec.rb+++ b/spec/models/work_package/work_package_relations_spec.rb@@ -29,6 +29,8 @@require "spec_helper"RSpec.describe WorkPackage do+ create_shared_association_defaults_for_work_package_factory+describe "#relation" dolet(:closed_state) docreate(:status,@@ -124,33 +126,38 @@ RSpec.describe WorkPackage dodescribe "#soonest_start" dolet(:predecessor) docreate(:work_package,+ subject: "predecessor",due_date: predecessor_due_date)endlet(:predecessor_due_date) { nil }let(:successor) docreate(:work_package,+ subject: "successor",schedule_manually: successor_schedule_manually,- project: predecessor.project)+ ignore_non_working_days: successor_ignore_non_working_days)endlet(:successor_schedule_manually) { false }+ let(:successor_ignore_non_working_days) { false }let(:successor_child) docreate(:work_package,+ subject: "successor_child",schedule_manually: successor_child_schedule_manually,- parent: successor,- project: predecessor.project)+ parent: successor)endlet(:successor_child_schedule_manually) { false }let(:successor_grandchild) docreate(:work_package,- parent: successor_child,- project: predecessor.project)+ subject: "successor_grandchild",+ parent: successor_child)endlet(:relation_successor) docreate(:relation,from: predecessor,to: successor,+ lag: relation_lag,relation_type: Relation::TYPE_PRECEDES)end+ let(:relation_lag) { 0 }let(:work_packages) { [predecessor, successor, successor_child] }let(:relations) { [relation_successor] }@@ -169,22 +176,101 @@ RSpec.describe WorkPackage docontext "with a predecessor" dolet(:work_packages) { [predecessor, successor] }- context "start date exists in predecessor" do- let(:predecessor_due_date) { Date.today }+ context "with a due date" do+ let(:predecessor_due_date) { Date.current }- it { expect(successor_child.soonest_start).to eq(predecessor.due_date + 1) }+ it { expect(successor.soonest_start).to eq(predecessor.due_date + 1) }end- context "no date in predecessor" do- it { expect(successor_child.soonest_start).to be_nil }+ context "without dates" do+ it { expect(successor.soonest_start).to be_nil }+ end++ context "with non-working weekends" do+ shared_let(:week_days) { week_with_saturday_and_sunday_as_weekend }++ let(:monday) { Date.current.monday }+ let(:thursday) { monday + 3.days }+ let(:friday) { monday + 4.days }+ let(:saturday) { monday + 5.days }+ let(:next_monday) { monday + 7.days }+ let(:next_tuesday) { monday + 8.days }++ context "if predecessor ends on Thursday, lag is 2 days " \+ "and successor has 'Working days only' active" do+ let(:successor_ignore_non_working_days) { false }+ let(:relation_lag) { 2 }+ let(:predecessor_due_date) { thursday }++ it "returns next Tuesday to have 2 working days in between (Friday and Monday) " \+ "as Saturday and Sunday are non-working days" do+ expect(successor.soonest_start).to eq(next_tuesday)+ end+ end++ context "if predecessor ends on Thursday, lag is 2 days " \+ "and successor has 'Working days only' inactive" do+ let(:successor_ignore_non_working_days) { true }+ let(:relation_lag) { 2 }+ let(:predecessor_due_date) { thursday }++ it "returns next Tuesday to have 2 working days in between (Friday and Monday)" do+ expect(successor.soonest_start).to eq(next_tuesday)+ end+ end++ context "if predecessor ends on Thursday, lag is 1 day " \+ "and successor has 'Working days only' active" do+ let(:successor_ignore_non_working_days) { false }+ let(:relation_lag) { 1 }+ let(:predecessor_due_date) { thursday }++ it "returns next Monday to have 1 working day in between (Friday) " \+ "as Saturday or Sunday are non-working days" do+ expect(successor.soonest_start).to eq(next_monday)+ end+ end++ context "if predecessor ends on Thursday, lag is 1 day " \+ "and successor has 'Working days only' inactive" do+ let(:successor_ignore_non_working_days) { true }+ let(:relation_lag) { 1 }+ let(:predecessor_due_date) { thursday }++ it "returns Saturday to have 1 working day in between (Friday)" do+ expect(successor.soonest_start).to eq(saturday)+ end+ end++ context "if predecessor ends on Friday, lag is 0 days " \+ "and successor has 'Working days only' active" do+ let(:successor_ignore_non_working_days) { false }+ let(:relation_lag) { 0 }+ let(:predecessor_due_date) { friday }++ it "returns next Monday as Saturday and Sunday are non-working days" do+ expect(successor.soonest_start).to eq(next_monday)+ end+ end++ context "if predecessor ends on Friday, lag is 0 days " \+ "and successor has 'Working days only' inactive" do+ let(:successor_ignore_non_working_days) { true }+ let(:relation_lag) { 0 }+ let(:predecessor_due_date) { friday }++ it "returns Saturday" do+ expect(successor.soonest_start).to eq(saturday)+ end+ endendendcontext "with the parent having a predecessor" dolet(:work_packages) { [predecessor, successor, successor_child] }- context "start date exists in predecessor" do- let(:predecessor_due_date) { Date.today }+ context "with a due date" do+ let(:predecessor_due_date) { Date.current }it { expect(successor_child.soonest_start).to eq(predecessor.due_date + 1) }@@ -195,7 +281,7 @@ RSpec.describe WorkPackage doendend- context "no start date exists in related work packages" do+ context "without dates" doit { expect(successor_child.soonest_start).to be_nil }endend@@ -203,8 +289,8 @@ RSpec.describe WorkPackage docontext "with the grandparent having a predecessor" dolet(:work_packages) { [predecessor, successor, successor_child, successor_grandchild] }- context "start date exists in predecessor" do- let(:predecessor_due_date) { Date.today }+ context "with a due date" do+ let(:predecessor_due_date) { Date.current }it { expect(successor_grandchild.soonest_start).to eq(predecessor.due_date + 1) }@@ -221,7 +307,7 @@ RSpec.describe WorkPackage doendend- context "no start date exists in related work packages" do+ context "without dates" doit { expect(successor_grandchild.soonest_start).to be_nil }endend@@ -229,8 +315,8 @@ RSpec.describe WorkPackage doenddescribe "#destroy" do- let(:work_package) { create(:work_package) }- let(:other_work_package) { create(:work_package) }+ shared_let(:work_package) { create(:work_package) }+ shared_let(:other_work_package) { create(:work_package) }context "for a work package with a relation as to" dolet!(:to_relation) { create(:follows_relation, from: other_work_package, to: work_package) }diff --git a/spec/services/work_packages/shared/all_days_spec.rb b/spec/services/work_packages/shared/all_days_spec.rbindex 26e3a8a8e86..91117812d2d 100644--- a/spec/services/work_packages/shared/all_days_spec.rb+++ b/spec/services/work_packages/shared/all_days_spec.rb@@ -69,6 +69,8 @@ RSpec.describe WorkPackages::Shared::AllDays doinclude_examples "lag computation excluding non-working days"+ include_examples "add lag to a date"+describe "#start_date" doit "returns the start date for a due date and a duration" doexpect(subject.start_date(sunday_2022_07_31, 1)).to eq(sunday_2022_07_31)@@ -144,34 +146,16 @@ RSpec.describe WorkPackages::Shared::AllDays doexpect(subject.soonest_working_day(nil)).to be_nilend- context "with lag" do- it "returns the soonest working day from the given day, after a configurable lag of working days" do- expect(subject.soonest_working_day(sunday_2022_07_31, lag: nil)).to eq(sunday_2022_07_31)- expect(subject.soonest_working_day(sunday_2022_07_31, lag: 0)).to eq(sunday_2022_07_31)- expect(subject.soonest_working_day(sunday_2022_07_31, lag: 1)).to eq(Date.new(2022, 8, 1))- end- end-context "with weekend days (Saturday and Sunday)", :weekend_saturday_sunday doit "returns the given day" doexpect(subject.soonest_working_day(sunday_2022_07_31)).to eq(sunday_2022_07_31)end-- context "with lag" do- include_examples "soonest working day with lag", date: Date.new(2022, 1, 1), lag: 30, expected: Date.new(2022, 1, 31)- endendcontext "with some non working days (Christmas 2022-12-25 and new year's day 2023-01-01)", :christmas_2022_new_year_2023 doit "returns the given day" doexpect(subject.soonest_working_day(Date.new(2022, 12, 25))).to eq(Date.new(2022, 12, 25))end-- context "with lag" do- include_examples "soonest working day with lag", date: Date.new(2022, 12, 24),- lag: 7,- expected: Date.new(2022, 12, 31)- endendendenddiff --git a/spec/services/work_packages/shared/shared_examples_days.rb b/spec/services/work_packages/shared/shared_examples_days.rbindex 513107a5fdc..85b4fb56f5c 100644--- a/spec/services/work_packages/shared/shared_examples_days.rb+++ b/spec/services/work_packages/shared/shared_examples_days.rb@@ -71,6 +71,15 @@ RSpec.shared_examples "it returns duration" do |expected_duration, start_date, dendend+RSpec.shared_examples "it adds lag" do |date:, lag:, expected_result:|+ it "from date #{date.to_fs(:wday_date)} " \+ "with lag #{lag} " \+ "=> #{expected_result.to_fs(:wday_date)}" \+ do+ expect(subject.add_lag(date, lag)).to eq(expected_result)+ end+end+RSpec.shared_examples "it returns lag" do |expected_lag, predecessor_date, successor_date|from_date_format = "%a %-d"from_date_format += " %b" if [predecessor_date.month, predecessor_date.year] != [successor_date.month, successor_date.year]@@ -102,12 +111,6 @@ RSpec.shared_examples "soonest working day" do |date:, expected:|endend-RSpec.shared_examples "soonest working day with lag" do |date:, lag:, expected:|- it "soonest_working_day(#{date.to_fs(:wday_date)}, lag: #{lag.inspect}) => #{expected.to_fs(:wday_date)}" do- expect(subject.soonest_working_day(date, lag:)).to eq(expected)- end-end-RSpec.shared_examples "lag computation excluding non-working days" dodescribe "#lag" dosunday_2022_07_31 = Date.new(2022, 7, 31)@@ -171,3 +174,65 @@ RSpec.shared_examples "lag computation excluding non-working days" doendendend++RSpec.shared_examples "add lag to a date" do+ describe "#add_lag" do+ saturday_2022_07_30 = Date.new(2022, 7, 30)+ sunday_2022_07_31 = Date.new(2022, 7, 31)+ monday_2022_08_01 = Date.new(2022, 8, 1)++ it "returns the soonest date after the given date where the number of working days in between equals the given lag" do+ expect(subject.add_lag(sunday_2022_07_31, 0)).to eq(monday_2022_08_01)+ expect(subject.add_lag(sunday_2022_07_31, 1)).to eq(Date.new(2022, 8, 2))+ expect(subject.add_lag(sunday_2022_07_31, 5)).to eq(Date.new(2022, 8, 6))+ expect(subject.add_lag(sunday_2022_07_31, 6)).to eq(Date.new(2022, 8, 7))+ end++ it "returns the day after the given date when lag is negative (like lag = 0)" do+ expect(subject.add_lag(sunday_2022_07_31, -100)).to eq(monday_2022_08_01)+ expect(subject.add_lag(sunday_2022_07_31, -1)).to eq(monday_2022_08_01)+ expect(subject.add_lag(sunday_2022_07_31, 0)).to eq(monday_2022_08_01)+ end++ it "works with big lag value like 100_000" do+ # Ensure implementation is not recursive and won't fail with SystemStackError: stack level too deep+ expect { subject.add_lag(sunday_2022_07_31, 100_000) }+ .not_to raise_error+ end++ context "with weekend days (Saturday and Sunday)", :weekend_saturday_sunday do+ include_examples "it adds lag", date: saturday_2022_07_30, lag: 0, expected_result: sunday_2022_07_31+ include_examples "it adds lag", date: saturday_2022_07_30, lag: 1, expected_result: Date.new(2022, 8, 2)++ include_examples "it adds lag", date: sunday_2022_07_31, lag: 0, expected_result: monday_2022_08_01+ include_examples "it adds lag", date: sunday_2022_07_31, lag: 1, expected_result: Date.new(2022, 8, 2)+ include_examples "it adds lag", date: sunday_2022_07_31, lag: 4, expected_result: Date.new(2022, 8, 5) # Friday+ include_examples "it adds lag", date: sunday_2022_07_31, lag: 5, expected_result: Date.new(2022, 8, 6) # Saturday+ include_examples "it adds lag", date: sunday_2022_07_31, lag: 6, expected_result: Date.new(2022, 8, 9) # Tuesday++ include_examples "it adds lag", date: monday_2022_08_01, lag: 3, expected_result: Date.new(2022, 8, 5) # Friday+ include_examples "it adds lag", date: monday_2022_08_01, lag: 4, expected_result: Date.new(2022, 8, 6) # Saturday+ include_examples "it adds lag", date: monday_2022_08_01, lag: 5, expected_result: Date.new(2022, 8, 9) # Tuesday+ end++ context "with some non working days (Christmas 2022-12-25 and new year's day 2023-01-01)", :christmas_2022_new_year_2023 do+ include_examples "it adds lag", date: Date.new(2022, 12, 24), lag: 0, expected_result: Date.new(2022, 12, 25)+ include_examples "it adds lag", date: Date.new(2022, 12, 24), lag: 1, expected_result: Date.new(2022, 12, 27)+ include_examples "it adds lag", date: Date.new(2022, 12, 24), lag: 6, expected_result: Date.new(2023, 1, 1)+ include_examples "it adds lag", date: Date.new(2022, 12, 24), lag: 7, expected_result: Date.new(2023, 1, 3)+ end++ context "with nil date" do+ it "returns nil" do+ expect(subject.add_lag(nil, 5)).to be_nil+ end+ end++ context "with nil lag" do+ it "returns the day after the given date when lag is nil (like lag = 0)" do+ expect(subject.add_lag(sunday_2022_07_31, nil)).to eq(monday_2022_08_01)+ expect(subject.add_lag(sunday_2022_07_31, 0)).to eq(monday_2022_08_01)+ end+ end+ end+enddiff --git a/spec/services/work_packages/shared/working_days_spec.rb b/spec/services/work_packages/shared/working_days_spec.rbindex e3c2d5e1feb..92019b14d1b 100644--- a/spec/services/work_packages/shared/working_days_spec.rb+++ b/spec/services/work_packages/shared/working_days_spec.rb@@ -93,6 +93,8 @@ RSpec.describe WorkPackages::Shared::WorkingDays doinclude_examples "lag computation excluding non-working days"+ include_examples "add lag to a date"+describe "#start_date" doit "returns the start date for a due date and a duration" doexpect(subject.start_date(monday_2022_08_01, 1)).to eq(monday_2022_08_01)@@ -190,49 +192,17 @@ RSpec.describe WorkPackages::Shared::WorkingDays doexpect(subject.soonest_working_day(nil)).to be_nilend- context "with lag" do- it "returns the soonest working day from the given day, after a configurable lag of working days" do- expect(subject.soonest_working_day(sunday_2022_07_31, lag: nil)).to eq(sunday_2022_07_31)- expect(subject.soonest_working_day(sunday_2022_07_31, lag: 0)).to eq(sunday_2022_07_31)- expect(subject.soonest_working_day(sunday_2022_07_31, lag: 1)).to eq(monday_2022_08_01)- end-- it "works with big lag value like 100_000" do- # First implementation was recursive and failed with SystemStackError: stack level too deep- expect { subject.soonest_working_day(sunday_2022_07_31, lag: 100_000) }- .not_to raise_error- end- end-context "with weekend days (Saturday and Sunday)", :weekend_saturday_sunday doinclude_examples "soonest working day", date: friday_2022_07_29, expected: friday_2022_07_29include_examples "soonest working day", date: saturday_2022_07_30, expected: monday_2022_08_01include_examples "soonest working day", date: sunday_2022_07_31, expected: monday_2022_08_01include_examples "soonest working day", date: monday_2022_08_01, expected: monday_2022_08_01-- context "with lag" do- include_examples "soonest working day with lag", date: friday_2022_07_29, lag: 0, expected: friday_2022_07_29- include_examples "soonest working day with lag", date: saturday_2022_07_30, lag: 0, expected: monday_2022_08_01- include_examples "soonest working day with lag", date: sunday_2022_07_31, lag: 0, expected: monday_2022_08_01- include_examples "soonest working day with lag", date: monday_2022_08_01, lag: 0, expected: monday_2022_08_01-- include_examples "soonest working day with lag", date: friday_2022_07_29, lag: 1, expected: monday_2022_08_01- include_examples "soonest working day with lag", date: saturday_2022_07_30, lag: 1, expected: Date.new(2022, 8, 2)- include_examples "soonest working day with lag", date: sunday_2022_07_31, lag: 1, expected: Date.new(2022, 8, 2)- include_examples "soonest working day with lag", date: monday_2022_08_01, lag: 1, expected: Date.new(2022, 8, 2)-- include_examples "soonest working day with lag", date: friday_2022_07_29, lag: 8, expected: Date.new(2022, 8, 10)- endendcontext "with some non working days (Christmas 2022-12-25 and new year's day 2023-01-01)", :christmas_2022_new_year_2023 doinclude_examples "soonest working day", date: Date.new(2022, 12, 25), expected: Date.new(2022, 12, 26)include_examples "soonest working day", date: Date.new(2022, 12, 31), expected: Date.new(2022, 12, 31)include_examples "soonest working day", date: Date.new(2023, 1, 1), expected: Date.new(2023, 1, 2)-- context "with lag" do- include_examples "soonest working day with lag", date: Date.new(2022, 12, 24), lag: 7, expected: Date.new(2023, 1, 2)- endendcontext "with no working days", :no_working_days dodiff --git a/spec/services/work_packages/update_service_integration_spec.rb b/spec/services/work_packages/update_service_integration_spec.rbindex a3f54355662..8529ccd28a3 100644--- a/spec/services/work_packages/update_service_integration_spec.rb+++ b/spec/services/work_packages/update_service_integration_spec.rb@@ -1301,6 +1301,85 @@ RSpec.describe WorkPackages::UpdateService, "integration", type: :model doendend+ describe "due_date and ignore_non_working_days combinations" do+ before do+ set_non_working_week_days("saturday", "sunday")+ end++ context "on an automatically scheduled successor whose start date is after a non-working day" do+ shared_let_work_packages(<<~TABLE)+ | subject | MTWTFSSmtwtfss | scheduling mode | days counting | successors+ | predecessor | XX | manual | working days only | work_package with lag 1+ | work_package | XXX | automatic | working days only |+ TABLE++ context "when setting ignore_non_working_days to true" do+ let(:attributes) { { ignore_non_working_days: true } }++ it "moves the start date earlier to start on a non-working day " \+ "and moves the due date too to keep same duration" do+ expect(subject).to be_success++ expect_work_packages_after_reload([work_package, predecessor], <<~TABLE)+ | subject | MTWTFSSmtwtfss | scheduling mode | days counting+ | predecessor | XX | manual | working days only+ | work_package | XXX | automatic | all days+ TABLE+ end+ end++ context "when setting ignore_non_working_days to true and setting a due date" do+ let(:attributes) { { ignore_non_working_days: true, due_date: _table.next_friday } }++ it "moves the start date earlier to start on a non-working day and uses the given due date" do+ expect(subject).to be_success++ expect_work_packages_after_reload([work_package, predecessor], <<~TABLE)+ | subject | MTWTFSSmtwtfss | scheduling mode | days counting+ | predecessor | XX | manual | working days only+ | work_package | XXXXXXX | automatic | all days+ TABLE+ end+ end++ context "when setting ignore_non_working_days to true and unsetting the due date" do+ let(:attributes) { { ignore_non_working_days: true, due_date: nil } }++ it "moves the start date earlier to start on a non-working day and removes the due date and duration" do+ expect(subject).to be_success++ expect_work_packages_after_reload([work_package, predecessor], <<~TABLE)+ | subject | MTWTFSSmtwtfss | duration | scheduling mode | days counting+ | predecessor | XX | 2 | manual | working days only+ | work_package | [ | | automatic | all days+ TABLE+ end+ end+ end++ context "on an automatically scheduled successor whose start and due dates are on non-working days " \+ "when setting only ignore_non_working_days to false" do+ let_work_packages(<<~TABLE)+ | subject | MTWTFSSmtwtfss | duration | scheduling mode | days counting | successors+ | predecessor | XX | 2 | manual | working days only | work_package with lag 1+ | work_package | XXXXXXXX | 8 | automatic | all days |+ TABLE++ let(:attributes) { { ignore_non_working_days: false } }++ it "moves the start date earlier to start on a non-working day " \+ "and moves the due date too to keep same duration" do+ expect(subject).to be_success++ expect_work_packages_after_reload([work_package, predecessor], <<~TABLE)+ | subject | MTWTFSSmtwtfss | duration | scheduling mode | days counting+ | predecessor | XX | 2 | manual | working days only+ | work_package | XXXXX..XXX | 8 | automatic | working days only+ TABLE+ end+ end+ end+context "when changing the type of a work package with children into a milestone" dolet_work_packages(<<~TABLE)| hierarchy | MTWTFSS | scheduling modediff --git a/spec/support/table_helpers/table.rb b/spec/support/table_helpers/table.rbindex 059c6a7f1f1..2b4becf09bc 100644--- a/spec/support/table_helpers/table.rb+++ b/spec/support/table_helpers/table.rb@@ -72,6 +72,13 @@ module TableHelpersdef friday = monday + 4.daysdef saturday = monday + 5.daysdef sunday = monday + 6.days+ def next_monday = monday + 7.days+ def next_tuesday = monday + 8.days+ def next_wednesday = monday + 9.days+ def next_thursday = monday + 10.days+ def next_friday = monday + 11.days+ def next_saturday = monday + 12.days+ def next_sunday = monday + 13.daysprivatediff --git a/spec/support/time_helpers.rb b/spec/support/time_helpers.rbindex 12c0eb90310..610ba88cf00 100644--- a/spec/support/time_helpers.rb+++ b/spec/support/time_helpers.rb@@ -47,3 +47,17 @@ RSpec::Matchers.define :equal_time_without_usec do |expected|expected_without_usec == actual_without_usecendend++RSpec.shared_context "with default browser timezone" do+ let(:_comment) do+ "This context does not try to override the browser timezone. " \+ "It will be the same as the system (positive offset for European devs, UTC for CI, etc.)."+ end+end++RSpec.shared_context "with a negative browser timezone (New York)", driver: :chrome_new_york_time_zone do+ let(:_comment) do+ "This context overrides browser timezone to be America/New_York. " \+ "Timezone offset is -4/-5 hours (EDT/EST)."+ end+end