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 move followers backwards when rescheduling

Christophe Bliard46987a557fcc
diff --git a/app/services/work_packages/schedule_dependency/dependency.rb b/app/services/work_packages/schedule_dependency/dependency.rb
index 7b793309d30..a9581d8b323 100644
--- a/app/services/work_packages/schedule_dependency/dependency.rb
+++ b/app/services/work_packages/schedule_dependency/dependency.rb
@@ -36,7 +36,8 @@ class WorkPackages::ScheduleDependency::Dependency
:schedule_dependency
# Returns the work package ids that this work package directly depends on to
- # determine its own dates.
+ # determine its own dates. This is used for the order of the dates
+ # computations.
#
# The dates of a work package depend on its descendants and predecessors
# dates.
diff --git a/app/services/work_packages/set_schedule_service.rb b/app/services/work_packages/set_schedule_service.rb
index 9ff79fe29b8..e36e4ee20dc 100644
--- a/app/services/work_packages/set_schedule_service.rb
+++ b/app/services/work_packages/set_schedule_service.rb
@@ -130,27 +130,22 @@ class WorkPackages::SetScheduleService
# relations as they inhibit moving a work package just the same. Only leaf
# work packages are calculated like this.
#
- # work package is moved to a later date (delta positive):
- # - all following work packages are moved by the same amount unless there is
- # still a time buffer between work package and its predecessors
+ # work package is moved to a later date:
+ # - following work packages are moved forward only to ensure they start
+ # after their predecessor's finish date. They may not need to move at all
+ # when there a time buffer between a follower and its predecessors
# (predecessors can also be acquired transitively by ancestors)
#
- # work package moved to an earlier date (delta negative):
- # - all following work packages are moved by the same amount unless a
- # follows relation of the work package or one of its ancestors limits
- # moving it. Then it is moved to the earliest date possible. This
- # limitation is propagated transitively to all following work packages.
+ # work package moved to an earlier date:
+ # - following work packages do not move at all.
def reschedule_by_predecessors(scheduled, dependency)
min_start_date = dependency.soonest_start_date
return unless min_start_date
- delta = predecessor_delta(dependency)
if !scheduled.start_date
schedule_on_missing_dates(scheduled, min_start_date)
- elsif delta >= 0
+ elsif min_start_date > scheduled.start_date
reschedule_to_date(scheduled, min_start_date)
- elsif delta < 0
- reschedule_by_delta(scheduled, delta, min_start_date)
end
end
@@ -175,38 +170,6 @@ class WorkPackages::SetScheduleService
scheduled.due_date && scheduled.due_date < min_start_date ? min_start_date : scheduled.due_date)
end
- def reschedule_by_delta(scheduled, moved_delta, min_start_date)
- days = WorkPackages::Shared::Days.for(scheduled)
-
- min_start_delta = days.delta(previous: scheduled.start_date || min_start_date, current: min_start_date)
- required_delta = [min_start_delta, [moved_delta, 0].min].max
-
- new_start_date = days.add_days(scheduled.start_date, required_delta)
- new_due_date = days.due_date(new_start_date, scheduled.duration) if scheduled.due_date && scheduled.duration
- scheduled.start_date = new_start_date
- scheduled.due_date = new_due_date
- end
-
- def predecessor_delta(dependency)
- predecessor = dependency.moving_predecessors.first
- return 0 unless predecessor
-
- days = WorkPackages::Shared::Days.for(dependency.work_package)
- rescheduling_delta(dependency.moving_predecessors.first, days)
- end
-
- def rescheduling_delta(work_package, days)
- if work_package.due_date.present?
- previous_due_date = work_package.due_date_before_last_save || work_package.due_date_was || work_package.due_date
- days.delta(previous: previous_due_date, current: work_package.due_date)
- elsif work_package.start_date.present?
- previous_start_date = work_package.start_date_before_last_save || work_package.start_date_was || work_package.start_date
- days.delta(previous: previous_start_date, current: work_package.start_date)
- else
- 0
- end
- end
-
def set_dates(work_package, start_date, due_date)
work_package.start_date = start_date
work_package.due_date = due_date
diff --git a/app/services/work_packages/shared/all_days.rb b/app/services/work_packages/shared/all_days.rb
index 732a7a1a168..c8b5b4077a1 100644
--- a/app/services/work_packages/shared/all_days.rb
+++ b/app/services/work_packages/shared/all_days.rb
@@ -50,18 +50,10 @@ module WorkPackages
start_date + duration - 1
end
- def add_days(date, count)
- date + count.days
- end
-
def soonest_working_day(date)
date
end
- def delta(previous:, current:)
- current - previous
- end
-
def working?(_date)
true
end
diff --git a/app/services/work_packages/shared/working_days.rb b/app/services/work_packages/shared/working_days.rb
index 0d117083b39..60ed7f0adfb 100644
--- a/app/services/work_packages/shared/working_days.rb
+++ b/app/services/work_packages/shared/working_days.rb
@@ -61,18 +61,6 @@ module WorkPackages
due_date
end
- def add_days(date, count)
- while count > 0
- date += 1
- count -= 1 if working?(date)
- end
- while count < 0
- date -= 1
- count += 1 if working?(date)
- end
- date
- end
-
def soonest_working_day(date)
return unless date
@@ -82,24 +70,6 @@ module WorkPackages
date
end
- def delta(previous:, current:)
- if current < previous
- return -delta(previous: current, current: previous)
- end
-
- delta = 0
- pos = last_pos = soonest_working_day(previous)
-
- while pos < current
- pos += 1
- if working?(last_pos) && working?(pos)
- delta += 1
- last_pos = pos
- end
- end
- delta
- end
-
def working?(date)
working_week_day?(date) && working_specific_date?(date)
end
diff --git a/spec/features/work_packages/scheduling/scheduling_mode_spec.rb b/spec/features/work_packages/scheduling/scheduling_mode_spec.rb
index be4c71a6929..abdb8930a85 100644
--- a/spec/features/work_packages/scheduling/scheduling_mode_spec.rb
+++ b/spec/features/work_packages/scheduling/scheduling_mode_spec.rb
@@ -144,13 +144,13 @@ describe 'scheduling mode',
# but the start date remains unchanged as its grandchild stays put.
expect_dates(wp_parent, '2016-01-01', '2016-01-10')
- # is moved backwards because of the follows relationship
+ # is moved forward because of the follows relationship
expect_dates(wp_suc, '2016-01-11', '2016-01-15')
- # is moved backwards because it is the parent of the successor
+ # is moved forward because it is the parent of the successor
expect_dates(wp_suc_parent, '2016-01-11', '2016-01-15')
- # is moved backwards as the whole hierarchy is moved backwards
+ # is moved forward as the whole hierarchy is moved forward
expect_dates(wp_suc_child, '2016-01-11', '2016-01-15')
# Switching back to automatic scheduling will lead to the work package
@@ -162,7 +162,7 @@ describe 'scheduling mode',
work_packages_page.expect_and_dismiss_toaster message: 'Successful update.'
- # Moved forward again as the child determines the dates again
+ # Moved backward again as the child determines the dates again
expect_dates(wp, '2016-01-01', '2016-01-05')
expect(wp.schedule_manually).to be_falsey
@@ -173,22 +173,22 @@ describe 'scheduling mode',
# the interval is shortened again.
expect_dates(wp_parent, '2016-01-01', '2016-01-05')
- # is moved forward again because of the follows relationship
- expect_dates(wp_suc, '2016-01-06', '2016-01-10')
+ # does not move backwards, as it just increases the gap between wp and wp_suc
+ expect_dates(wp_suc, '2016-01-11', '2016-01-15')
- # is moved forward again because its child is also moved forward
- expect_dates(wp_suc_parent, '2016-01-06', '2016-01-10')
+ # does not move backwards either
+ expect_dates(wp_suc_parent, '2016-01-11', '2016-01-15')
- # is moved forward again because its parent is also moved forward
- expect_dates(wp_suc_child, '2016-01-06', '2016-01-10')
+ # does not move backwards either because its parent did not move
+ expect_dates(wp_suc_child, '2016-01-11', '2016-01-15')
- # Switching back to manual scheduling but this time forward will lead to the work package
+ # Switching back to manual scheduling but this time backward will lead to the work package
# and all work packages that are dependent to be rescheduled again.
combined_field.activate!(expect_open: false)
combined_field.expect_active!
combined_field.set_scheduling_mode manually: true
- # The calendar needs some time to get initialised.
+ # The calendar needs some time to get initialized.
sleep 2
combined_field.expect_calendar
@@ -209,17 +209,18 @@ describe 'scheduling mode',
# but the due date remains unchanged as its grandchild stays put.
expect_dates(wp_parent, '2015-12-20', '2016-01-05')
- # is moved forward because of the follows relationship
- expect_dates(wp_suc, '2016-01-01', '2016-01-05')
+ # does not move backwards, as it just increases the gap between wp and wp_suc
+ expect_dates(wp_suc, '2016-01-11', '2016-01-15')
- # is moved forward because it is the parent of the successor
- expect_dates(wp_suc_parent, '2016-01-01', '2016-01-05')
+ # does not move backwards either
+ expect_dates(wp_suc_parent, '2016-01-11', '2016-01-15')
- # is moved forward as the whole hierarchy is moved backwards
- expect_dates(wp_suc_child, '2016-01-01', '2016-01-05')
+ # does not move backwards either because its parent did not move
+ expect_dates(wp_suc_child, '2016-01-11', '2016-01-15')
# Switching back to automatic scheduling will lead to the work package
- # and all work packages that are dependent to be rescheduled again.
+ # and all work packages that are dependent to be rescheduled again to
+ # satisfy wp follows wp_pre relation.
combined_field.activate!(expect_open: false)
combined_field.expect_active!
combined_field.set_scheduling_mode manually: false
@@ -238,13 +239,13 @@ describe 'scheduling mode',
# the interval is shortened again.
expect_dates(wp_parent, '2016-01-01', '2016-01-05')
- # is moved backwards again because of the follows relationship
- expect_dates(wp_suc, '2016-01-06', '2016-01-10')
+ # does not move
+ expect_dates(wp_suc, '2016-01-11', '2016-01-15')
- # is moved backwards again because its child is also moved forward
- expect_dates(wp_suc_parent, '2016-01-06', '2016-01-10')
+ # does not move either
+ expect_dates(wp_suc_parent, '2016-01-11', '2016-01-15')
- # is moved backwards again because its parent is also moved forward
- expect_dates(wp_suc_child, '2016-01-06', '2016-01-10')
+ # does not move either because its parent did not move
+ expect_dates(wp_suc_child, '2016-01-11', '2016-01-15')
end
end
diff --git a/spec/services/work_packages/set_schedule_service_spec.rb b/spec/services/work_packages/set_schedule_service_spec.rb
index 4f69d3dfc8a..63236ce4adc 100644
--- a/spec/services/work_packages/set_schedule_service_spec.rb
+++ b/spec/services/work_packages/set_schedule_service_spec.rb
@@ -160,6 +160,22 @@ describe WorkPackages::SetScheduleService do
end
end
+ shared_examples_for 'does not reschedule' do
+ before do
+ subject
+ end
+
+ it 'is success' do
+ expect(subject)
+ .to be_success
+ end
+
+ it 'does not change any other work packages' do
+ expect(subject.all_results)
+ .to match_array [work_package]
+ end
+ end
+
context 'without relation' do
it 'is success' do
expect(subject)
@@ -235,11 +251,7 @@ describe WorkPackages::SetScheduleService do
work_package.due_date = Time.zone.today + 5.days
end
- it_behaves_like 'reschedules' do
- let(:expected) do
- {}
- end
- end
+ it_behaves_like 'does not reschedule'
end
context 'when moving forward with the follower having some space left and a delay' do
@@ -266,12 +278,7 @@ describe WorkPackages::SetScheduleService do
work_package.due_date = Time.zone.today + 5.days
end
- it_behaves_like 'reschedules' do
- # Nothing should be rescheduled
- let(:expected) do
- {}
- end
- end
+ it_behaves_like 'does not reschedule'
end
context 'when moving backwards' do
@@ -279,11 +286,7 @@ describe WorkPackages::SetScheduleService do
work_package.due_date = Time.zone.today - 5.days
end
- it_behaves_like 'reschedules' do
- let(:expected) do
- { following_work_package1 => [Time.zone.today - 4.days, Time.zone.today - 2.days] }
- end
- end
+ it_behaves_like 'does not reschedule'
end
context 'when moving backwards with space between' do
@@ -294,34 +297,7 @@ describe WorkPackages::SetScheduleService do
work_package.due_date = Time.zone.today - 5.days
end
- it_behaves_like 'reschedules' do
- let(:expected) do
- { following_work_package1 => [Time.zone.today - 2.days, Time.zone.today] }
- end
- end
- end
-
- context 'when moving backwards with the follower having another relation limiting movement' do
- let!(:other_work_package) do
- create(:work_package,
- start_date: follower1_start_date - 8.days,
- due_date: follower1_start_date - 5.days).tap do |wp|
- create(:follows_relation,
- delay: 3,
- to: wp,
- from: following_work_package1)
- end
- end
-
- before do
- work_package.due_date = Time.zone.today - 5.days
- end
-
- it_behaves_like 'reschedules' do
- let(:expected) do
- { following_work_package1 => [Time.zone.today, Time.zone.today + 2.days] }
- end
- end
+ it_behaves_like 'does not reschedule'
end
context 'when moving backwards with the follower having no start date (which should not happen) \
@@ -359,23 +335,14 @@ describe WorkPackages::SetScheduleService do
work_package.start_date = work_package.due_date = nil
end
- it_behaves_like 'reschedules' do
- # The follower will keep its dates
- let(:expected) do
- {}
- end
- end
+ # The follower will keep its dates
+ it_behaves_like 'does not reschedule'
context 'when the follower has no start date but a due date' do
let(:follower1_start_date) { nil }
let(:follower1_due_date) { Time.zone.today + 15.days }
- it_behaves_like 'reschedules' do
- # Nothing should be rescheduled
- let(:expected) do
- {}
- end
- end
+ it_behaves_like 'does not reschedule'
end
end
@@ -428,11 +395,7 @@ describe WorkPackages::SetScheduleService do
let(:follower1_start_date) { nil }
let(:follower1_due_date) { nil }
- it_behaves_like 'reschedules' do
- let(:expected) do
- {}
- end
- end
+ it_behaves_like 'does not reschedule'
end
context 'with the successor having another predecessor which has no dates' do
@@ -465,11 +428,7 @@ describe WorkPackages::SetScheduleService do
work_package.due_date = Time.zone.today - 5.days
end
- it_behaves_like 'reschedules' do
- let(:expected) do
- { following_work_package1 => [Time.zone.today - 4.days, Time.zone.today - 2.days] }
- end
- end
+ it_behaves_like 'does not reschedule'
end
end
end
@@ -608,84 +567,7 @@ describe WorkPackages::SetScheduleService do
work_package.due_date = Time.zone.today - 5.days
end
- it_behaves_like 'reschedules' do
- let(:expected) do
- { following_work_package1 => [Time.zone.today - 4.days, Time.zone.today - 2.days],
- parent_following_work_package1 => [Time.zone.today - 4.days, Time.zone.today - 2.days] }
- end
- end
- end
-
- context 'when moving backwards with the parent having another relation limiting movement' do
- let!(:other_work_package) do
- create(:work_package,
- start_date: Time.zone.today - 8.days,
- due_date: Time.zone.today - 4.days).tap do |wp|
- create(:follows_relation,
- delay: 2,
- to: wp,
- from: parent_following_work_package1)
- end
- end
-
- before do
- work_package.due_date = Time.zone.today - 5.days
- end
-
- it_behaves_like 'reschedules' do
- let(:expected) do
- { following_work_package1 => [Time.zone.today - 1.day, Time.zone.today + 1.day],
- parent_following_work_package1 => [Time.zone.today - 1.day, Time.zone.today + 1.day] }
- end
- end
- end
-
- context 'when moving backwards with the parent having another relation not limiting movement' do
- let(:other_work_package) do
- create(:work_package,
- start_date: Time.zone.today - 10.days,
- due_date: Time.zone.today - 9.days)
- end
-
- let(:other_follow_relation) do
- create(:follows_relation,
- delay: 2,
- to: other_work_package,
- from: parent_following_work_package1)
- end
-
- before do
- work_package.due_date = Time.zone.today - 5.days
- end
-
- it_behaves_like 'reschedules' do
- let(:expected) do
- { following_work_package1 => [Time.zone.today - 4.days, Time.zone.today - 2.days],
- parent_following_work_package1 => [Time.zone.today - 4.days, Time.zone.today - 2.days] }
- end
- end
- end
-
- context 'when moving backwards with the parent having another child not being moved' do
- let(:parent_follower1_start_date) { follower1_start_date }
- let(:parent_follower1_due_date) { follower1_due_date + 4.days }
-
- let!(:following) do
- [following_work_package1,
- parent_following_work_package1,
- follower_sibling_work_package]
- end
-
- before do
- work_package.due_date = Time.zone.today - 5.days
- end
-
- it_behaves_like 'reschedules' do
- let(:expected) do
- { following_work_package1 => [Time.zone.today - 4.days, Time.zone.today - 2.days],
- parent_following_work_package1 => [Time.zone.today - 4.days, Time.zone.today + 7.days] }
- end
- end
+ it_behaves_like 'does not reschedule'
end
end
@@ -732,11 +614,7 @@ describe WorkPackages::SetScheduleService do
end
context 'with unchanged dates (e.g. when creating a follows relation) and successor starting 1 day after scheduled' do
- it_behaves_like 'reschedules' do
- let(:expected) do
- {}
- end
- end
+ it_behaves_like 'does not reschedule'
end
context 'with unchanged dates (e.g. when creating a follows relation) and successor starting 3 days after scheduled' do
@@ -747,11 +625,7 @@ describe WorkPackages::SetScheduleService do
let(:child2_start_date) { follower1_start_date + 8.days }
let(:child2_due_date) { follower1_due_date }
- it_behaves_like 'reschedules' do
- let(:expected) do
- {}
- end
- end
+ it_behaves_like 'does not reschedule'
end
context 'with unchanged dates (e.g. when creating a follows relation) and successor\'s first child needs to be rescheduled' do
@@ -843,13 +717,7 @@ describe WorkPackages::SetScheduleService do
work_package.due_date = Time.zone.today - 5.days
end
- it_behaves_like 'reschedules' do
- let(:expected) do
- { following_work_package1 => [Time.zone.today - 4.days, Time.zone.today - 2.days],
- following_work_package2 => [Time.zone.today - 1.day, Time.zone.today + 3.days],
- following_work_package3 => [Time.zone.today + 4.days, Time.zone.today + 5.days] }
- end
- end
+ it_behaves_like 'does not reschedule'
end
end
@@ -898,14 +766,7 @@ describe WorkPackages::SetScheduleService do
work_package.due_date = Time.zone.today - 5.days
end
- it_behaves_like 'reschedules' do
- let(:expected) do
- { following_work_package1 => [Time.zone.today - 4.days, Time.zone.today - 2.days],
- following_work_package2 => [Time.zone.today - 1.day, Time.zone.today + 3.days],
- following_work_package3 => [Time.zone.today - 1.day, Time.zone.today + 2.days],
- following_work_package4 => [Time.zone.today + 4.days, Time.zone.today + 5.days] }
- end
- end
+ it_behaves_like 'does not reschedule'
end
end
diff --git a/spec/services/work_packages/set_schedule_service_working_days_spec.rb b/spec/services/work_packages/set_schedule_service_working_days_spec.rb
index 8d42075d5b0..ef5dd655f92 100644
--- a/spec/services/work_packages/set_schedule_service_working_days_spec.rb
+++ b/spec/services/work_packages/set_schedule_service_working_days_spec.rb
@@ -290,34 +290,10 @@ describe WorkPackages::SetScheduleService, 'working days' do
CHART
end
- it 'reschedules the follower to start after the non-working days' do
- expect_schedule(subject.all_results, <<~CHART)
+ it 'does not move the follower' do
+ expect(subject.all_results).to match_schedule(<<~CHART)
| MTWTFSS |
work_package | X |
- follower | XX |
- CHART
- end
- end
-
- context 'on a day in the middle of working days' do
- let_schedule(<<~CHART)
- days | MTWTFSS |
- work_package | X |
- follower | XX | follows work_package
- CHART
-
- before do
- change_schedule([work_package], <<~CHART)
- days | mtwtfssmtwtfssMTWTFSS |
- work_package | X |
- CHART
- end
-
- it 'reschedules the follower to move by the same delta of working days' do
- expect_schedule(subject.all_results, <<~CHART)
- days | mtwtfssmtwtfssMTWTFSS |
- work_package | X |
- follower | XX |
CHART
end
end
@@ -336,11 +312,10 @@ describe WorkPackages::SetScheduleService, 'working days' do
CHART
end
- it 'reschedules follower to move backward by the same delta of working days' do
- expect_schedule(subject.all_results, <<~CHART)
+ it 'does not move the follower' do
+ expect(subject.all_results).to match_schedule(<<~CHART)
| MTWTFSS |
work_package | X |
- follower | X |
CHART
end
end
@@ -353,30 +328,6 @@ describe WorkPackages::SetScheduleService, 'working days' do
annoyer | XX..XX |
CHART
- before do
- change_schedule([work_package], <<~CHART)
- days | mtwtfssmtwtfssMTWTFSS |
- work_package | X _ |
- CHART
- end
-
- it 'reschedules follower to move backward but not earlier than the other relation soonest start date' do
- expect_schedule(subject.all_results, <<~CHART)
- days | mtwtfssmtwtfssMTWTFSS |
- work_package | X |
- follower | X..X |
- CHART
- end
- end
-
- context 'with the follower having another relation limiting movement and only due date' do
- let_schedule(<<~CHART)
- days | mtwtfssmtwtfssMTWTFSS |
- work_package | X |
- follower | ] | follows work_package, follows annoyer with delay 2
- annoyer | XX..XX |
- CHART
-
before do
change_schedule([work_package], <<~CHART)
days | mtwtfssmtwtfssMTWTFSS |
@@ -384,11 +335,10 @@ describe WorkPackages::SetScheduleService, 'working days' do
CHART
end
- it 'reschedules follower to start at the other relation soonest start date and keep its end date' do
+ it 'does not move the follower' do
expect(subject.all_results).to match_schedule(<<~CHART)
days | mtwtfssmtwtfssMTWTFSS |
work_package | X |
- follower | X..XXX |
CHART
end
end
@@ -603,11 +553,10 @@ describe WorkPackages::SetScheduleService, 'working days' do
CHART
end
- it 'reschedules follower without influence from the other predecessor' do
+ it 'does not move the follower' do
expect(subject.all_results).to match_schedule(<<~CHART)
days | mtwtfssMTWTFSS |
work_package | ] |
- follower | XX..X |
CHART
end
end
@@ -729,64 +678,10 @@ describe WorkPackages::SetScheduleService, 'working days' do
CHART
end
- it 'reschedules follower and follower parent to start right after the moved predecessor' do
+ it 'does not reschedule the followers' do
expect(subject.all_results).to match_schedule(<<~CHART)
days | mtwtfssMTWTFSS |
work_package | ] |
- follower | X..X |
- follower_parent | X..X |
- CHART
- end
- end
-
- context 'when moving backwards with the parent having a predecessor limiting movement' do
- let_schedule(<<~CHART)
- days | mtwtfssMTWTFSS |
- work_package | ] |
- follower | XX | follows work_package, child of follower_parent
- follower_parent | XX | follows predecessor with delay 2
- predecessor | XX |
- CHART
-
- before do
- change_schedule([work_package], <<~CHART)
- days | mtwtfssMTWTFSS |
- work_package | ] |
- CHART
- end
-
- it 'constraints follower and follower parent to start after the predecessor limiting movement' do
- expect(subject.all_results).to match_schedule(<<~CHART)
- days | mtwtfssMTWTFSS |
- work_package | ] |
- follower | XX |
- follower_parent | XX |
- CHART
- end
- end
-
- context 'when moving backwards with the parent having another relation not limiting movement' do
- let_schedule(<<~CHART)
- days | mtwtfssMTWTFSS |
- work_package | ] |
- follower | XXXX | follows work_package, child of follower_parent
- follower_parent | XXXX | follows predecessor with delay 2
- predecessor | XX |
- CHART
-
- before do
- change_schedule([work_package], <<~CHART)
- days | mtwtfssMTWTFSS |
- work_package | ] |
- CHART
- end
-
- it 'reschedules follower and follower parent to start right after the moved predecessor' do
- expect(subject.all_results).to match_schedule(<<~CHART)
- days | mtwtfssMTWTFSS |
- work_package | ] |
- follower | XXX..X |
- follower_parent | XXX..X |
CHART
end
end
@@ -807,12 +702,10 @@ describe WorkPackages::SetScheduleService, 'working days' do
CHART
end
- it 'reschedules follower to start right after the moved predecessor, and follower parent spans on its two children' do
+ it 'does not rechedule the followers or the other child' do
expect(subject.all_results).to match_schedule(<<~CHART)
days | mtwtfssMTWTFSS |
work_package | ] |
- follower | XX |
- follower_parent | XXX..XXXXX |
CHART
end
end
@@ -1110,14 +1003,10 @@ describe WorkPackages::SetScheduleService, 'working days' do
CHART
end
- it 'reschedules every follower backwards by the same delta' do
+ it 'does not reschedule any followers' do
expect(subject.all_results).to match_schedule(<<~CHART)
- days | m sMTWTFSSm sm sm |
- work_package | ] |
- follower1 | X..XX |
- follower2 | XXX..X |
- follower3 | XXXXX |
- follower4 | XX |
+ days | m sMTWTFSS |
+ work_package | ] |
CHART
end
end
@@ -1170,14 +1059,10 @@ describe WorkPackages::SetScheduleService, 'working days' do
CHART
end
- it 'reschedules every follower backwards by the same delta' do
+ it 'does not reschedule any followers' do
expect(subject.all_results).to match_schedule(<<~CHART)
- days | m sMTWTFSSm |
- work_package | ] |
- follower1 | XX..X |
- follower2 | XXXX..X |
- follower3 | XXX |
- follower4 | XXX |
+ days | m sMTWTFSS |
+ work_package | ] |
CHART
end
end
diff --git a/spec/services/work_packages/shared/all_days_spec.rb b/spec/services/work_packages/shared/all_days_spec.rb
index 7889298dae6..0e7ff518bb7 100644
--- a/spec/services/work_packages/shared/all_days_spec.rb
+++ b/spec/services/work_packages/shared/all_days_spec.rb
@@ -133,36 +133,6 @@ RSpec.describe WorkPackages::Shared::AllDays do
end
end
- describe '#add_days' do
- it 'adds the number of days to the date' do
- expect(subject.add_days(sunday_2022_07_31, 7)).to eq(Date.new(2022, 8, 7))
- end
-
- include_examples 'add_days returns date', date: Date.new(2022, 6, 15), count: 0, expected: Date.new(2022, 6, 15)
- include_examples 'add_days returns date', date: Date.new(2022, 6, 15), count: 1, expected: Date.new(2022, 6, 16)
- include_examples 'add_days returns date', date: Date.new(2022, 6, 15), count: 10, expected: Date.new(2022, 6, 25)
- include_examples 'add_days returns date', date: Date.new(2022, 6, 15), count: 100, expected: Date.new(2022, 9, 23)
- include_examples 'add_days returns date', date: Date.new(2022, 6, 15), count: 365, expected: Date.new(2023, 6, 15)
- include_examples 'add_days returns date', date: Date.new(2022, 6, 15), count: -1, expected: Date.new(2022, 6, 14)
- include_examples 'add_days returns date', date: Date.new(2022, 6, 15), count: -10, expected: Date.new(2022, 6, 5)
- include_examples 'add_days returns date', date: Date.new(2022, 6, 15), count: -100, expected: Date.new(2022, 3, 7)
- include_examples 'add_days returns date', date: Date.new(2022, 6, 15), count: -730, expected: Date.new(2020, 6, 15)
-
- context 'with weekend days (Saturday and Sunday)', :weekend_saturday_sunday do
- it 'adds the number of days to the date' do
- expect(subject.add_days(sunday_2022_07_31, 7)).to eq(Date.new(2022, 8, 7))
- expect(subject.add_days(sunday_2022_07_31, -7)).to eq(Date.new(2022, 7, 24))
- end
- 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
- it 'adds the number of days to the date' do
- expect(subject.add_days(Date.new(2022, 1, 1), 365)).to eq(Date.new(2023, 1, 1))
- expect(subject.add_days(Date.new(2022, 1, 1), -365)).to eq(Date.new(2021, 1, 1))
- end
- end
- end
-
describe '#soonest_working_day' do
it 'returns the given day' do
expect(subject.soonest_working_day(sunday_2022_07_31)).to eq(sunday_2022_07_31)
@@ -184,23 +154,4 @@ RSpec.describe WorkPackages::Shared::AllDays do
end
end
end
-
- describe '#delta' do
- it 'returns the number of shift from one day to another between two dates' do
- expect(subject.delta(previous: Date.new(2022, 8, 1), current: Date.new(2022, 8, 30))).to eq(29)
- expect(subject.delta(previous: Date.new(2022, 8, 15), current: Date.new(2022, 8, 1))).to eq(-14)
- end
-
- context 'with weekend days (Saturday and Sunday)', :weekend_saturday_sunday do
- it 'returns the same delta as without them' do
- expect(subject.delta(previous: Date.new(2022, 8, 1), current: Date.new(2022, 8, 30))).to eq(29)
- end
- 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
- it 'returns the same delta as without them' do
- expect(subject.delta(previous: Date.new(2022, 12, 1), current: Date.new(2023, 1, 1))).to eq(31)
- end
- end
- end
end
diff --git a/spec/services/work_packages/shared/shared_examples_days.rb b/spec/services/work_packages/shared/shared_examples_days.rb
index 2ccd31d6522..03fa9680a27 100644
--- a/spec/services/work_packages/shared/shared_examples_days.rb
+++ b/spec/services/work_packages/shared/shared_examples_days.rb
@@ -76,25 +76,8 @@ RSpec.shared_examples 'due_date' do |start_date:, duration:, expected:|
end
end
-RSpec.shared_examples 'add_days returns date' do |date:, count:, expected:|
- it "add_days(#{date.to_fs(:wday_date)}, #{count}) => #{expected.to_fs(:wday_date)}" do
- expect(subject.add_days(date, count)).to eq(expected)
- end
-end
-
RSpec.shared_examples 'soonest working day' do |date:, expected:|
it "soonest_working_day(#{date.to_fs(:wday_date)}) => #{expected.to_fs(:wday_date)}" do
expect(subject.soonest_working_day(date)).to eq(expected)
end
end
-
-RSpec.shared_examples 'delta' do |previous:, current:, expected:|
- it "delta(previous: #{previous.to_fs(:wday_date)}, current: #{current.to_fs(:wday_date)}) => #{expected} days" do
- expect(subject.delta(previous:, current:)).to eq(expected)
- end
-
- # check inverse: delta(a, b) == -delta(b, a)
- it "delta(previous: #{current.to_fs(:wday_date)}, current: #{previous.to_fs(:wday_date)}) => #{-expected} days" do
- expect(subject.delta(previous: current, current: previous)).to eq(-expected)
- end
-end
diff --git a/spec/services/work_packages/shared/working_days_spec.rb b/spec/services/work_packages/shared/working_days_spec.rb
index c3c99b7db83..899332ce07c 100644
--- a/spec/services/work_packages/shared/working_days_spec.rb
+++ b/spec/services/work_packages/shared/working_days_spec.rb
@@ -179,62 +179,6 @@ RSpec.describe WorkPackages::Shared::WorkingDays do
end
end
- describe '#add_days' do
- it 'when positive, adds the number of working days to the date, ignoring non-working days' do
- # Friday is a non working week day
- set_non_working_week_days('friday')
- create(:non_working_day, date: wednesday_2022_08_03)
-
- # Wednesday is skipped (non working day)
- expect(subject.add_days(monday_2022_08_01, 2)).to eq(Date.new(2022, 8, 4))
-
- # Wednesday is skipped (non working day) + Friday is skipped (non working week day)
- expect(subject.add_days(monday_2022_08_01, 7)).to eq(Date.new(2022, 8, 10))
-
- # Wednesday is skipped (non working day) + Friday is skipped twice (non working week day)
- expect(subject.add_days(monday_2022_08_01, 14)).to eq(Date.new(2022, 8, 18))
- end
-
- it 'when negative, removes the number of working days to the date, ignoring non-working days' do
- # Friday is a non working week day
- set_non_working_week_days('friday')
- create(:non_working_day, date: sunday_2022_07_31)
-
- # Sunday is skipped (non working day)
- expect(subject.add_days(monday_2022_08_01, -1)).to eq(Date.new(2022, 7, 30)) # Saturday
-
- # Sunday is skipped (non working day) + Friday is skipped (non working week day)
- expect(subject.add_days(monday_2022_08_01, -2)).to eq(Date.new(2022, 7, 28)) # Thursday
-
- # Sunday is skipped (non working day) + Friday is skipped twice (non working week day)
- expect(subject.add_days(monday_2022_08_01, -8)).to eq(Date.new(2022, 7, 21)) # Wednesday
- end
-
- context 'with weekend days (Saturday and Sunday)', :weekend_saturday_sunday do
- include_examples 'add_days returns date', date: saturday_2022_07_30, count: 0, expected: saturday_2022_07_30
- include_examples 'add_days returns date', date: saturday_2022_07_30, count: 1, expected: monday_2022_08_01
- include_examples 'add_days returns date', date: saturday_2022_07_30, count: -1, expected: friday_2022_07_29
-
- include_examples 'add_days returns date', date: sunday_2022_07_31, count: 0, expected: sunday_2022_07_31
- include_examples 'add_days returns date', date: sunday_2022_07_31, count: 1, expected: monday_2022_08_01
- include_examples 'add_days returns date', date: sunday_2022_07_31, count: -1, expected: friday_2022_07_29
-
- include_examples 'add_days returns date', date: Date.new(2022, 6, 15), count: 100, expected: Date.new(2022, 11, 2)
- include_examples 'add_days returns date', date: Date.new(2022, 6, 15), count: -100, expected: Date.new(2022, 1, 26)
-
- include_examples 'add_days returns date', date: Date.new(2022, 1, 1), count: 365, expected: Date.new(2023, 5, 26)
- include_examples 'add_days returns date', date: Date.new(2022, 12, 31), count: -365, expected: Date.new(2021, 8, 9)
- 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 'add_days returns date', date: Date.new(2022, 12, 24), count: 1, expected: Date.new(2022, 12, 26)
- include_examples 'add_days returns date', date: Date.new(2022, 12, 24), count: 7, expected: Date.new(2023, 1, 2)
-
- include_examples 'add_days returns date', date: Date.new(2022, 12, 26), count: -1, expected: Date.new(2022, 12, 24)
- include_examples 'add_days returns date', date: Date.new(2023, 1, 2), count: -7, expected: Date.new(2022, 12, 24)
- end
- end
-
describe '#soonest_working_day' do
it 'returns the soonest working day from the given day' do
expect(subject.soonest_working_day(sunday_2022_07_31)).to eq(sunday_2022_07_31)
@@ -264,28 +208,4 @@ RSpec.describe WorkPackages::Shared::WorkingDays do
end
end
end
-
- describe '#delta' do
- it 'returns the number of shift from one working day to another between two dates' do
- expect(subject.delta(previous: monday_2022_08_01, current: wednesday_2022_08_03)).to eq(2)
- expect(subject.delta(previous: wednesday_2022_08_03, current: monday_2022_08_01)).to eq(-2)
- end
-
- context 'with weekend days (Saturday and Sunday)', :weekend_saturday_sunday do
- include_examples 'delta', previous: friday_2022_07_29, current: saturday_2022_07_30, expected: 0
- include_examples 'delta', previous: friday_2022_07_29, current: sunday_2022_07_31, expected: 0
- include_examples 'delta', previous: saturday_2022_07_30, current: monday_2022_08_01, expected: 0
- include_examples 'delta', previous: saturday_2022_07_30, current: sunday_2022_07_31, expected: 0
- include_examples 'delta', previous: sunday_2022_07_31, current: monday_2022_08_01, expected: 0
- include_examples 'delta', previous: saturday_2022_07_30, current: wednesday_2022_08_03, expected: 2
- include_examples 'delta', previous: sunday_2022_07_31, current: wednesday_2022_08_03, expected: 2
- include_examples 'delta', previous: friday_2022_07_29, current: monday_2022_08_01, expected: 1
- include_examples 'delta', previous: friday_2022_07_29, current: Date.new(2022, 8, 5), expected: 5
- include_examples 'delta', previous: friday_2022_07_29, current: Date.new(2022, 8, 8), expected: 6
- 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 'delta', previous: Date.new(2022, 12, 27), current: Date.new(2022, 12, 20), expected: -6
- end
- end
end
diff --git a/spec/services/work_packages/update_service_integration_spec.rb b/spec/services/work_packages/update_service_integration_spec.rb
index 6ba6795b178..099e99f6022 100644
--- a/spec/services/work_packages/update_service_integration_spec.rb
+++ b/spec/services/work_packages/update_service_integration_spec.rb
@@ -465,7 +465,7 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma
# calculated
# sibling1 not factored in as its estimated_hours are nil
calculated_ratio = ((work_package.done_ratio * work_package.estimated_hours) +
- (sibling2_work_package.done_ratio * sibling2_work_package.estimated_hours)) /
+ (sibling2_work_package.done_ratio * sibling2_work_package.estimated_hours)) / \
(work_package.done_ratio +
sibling2_work_package.done_ratio)
@@ -773,7 +773,7 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma
# rubocop:enable RSpec/MultipleExpectations
end
- describe 'rescheduling work packages forward follows/hierarchy relations' do
+ describe 'rescheduling work packages backwards with follows/hierarchy relations' do
# layout
# other_work_package
# +
@@ -883,7 +883,7 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma
end
# rubocop:disable RSpec/ExampleLength
- it 'propagates the changes to start/finish date along' do
+ it 'does not propagate the changes to followers' do
expect(subject)
.to be_success
@@ -895,33 +895,33 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma
following_work_package.reload(select: %i(start_date due_date))
expect(following_work_package.start_date)
- .to eql Time.zone.today + 1.day
+ .to eql Time.zone.today + 6.days
expect(following_work_package.due_date)
- .to eql Time.zone.today + 15.days
+ .to eql Time.zone.today + 20.days
following_parent_work_package.reload(select: %i(start_date due_date))
expect(following_parent_work_package.start_date)
- .to eql Time.zone.today + 1.day
+ .to eql Time.zone.today + 6.days
expect(following_parent_work_package.due_date)
- .to eql Time.zone.today + 15.days
+ .to eql Time.zone.today + 20.days
following2_parent_work_package.reload(select: %i(start_date due_date))
expect(following2_parent_work_package.start_date)
- .to eql Time.zone.today + 22.days
+ .to eql Time.zone.today + 24.days
expect(following2_parent_work_package.due_date)
- .to eql Time.zone.today + 26.days
+ .to eql Time.zone.today + 28.days
following2_work_package.reload(select: %i(start_date due_date))
expect(following2_work_package.start_date)
- .to eql Time.zone.today + 22.days
+ .to eql Time.zone.today + 24.days
expect(following2_work_package.due_date)
- .to eql Time.zone.today + 26.days
+ .to eql Time.zone.today + 28.days
following3_work_package.reload(select: %i(start_date due_date))
expect(following3_work_package.start_date)
- .to eql Time.zone.today + 27.days
+ .to eql Time.zone.today + 29.days
expect(following3_work_package.due_date)
- .to eql Time.zone.today + 31.days
+ .to eql Time.zone.today + 33.days
end
# rubocop:enable RSpec/ExampleLength
end
diff --git a/spec/workers/work_packages/apply_working_days_change_job_spec.rb b/spec/workers/work_packages/apply_working_days_change_job_spec.rb
index df255d5f08d..cc267bf9727 100644
--- a/spec/workers/work_packages/apply_working_days_change_job_spec.rb
+++ b/spec/workers/work_packages/apply_working_days_change_job_spec.rb
@@ -135,12 +135,12 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
set_working_week_days('wednesday')
end
- it 'moves the follower start date backwards by consequence of the predecessor dates shift' do
+ it 'does not move the follower backwards' do
job.perform_now(user_id: user.id)
expect(WorkPackage.all).to match_schedule(<<~CHART)
- days | MTWTFSS |
- predecessor | XX | working days work week
- follower | XXX | working days include weekends
+ days | MTWTFSS |
+ predecessor | XX | working days work week
+ follower | XXX | working days include weekends
CHART
end
end