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
Update WorkingDaysUpdateService spec to verify the delete/recreate scenario works correctly
Dombi Attila210da2a807f8
diff --git a/spec/services/settings/working_days_update_service_spec.rb b/spec/services/settings/working_days_update_service_spec.rbindex ba69682fb52..6ced425dab7 100644--- a/spec/services/settings/working_days_update_service_spec.rb+++ b/spec/services/settings/working_days_update_service_spec.rb@@ -132,12 +132,23 @@ describe Settings::WorkingDaysUpdateService docontext 'when deleting and re-creating the duplicate non-working day' dolet(:non_working_days_params) do[- existing_nwd.slice(:id, :name, :date).merge('_destroy' => true),- existing_nwd.slice(:name, :date)+ nwd_to_delete.slice(:id, :name, :date).merge('_destroy' => true),+ nwd_to_delete.slice(:name, :date)]endinclude_examples 'successful call'++ it 'persists (create/delete) the non working days' do+ expect { subject }.not_to change(NonWorkingDay, :count)+ expect { nwd_to_delete.reload }.to raise_error(ActiveRecord::RecordNotFound)++ # The nwd_to_delete is being re-created after the deletion.+ expect(NonWorkingDay.all).to contain_exactly(+ have_attributes(existing_nwd.slice(:name, :date)),+ have_attributes(nwd_to_delete.slice(:name, :date))+ )+ endendendenddiff --git a/spec/workers/work_packages/apply_working_days_change_job_spec.rb b/spec/workers/work_packages/apply_working_days_change_job_spec.rbindex a55f68a7571..b09f7958c36 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@@ -61,514 +61,1033 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendend- context 'when a work package includes a date that is now a non-working day' do- let_schedule(<<~CHART)- days | MTWTFSS |- work_package | XXXX ░░ |- work_package_on_start | XX ░░ |- work_package_on_due | XXX ░░ |- wp_start_only | [ ░░ |- wp_due_only | ] ░░ |- CHART-- before do- set_non_working_week_days('wednesday')- end+ describe '#perform' do+ context 'with non-working weekday settings' do+ context 'when a work package includes a date that is now a non-working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XXXX ░░ |+ work_package_on_start | XX ░░ |+ work_package_on_due | XXX ░░ |+ wp_start_only | [ ░░ |+ wp_due_only | ] ░░ |+ CHART++ before do+ set_non_working_week_days('wednesday')+ end- it 'moves the finish date to the corresponding number of now-excluded days to maintain duration [#31992]' do- job.perform_now(user_id: user.id, previous_working_days:)+ it 'moves the finish date to the corresponding number of now-excluded days to maintain duration [#31992]' do+ job.perform_now(user_id: user.id, previous_working_days:)++ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XX▓XX░░ |+ work_package_on_start | ░XX░░ |+ work_package_on_due | XX▓X ░░ |+ wp_start_only | ░[ ░░ |+ wp_due_only | ░] ░░ |+ CHART+ end- expect(WorkPackage.all).to match_schedule(<<~CHART)- days | MTWTFSS |- work_package | XX▓XX░░ |- work_package_on_start | ░XX░░ |- work_package_on_due | XX▓X ░░ |- wp_start_only | ░[ ░░ |- wp_due_only | ░] ░░ |- CHART- end+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [work_package,+ work_package_on_start,+ work_package_on_due,+ wp_start_only,+ wp_due_only]+ end+ let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }+ end+ end++ context 'when a work package was scheduled to start on a date that is now a non-working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XX ░░ |+ CHART- it_behaves_like 'journal updates with note' do- let(:changed_work_packages) do- [work_package,- work_package_on_start,- work_package_on_due,- wp_start_only,- wp_due_only]+ before do+ set_non_working_week_days('wednesday')+ end++ it 'moves the start date to the earliest working day in the future, ' \+ 'and the finish date changes by consequence [#31992]' do+ job.perform_now(user_id: user.id, previous_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | ░XX░░ |+ CHART+ end++ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [work_package]+ end+ let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }+ endend- let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }- end- end- context 'when a work package was scheduled to start on a date that is now a non-working day' do- let_schedule(<<~CHART)- days | MTWTFSS |- work_package | XX ░░ |- CHART+ context 'when a work package includes a date that is no more a non-working day' do+ let_schedule(<<~CHART)+ days | fssMTWTFSS |+ work_package | X▓▓XX ░░ |+ CHART- before do- set_non_working_week_days('wednesday')- end+ before do+ set_working_week_days('saturday')+ end- it 'moves the start date to the earliest working day in the future, ' \- 'and the finish date changes by consequence [#31992]' do- job.perform_now(user_id: user.id, previous_working_days:)- expect(WorkPackage.all).to match_schedule(<<~CHART)- days | MTWTFSS |- work_package | ░XX░░ |- CHART- end+ it 'moves the finish date backwards to the corresponding number of now-included days to maintain duration [#31992]' do+ job.perform_now(user_id: user.id, previous_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | fssMTWTFSS |+ work_package | XX▓X ░ |+ CHART+ end- it_behaves_like 'journal updates with note' do- let(:changed_work_packages) do- [work_package]+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [work_package]+ end+ let(:journal_notice) { "**Working days** changed (Saturday is now working)." }+ endend- let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }- end- end- context 'when a work package includes a date that is no more a non-working day' do- let_schedule(<<~CHART)- days | fssMTWTFSS |- work_package | X▓▓XX ░░ |- CHART+ context 'when a follower has a predecessor with dates covering a day that is now a non-working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX ░░ | working days work week+ follower | XXX░ | working days include weekends, follows predecessor+ CHART- before do- set_working_week_days('saturday')- end+ before do+ set_non_working_week_days('wednesday')+ end- it 'moves the finish date backwards to the corresponding number of now-included days to maintain duration [#31992]' do- job.perform_now(user_id: user.id, previous_working_days:)- expect(WorkPackage.all).to match_schedule(<<~CHART)- days | fssMTWTFSS |- work_package | XX▓X ░ |- CHART- end+ it 'moves the follower start date by consequence of the predecessor dates shift [#31992]' do+ job.perform_now(user_id: user.id, previous_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | X▓X ░░ |+ follower | ░ XXX |+ CHART+ end- it_behaves_like 'journal updates with note' do- let(:changed_work_packages) do- [work_package]+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [predecessor, follower]+ end+ let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }+ endend- let(:journal_notice) { "**Working days** changed (Saturday is now working)." }- end- end- context 'when a follower has a predecessor with dates covering a day that is now a non-working day' do- let_schedule(<<~CHART)- days | MTWTFSS |- predecessor | XX ░░ | working days work week- follower | XXX░ | working days include weekends, follows predecessor- CHART+ context 'when a follower has a predecessor with delay covering a day that is now a non-working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX ░░ |+ follower | X ░░ | follows predecessor with delay 1+ CHART- before do- set_non_working_week_days('wednesday')- end+ before do+ set_non_working_week_days('wednesday')+ end- it 'moves the follower start date by consequence of the predecessor dates shift [#31992]' do- job.perform_now(user_id: user.id, previous_working_days:)- expect(WorkPackage.all).to match_schedule(<<~CHART)- days | MTWTFSS |- predecessor | X▓X ░░ |- follower | ░ XXX |- CHART- end+ it 'moves the follower start date forward to keep the delay to 1 day' do+ job.perform_now(user_id: user.id, previous_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX░ ░░ |+ follower | ░ X░░ |+ CHART+ end- it_behaves_like 'journal updates with note' do- let(:changed_work_packages) do- [predecessor, follower]+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [follower]+ end+ let(:unchanged_work_packages) do+ [predecessor]+ end+ let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }+ endend- let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }- end- end- context 'when a follower has a predecessor with delay covering a day that is now a non-working day' do- let_schedule(<<~CHART)- days | MTWTFSS |- predecessor | XX ░░ |- follower | X ░░ | follows predecessor with delay 1- CHART+ context 'with work packages without dates following each other with delay' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | ░░ |+ follower | ░░ | follows predecessor with delay 5+ CHART- before do- set_non_working_week_days('wednesday')- end+ before do+ set_non_working_week_days('wednesday')+ end- it 'moves the follower start date forward to keep the delay to 1 day' do- job.perform_now(user_id: user.id, previous_working_days:)- expect(WorkPackage.all).to match_schedule(<<~CHART)- days | MTWTFSS |- predecessor | XX░ ░░ |- follower | ░ X░░ |- CHART- end+ it 'does not move anything (obviously) and does not crash either' do+ job.perform_now(user_id: user.id, previous_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | ░ ░░ |+ follower | ░ ░░ |+ CHART+ end- it_behaves_like 'journal updates with note' do- let(:changed_work_packages) do- [follower]+ it_behaves_like 'journal updates with note' do+ let(:unchanged_work_packages) do+ [predecessor, follower]+ end+ endend- let(:unchanged_work_packages) do- [predecessor]++ context 'when a follower has a predecessor with delay covering multiple days with different working changes' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | X ░ ░░ |+ follower | ░ X░░ | follows predecessor with delay 2+ CHART+ let(:work_week) { set_work_week('monday', 'tuesday', 'thursday', 'friday') }++ before do+ set_non_working_week_days('tuesday')+ set_working_week_days('wednesday')+ end++ it 'correctly handles the changes' do+ job.perform_now(user_id: user.id, previous_working_days:)+ expect_schedule(WorkPackage.all, <<~CHART)+ days | MTWTFSS |+ predecessor | X░ ░░ |+ follower | ░ X░░ |+ CHART+ end++ it_behaves_like 'journal updates with note' do+ let(:unchanged_work_packages) do+ [predecessor, follower]+ end+ endend- let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }- end- end- context 'with work packages without dates following each other with delay' do- let_schedule(<<~CHART)- days | MTWTFSS |- predecessor | ░░ |- follower | ░░ | follows predecessor with delay 5- CHART+ context 'when a follower has a predecessor with dates covering a day that is now a working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | X▓X ░░ | working days work week+ follower | ░ XXX | working days include weekends, follows predecessor+ CHART+ let(:work_week) { set_work_week('monday', 'tuesday', 'thursday', 'friday') }- before do- set_non_working_week_days('wednesday')- end+ before do+ set_working_week_days('wednesday')+ end- it 'does not move anything (obviously) and does not crash either' do- job.perform_now(user_id: user.id, previous_working_days:)- expect(WorkPackage.all).to match_schedule(<<~CHART)- days | MTWTFSS |- predecessor | ░ ░░ |- follower | ░ ░░ |- CHART- end+ it 'does not move the follower backwards' do+ job.perform_now(user_id: user.id, previous_working_days:)- it_behaves_like 'journal updates with note' do- let(:unchanged_work_packages) do- [predecessor, follower]+ expect_schedule(WorkPackage.all, <<~CHART)+ days | MTWTFSS |+ predecessor | XX ░░ |+ follower | XXX |+ CHART+ end++ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [predecessor]+ end+ let(:unchanged_work_packages) do+ [follower]+ end+ let(:journal_notice) { "**Working days** changed (Wednesday is now working)." }+ endend- end- end- context 'when a follower has a predecessor with delay covering multiple days with different working changes' do- let_schedule(<<~CHART)- days | MTWTFSS |- predecessor | X ░ ░░ |- follower | ░ X░░ | follows predecessor with delay 2- CHART- let(:work_week) { set_work_week('monday', 'tuesday', 'thursday', 'friday') }-- before do- set_non_working_week_days('tuesday')- set_working_week_days('wednesday')- end+ context 'when a follower has a predecessor with a non-working day between them that is now a working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX░ ░░ |+ follower | ░XX░░ | follows predecessor+ CHART+ let(:work_week) { set_work_week('monday', 'tuesday', 'thursday', 'friday') }- it 'correctly handles the changes' do- job.perform_now(user_id: user.id, previous_working_days:)- expect_schedule(WorkPackage.all, <<~CHART)- days | MTWTFSS |- predecessor | X░ ░░ |- follower | ░ X░░ |- CHART- end+ before do+ set_working_week_days('wednesday')+ end++ it 'does not move the follower' do+ job.perform_now(user_id: user.id, previous_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX |+ follower | XX░░ |+ CHART+ end- it_behaves_like 'journal updates with note' do- let(:unchanged_work_packages) do- [predecessor, follower]+ it_behaves_like 'journal updates with note' do+ let(:unchanged_work_packages) do+ [predecessor, follower]+ end+ endend- end- end- context 'when a follower has a predecessor with dates covering a day that is now a working day' do- let_schedule(<<~CHART)- days | MTWTFSS |- predecessor | X▓X ░░ | working days work week- follower | ░ XXX | working days include weekends, follows predecessor- CHART- let(:work_week) { set_work_week('monday', 'tuesday', 'thursday', 'friday') }+ context 'when a work package has working days include weekends, and includes a date that is now a non-working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XXXX ░░ | working days include weekends+ CHART- before do- set_working_week_days('wednesday')- end+ before do+ set_non_working_week_days('wednesday')+ end- it 'does not move the follower backwards' do- job.perform_now(user_id: user.id, previous_working_days:)+ it 'does not move any dates' do+ job.perform_now(user_id: user.id, previous_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XXXX ░░ |+ CHART+ end- expect_schedule(WorkPackage.all, <<~CHART)- days | MTWTFSS |- predecessor | XX ░░ |- follower | XXX |- CHART- end+ it_behaves_like 'journal updates with note' do+ let(:unchanged_work_packages) do+ [work_package]+ end+ end+ end++ context 'when a work package only has a duration' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | ░░ | duration 3 days+ CHART++ before do+ set_non_working_week_days('wednesday')+ end- it_behaves_like 'journal updates with note' do- let(:changed_work_packages) do- [predecessor]+ it 'does not change anything' do+ job.perform_now(user_id: user.id, previous_working_days:)+ expect(work_package.duration).to eq(3)+ end++ it_behaves_like 'journal updates with note' do+ let(:unchanged_work_packages) do+ [work_package]+ end+ endend- let(:unchanged_work_packages) do- [follower]++ context 'when having multiple work packages following each other, and having days becoming non working days' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ wp1 | X▓▓XX | follows wp2+ wp2 | X ░░ | follows wp3+ wp3 | XXX ░░ |+ CHART++ before do+ set_non_working_week_days('tuesday', 'wednesday', 'friday')+ end++ it 'updates them only once most of the time' do+ expect { job.perform_now(user_id: user.id, previous_working_days:) }+ .to change { WorkPackage.pluck(:lock_version) }+ .from([0, 0, 0])+ .to([1, 1, 1])+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSSmtwtfssmtwtfss |+ wp1 | ░░ ░░░ ░░ ░░░X▓▓X▓▓▓X |+ wp2 | ░░ ░░░ ░░X░░░ ░░ ░░░ |+ wp3 | X▓▓X▓▓▓X░░ ░░░ ░░ ░░░ |+ CHART+ end++ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [wp1, wp2, wp3]+ end+ let(:journal_notice) do+ "**Working days** changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."+ end+ endend- let(:journal_notice) { "**Working days** changed (Wednesday is now working)." }- end- end- context 'when a follower has a predecessor with a non-working day between them that is now a working day' do- let_schedule(<<~CHART)- days | MTWTFSS |- predecessor | XX░ ░░ |- follower | ░XX░░ | follows predecessor- CHART- let(:work_week) { set_work_week('monday', 'tuesday', 'thursday', 'friday') }+ context 'with multiple predecessors for same follower' do+ # Given below schedule, as work packages are processed by order of start_date+ # ascending, the processing order will be wp1, wp2, wp3.+ #+ # So when Tuesday, Wednesday and Friday become non-working days:+ # * wp1 will move from Tuesday to Thursday and its followers will be rescheduled too+ # * follower wp3 gets rescheduled and moves to next Monday+ # * wp2 will move from Wednesday-Thursday to Thursday-nextMonday too and its followers will be rescheduled too+ # * follower wp3 gets rescheduled *again* and moves to next Thursday+ let_schedule(<<~CHART)+ days | MTWTFSS |+ wp1 | X ░░ |+ wp2 | XX ░░ |+ wp3 | X░░ | follows wp1, follows wp2+ CHART++ before do+ set_non_working_week_days('tuesday', 'wednesday', 'friday')+ end- before do- set_working_week_days('wednesday')- end+ it 'can update some followers twice sometimes' do+ expect { job.perform_now(user_id: user.id, previous_working_days:) }+ .to change { WorkPackage.order(:subject).pluck(:lock_version) }+ .from([0, 0, 0])+ .to([1, 1, 2])+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSSmtwt |+ wp1 | ░░X░░░ ░░ |+ wp2 | ░░X▓▓▓X░░ |+ wp3 | ░░ ░░░ ░░X |+ CHART+ end- it 'does not move the follower' do- job.perform_now(user_id: user.id, previous_working_days:)- expect(WorkPackage.all).to match_schedule(<<~CHART)- days | MTWTFSS |- predecessor | XX |- follower | XX░░ |- CHART- end+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [wp1, wp2, wp3]+ end+ let(:journal_notice) do+ "**Working days** changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."+ end+ end+ end- it_behaves_like 'journal updates with note' do- let(:unchanged_work_packages) do- [predecessor, follower]+ context 'when having multiple work packages following each other, and having days becoming working days' do+ let_schedule(<<~CHART)+ days | MTWTFSSmtwtfssmtwtfss |+ wp1 | ░░ ░░░ ░░ ░░░X▓▓X▓▓▓X | follows wp2+ wp2 | ░░ ░░░ ░░X░░░ ░░ ░░░ | follows wp3+ wp3 | X▓▓X▓▓▓X░░ ░░░ ░░ ░░░ |+ CHART++ let(:work_week) { set_work_week('monday', 'thursday') }++ before do+ set_working_week_days('tuesday', 'wednesday', 'friday')+ end++ it 'keeps the same start dates and updates them only once' do+ job.perform_now(user_id: user.id, previous_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSSmtwtfssmtwtfss |+ wp1 | ░░ ░░XXX ░░ | follows wp2+ wp2 | ░░ X ░░ ░░ | follows wp3+ wp3 | XXX ░░ ░░ ░░ |+ CHART+ expect(WorkPackage.pluck(:lock_version)).to all(be <= 1)+ end++ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [wp1, wp3]+ end+ let(:unchanged_work_packages) do+ [wp2]+ end+ let(:journal_notice) do+ "**Working days** changed (Tuesday is now working, Wednesday is now working, Friday is now working)."+ end+ endend- end- end- context 'when a work package has working days include weekends, and includes a date that is now a non-working day' do- let_schedule(<<~CHART)- days | MTWTFSS |- work_package | XXXX ░░ | working days include weekends- CHART+ context 'when having multiple work packages following each other and first one only has a due date' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ wp1 | X▓▓XX | follows wp2+ wp2 | XX ░░ | follows wp3+ wp3 | ] ░░ |+ CHART- before do- set_non_working_week_days('wednesday')- end+ before do+ set_non_working_week_days('tuesday', 'wednesday', 'friday')+ end- it 'does not move any dates' do- job.perform_now(user_id: user.id, previous_working_days:)- expect(WorkPackage.all).to match_schedule(<<~CHART)- days | MTWTFSS |- work_package | XXXX ░░ |- CHART- end+ it 'updates all of them correctly' do+ expect { job.perform_now(user_id: user.id, previous_working_days:) }+ .to change { WorkPackage.pluck(:lock_version) }+ .from([0, 0, 0])+ .to([1, 1, 1])+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSSm t ssm t ssm |+ wp1 | ░░ ░░░ ░░ ░░░X▓▓X▓▓▓X |+ wp2 | ░░ ░░░X▓▓X░░░ ░░ ░░░ |+ wp3 | ░░]░░░ ░░ ░░░ ░░ ░░░ |+ CHART+ end- it_behaves_like 'journal updates with note' do- let(:unchanged_work_packages) do- [work_package]+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [wp1, wp2, wp3]+ end+ let(:journal_notice) do+ "**Working days** changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."+ end+ endend- end- end- context 'when a work package only has a duration' do- let_schedule(<<~CHART)- days | MTWTFSS |- work_package | ░░ | duration 3 days- CHART+ context 'when having a non english default language', with_settings: { default_language: :fr } do+ let_schedule(<<~CHART)+ days | fssMTWTFSS |+ work_package | X▓▓XX ░░ |+ CHART- before do- set_non_working_week_days('wednesday')- end+ before do+ set_working_week_days('saturday')+ end- it 'does not change anything' do- job.perform_now(user_id: user.id, previous_working_days:)- expect(work_package.duration).to eq(3)- end+ # Not interested in the scheduling changes in this spec+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [work_package]+ end+ let(:journal_notice) do+ I18n.with_locale(:fr) do+ I18n.t(:'working_days.journal_note.changed',+ changes: I18n.t(:'working_days.journal_note.days.working',+ day: I18n.t('date.day_names')[6]))+ end+ end+ end+ end++ context 'when turning Sunday into a working day' do+ let_schedule(<<~CHART)+ days | MTWTFSSm |+ work_package | X▓▓X |+ CHART++ before do+ set_working_week_days('Sunday')+ end- it_behaves_like 'journal updates with note' do- let(:unchanged_work_packages) do- [work_package]+ # Not interested in the scheduling changes in this spec+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [work_package]+ end+ let(:journal_notice) do+ "**Working days** changed (Sunday is now working)."+ end+ endendend- end- context 'when having multiple work packages following each other, and having days becoming non working days' do- let_schedule(<<~CHART)- days | MTWTFSS |- wp1 | X▓▓XX | follows wp2- wp2 | X ░░ | follows wp3- wp3 | XXX ░░ |- CHART+ context 'with non-working days' do+ context 'when a work package includes a date that is now a non-working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XXXX ░░ |+ work_package_on_start | XX ░░ |+ work_package_on_due | XXX ░░ |+ wp_start_only | [ ░░ |+ wp_due_only | ] ░░ |+ CHART++ before do+ create(:non_working_day, date: Date.current.next_occurring(:wednesday))+ end- before do- set_non_working_week_days('tuesday', 'wednesday', 'friday')- end+ it 'moves the finish date to the corresponding number of now-excluded days to maintain duration [#31992]' do+ job.perform_now(user_id: user.id, previous_non_working_days:)++ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XX▓XX░░ |+ work_package_on_start | ░XX░░ |+ work_package_on_due | XX▓X ░░ |+ wp_start_only | ░[ ░░ |+ wp_due_only | ░] ░░ |+ CHART+ end- it 'updates them only once most of the time' do- expect { job.perform_now(user_id: user.id, previous_working_days:) }- .to change { WorkPackage.pluck(:lock_version) }- .from([0, 0, 0])- .to([1, 1, 1])- expect(WorkPackage.all).to match_schedule(<<~CHART)- days | MTWTFSSmtwtfssmtwtfss |- wp1 | ░░ ░░░ ░░ ░░░X▓▓X▓▓▓X |- wp2 | ░░ ░░░ ░░X░░░ ░░ ░░░ |- wp3 | X▓▓X▓▓▓X░░ ░░░ ░░ ░░░ |- CHART- end+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [work_package,+ work_package_on_start,+ work_package_on_due,+ wp_start_only,+ wp_due_only]+ end+ let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }+ end+ end- it_behaves_like 'journal updates with note' do- let(:changed_work_packages) do- [wp1, wp2, wp3]+ context 'when a work package was scheduled to start on a date that is now a non-working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XX ░░ |+ CHART++ before do+ create(:non_working_day, date: Date.current.next_occurring(:wednesday))+ end++ it 'moves the start date to the earliest working day in the future, ' \+ 'and the finish date changes by consequence [#31992]' do+ job.perform_now(user_id: user.id, previous_non_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | ░XX░░ |+ CHART+ end++ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [work_package]+ end+ let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }+ endend- let(:journal_notice) do- "**Working days** changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."++ context 'when a work package includes a date that is no more a non-working day' do+ let_schedule(<<~CHART)+ days | fssMTWTFSS |+ work_package | X▓▓XX ░░ |+ CHART++ before do+ set_working_week_days('saturday')+ end++ it 'moves the finish date backwards to the corresponding number of now-included days to maintain duration [#31992]' do+ job.perform_now(user_id: user.id, previous_non_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | fssMTWTFSS |+ work_package | XX▓X ░ |+ CHART+ end++ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [work_package]+ end+ let(:journal_notice) { "**Working days** changed (Saturday is now working)." }+ endend- end- end- context 'with multiple predecessors for same follower' do- # Given below schedule, as work packages are processed by order of start_date- # ascending, the processing order will be wp1, wp2, wp3.- #- # So when Tuesday, Wednesday and Friday become non-working days:- # * wp1 will move from Tuesday to Thursday and its followers will be rescheduled too- # * follower wp3 gets rescheduled and moves to next Monday- # * wp2 will move from Wednesday-Thursday to Thursday-nextMonday too and its followers will be rescheduled too- # * follower wp3 gets rescheduled *again* and moves to next Thursday- let_schedule(<<~CHART)- days | MTWTFSS |- wp1 | X ░░ |- wp2 | XX ░░ |- wp3 | X░░ | follows wp1, follows wp2- CHART-- before do- set_non_working_week_days('tuesday', 'wednesday', 'friday')- end+ context 'when a follower has a predecessor with dates covering a day that is now a non-working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX ░░ | working days work week+ follower | XXX░ | working days include weekends, follows predecessor+ CHART- it 'can update some followers twice sometimes' do- expect { job.perform_now(user_id: user.id, previous_working_days:) }- .to change { WorkPackage.order(:subject).pluck(:lock_version) }- .from([0, 0, 0])- .to([1, 1, 2])- expect(WorkPackage.all).to match_schedule(<<~CHART)- days | MTWTFSSmtwt |- wp1 | ░░X░░░ ░░ |- wp2 | ░░X▓▓▓X░░ |- wp3 | ░░ ░░░ ░░X |- CHART- end+ before do+ create(:non_working_day, date: Date.current.next_occurring(:wednesday))+ end- it_behaves_like 'journal updates with note' do- let(:changed_work_packages) do- [wp1, wp2, wp3]+ it 'moves the follower start date by consequence of the predecessor dates shift [#31992]' do+ job.perform_now(user_id: user.id, previous_non_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | X▓X ░░ |+ follower | ░ XXX |+ CHART+ end++ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [predecessor, follower]+ end+ let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }+ endend- let(:journal_notice) do- "**Working days** changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."++ context 'when a follower has a predecessor with delay covering a day that is now a non-working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX ░░ |+ follower | X ░░ | follows predecessor with delay 1+ CHART++ before do+ create(:non_working_day, date: Date.current.next_occurring(:wednesday))+ end++ it 'moves the follower start date forward to keep the delay to 1 day' do+ job.perform_now(user_id: user.id, previous_non_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX░ ░░ |+ follower | ░ X░░ |+ CHART+ end++ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [follower]+ end+ let(:unchanged_work_packages) do+ [predecessor]+ end+ let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }+ endend- end- end- context 'when having multiple work packages following each other, and having days becoming working days' do- let_schedule(<<~CHART)- days | MTWTFSSmtwtfssmtwtfss |- wp1 | ░░ ░░░ ░░ ░░░X▓▓X▓▓▓X | follows wp2- wp2 | ░░ ░░░ ░░X░░░ ░░ ░░░ | follows wp3- wp3 | X▓▓X▓▓▓X░░ ░░░ ░░ ░░░ |- CHART+ context 'with work packages without dates following each other with delay' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | ░░ |+ follower | ░░ | follows predecessor with delay 5+ CHART- let(:work_week) { set_work_week('monday', 'thursday') }+ before do+ set_non_working_week_days('wednesday')+ end- before do- set_working_week_days('tuesday', 'wednesday', 'friday')- end+ it 'does not move anything (obviously) and does not crash either' do+ job.perform_now(user_id: user.id, previous_non_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | ░ ░░ |+ follower | ░ ░░ |+ CHART+ end- it 'keeps the same start dates and updates them only once' do- job.perform_now(user_id: user.id, previous_working_days:)- expect(WorkPackage.all).to match_schedule(<<~CHART)- days | MTWTFSSmtwtfssmtwtfss |- wp1 | ░░ ░░XXX ░░ | follows wp2- wp2 | ░░ X ░░ ░░ | follows wp3- wp3 | XXX ░░ ░░ ░░ |- CHART- expect(WorkPackage.pluck(:lock_version)).to all(be <= 1)- end+ it_behaves_like 'journal updates with note' do+ let(:unchanged_work_packages) do+ [predecessor, follower]+ end+ end+ end++ context 'when a follower has a predecessor with delay covering multiple days with different working changes' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | X ░ ░░ |+ follower | ░ X░░ | follows predecessor with delay 2+ CHART+ let(:work_week) { set_work_week('monday', 'tuesday', 'thursday', 'friday') }++ before do+ create(:non_working_day, date: Date.current.next_occurring(:tuesday))+ # set_non_working_week_days('tuesday')+ # set_working_week_days('wednesday')+ end++ it 'correctly handles the changes' do+ job.perform_now(user_id: user.id, previous_non_working_days:)+ expect_schedule(WorkPackage.all, <<~CHART)+ days | MTWTFSS |+ predecessor | X░ ░░ |+ follower | ░ X░░ |+ CHART+ end++ it_behaves_like 'journal updates with note' do+ let(:unchanged_work_packages) do+ [predecessor, follower]+ end+ end+ end++ context 'when a follower has a predecessor with dates covering a day that is now a working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | X▓X ░░ | working days work week+ follower | ░ XXX | working days include weekends, follows predecessor+ CHART+ let(:work_week) { set_work_week('monday', 'tuesday', 'thursday', 'friday') }++ before do+ set_working_week_days('wednesday')+ end++ it 'does not move the follower backwards' do+ job.perform_now(user_id: user.id, previous_non_working_days:)++ expect_schedule(WorkPackage.all, <<~CHART)+ days | MTWTFSS |+ predecessor | XX ░░ |+ follower | XXX |+ CHART+ end- it_behaves_like 'journal updates with note' do- let(:changed_work_packages) do- [wp1, wp3]+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [predecessor]+ end+ let(:unchanged_work_packages) do+ [follower]+ end+ let(:journal_notice) { "**Working days** changed (Wednesday is now working)." }+ endend- let(:unchanged_work_packages) do- [wp2]++ context 'when a follower has a predecessor with a non-working day between them that is now a working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX░ ░░ |+ follower | ░XX░░ | follows predecessor+ CHART+ let(:work_week) { set_work_week('monday', 'tuesday', 'thursday', 'friday') }++ before do+ set_working_week_days('wednesday')+ end++ it 'does not move the follower' do+ job.perform_now(user_id: user.id, previous_non_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ predecessor | XX |+ follower | XX░░ |+ CHART+ end++ it_behaves_like 'journal updates with note' do+ let(:unchanged_work_packages) do+ [predecessor, follower]+ end+ endend- let(:journal_notice) do- "**Working days** changed (Tuesday is now working, Wednesday is now working, Friday is now working)."++ context 'when a work package has working days include weekends, and includes a date that is now a non-working day' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XXXX ░░ | working days include weekends+ CHART++ before do+ set_non_working_week_days('wednesday')+ end++ it 'does not move any dates' do+ job.perform_now(user_id: user.id, previous_non_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | XXXX ░░ |+ CHART+ end++ it_behaves_like 'journal updates with note' do+ let(:unchanged_work_packages) do+ [work_package]+ end+ endend- end- end- context 'when having multiple work packages following each other and first one only has a due date' do- let_schedule(<<~CHART)- days | MTWTFSS |- wp1 | X▓▓XX | follows wp2- wp2 | XX ░░ | follows wp3- wp3 | ] ░░ |- CHART+ context 'when a work package only has a duration' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ work_package | ░░ | duration 3 days+ CHART- before do- set_non_working_week_days('tuesday', 'wednesday', 'friday')- end+ before do+ set_non_working_week_days('wednesday')+ end- it 'updates all of them correctly' do- expect { job.perform_now(user_id: user.id, previous_working_days:) }- .to change { WorkPackage.pluck(:lock_version) }- .from([0, 0, 0])- .to([1, 1, 1])- expect(WorkPackage.all).to match_schedule(<<~CHART)- days | MTWTFSSm t ssm t ssm |- wp1 | ░░ ░░░ ░░ ░░░X▓▓X▓▓▓X |- wp2 | ░░ ░░░X▓▓X░░░ ░░ ░░░ |- wp3 | ░░]░░░ ░░ ░░░ ░░ ░░░ |- CHART- end+ it 'does not change anything' do+ job.perform_now(user_id: user.id, previous_non_working_days:)+ expect(work_package.duration).to eq(3)+ end- it_behaves_like 'journal updates with note' do- let(:changed_work_packages) do- [wp1, wp2, wp3]+ it_behaves_like 'journal updates with note' do+ let(:unchanged_work_packages) do+ [work_package]+ end+ endend- let(:journal_notice) do- "**Working days** changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."++ context 'when having multiple work packages following each other, and having days becoming non working days' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ wp1 | X▓▓XX | follows wp2+ wp2 | X ░░ | follows wp3+ wp3 | XXX ░░ |+ CHART++ before do+ set_non_working_week_days('tuesday', 'wednesday', 'friday')+ end++ it 'updates them only once most of the time' do+ expect { job.perform_now(user_id: user.id, previous_non_working_days:) }+ .to change { WorkPackage.pluck(:lock_version) }+ .from([0, 0, 0])+ .to([1, 1, 1])+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSSmtwtfssmtwtfss |+ wp1 | ░░ ░░░ ░░ ░░░X▓▓X▓▓▓X |+ wp2 | ░░ ░░░ ░░X░░░ ░░ ░░░ |+ wp3 | X▓▓X▓▓▓X░░ ░░░ ░░ ░░░ |+ CHART+ end++ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [wp1, wp2, wp3]+ end+ let(:journal_notice) do+ "**Working days** changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."+ end+ endend- end- end- context 'when having a non english default language', with_settings: { default_language: :fr } do- let_schedule(<<~CHART)- days | fssMTWTFSS |- work_package | X▓▓XX ░░ |- CHART+ context 'with multiple predecessors for same follower' do+ # Given below schedule, as work packages are processed by order of start_date+ # ascending, the processing order will be wp1, wp2, wp3.+ #+ # So when Tuesday, Wednesday and Friday become non-working days:+ # * wp1 will move from Tuesday to Thursday and its followers will be rescheduled too+ # * follower wp3 gets rescheduled and moves to next Monday+ # * wp2 will move from Wednesday-Thursday to Thursday-nextMonday too and its followers will be rescheduled too+ # * follower wp3 gets rescheduled *again* and moves to next Thursday+ let_schedule(<<~CHART)+ days | MTWTFSS |+ wp1 | X ░░ |+ wp2 | XX ░░ |+ wp3 | X░░ | follows wp1, follows wp2+ CHART++ before do+ set_non_working_week_days('tuesday', 'wednesday', 'friday')+ end- before do- set_working_week_days('saturday')- end+ it 'can update some followers twice sometimes' do+ expect { job.perform_now(user_id: user.id, previous_non_working_days:) }+ .to change { WorkPackage.order(:subject).pluck(:lock_version) }+ .from([0, 0, 0])+ .to([1, 1, 2])+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSSmtwt |+ wp1 | ░░X░░░ ░░ |+ wp2 | ░░X▓▓▓X░░ |+ wp3 | ░░ ░░░ ░░X |+ CHART+ end- # Not interested in the scheduling changes in this spec- it_behaves_like 'journal updates with note' do- let(:changed_work_packages) do- [work_package]+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [wp1, wp2, wp3]+ end+ let(:journal_notice) do+ "**Working days** changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."+ end+ endend- let(:journal_notice) do- I18n.with_locale(:fr) do- I18n.t(:'working_days.journal_note.changed',- changes: I18n.t(:'working_days.journal_note.days.working',- day: I18n.t('date.day_names')[6]))++ context 'when having multiple work packages following each other, and having days becoming working days' do+ let_schedule(<<~CHART)+ days | MTWTFSSmtwtfssmtwtfss |+ wp1 | ░░ ░░░ ░░ ░░░X▓▓X▓▓▓X | follows wp2+ wp2 | ░░ ░░░ ░░X░░░ ░░ ░░░ | follows wp3+ wp3 | X▓▓X▓▓▓X░░ ░░░ ░░ ░░░ |+ CHART++ let(:work_week) { set_work_week('monday', 'thursday') }++ before do+ set_working_week_days('tuesday', 'wednesday', 'friday')+ end++ it 'keeps the same start dates and updates them only once' do+ job.perform_now(user_id: user.id, previous_non_working_days:)+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSSmtwtfssmtwtfss |+ wp1 | ░░ ░░XXX ░░ | follows wp2+ wp2 | ░░ X ░░ ░░ | follows wp3+ wp3 | XXX ░░ ░░ ░░ |+ CHART+ expect(WorkPackage.pluck(:lock_version)).to all(be <= 1)+ end++ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [wp1, wp3]+ end+ let(:unchanged_work_packages) do+ [wp2]+ end+ let(:journal_notice) do+ "**Working days** changed (Tuesday is now working, Wednesday is now working, Friday is now working)."+ endendend- end- end- context 'when turning Sunday into a working day' do- let_schedule(<<~CHART)- days | MTWTFSSm |- work_package | X▓▓X |- CHART+ context 'when having multiple work packages following each other and first one only has a due date' do+ let_schedule(<<~CHART)+ days | MTWTFSS |+ wp1 | X▓▓XX | follows wp2+ wp2 | XX ░░ | follows wp3+ wp3 | ] ░░ |+ CHART- before do- set_working_week_days('Sunday')- end+ before do+ set_non_working_week_days('tuesday', 'wednesday', 'friday')+ end++ it 'updates all of them correctly' do+ expect { job.perform_now(user_id: user.id, previous_non_working_days:) }+ .to change { WorkPackage.pluck(:lock_version) }+ .from([0, 0, 0])+ .to([1, 1, 1])+ expect(WorkPackage.all).to match_schedule(<<~CHART)+ days | MTWTFSSm t ssm t ssm |+ wp1 | ░░ ░░░ ░░ ░░░X▓▓X▓▓▓X |+ wp2 | ░░ ░░░X▓▓X░░░ ░░ ░░░ |+ wp3 | ░░]░░░ ░░ ░░░ ░░ ░░░ |+ CHART+ end- # Not interested in the scheduling changes in this spec- it_behaves_like 'journal updates with note' do- let(:changed_work_packages) do- [work_package]+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [wp1, wp2, wp3]+ end+ let(:journal_notice) do+ "**Working days** changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."+ end+ endend- let(:journal_notice) do- "**Working days** changed (Sunday is now working)."++ context 'when having a non english default language', with_settings: { default_language: :fr } do+ let_schedule(<<~CHART)+ days | fssMTWTFSS |+ work_package | X▓▓XX ░░ |+ CHART++ before do+ set_working_week_days('saturday')+ end++ # Not interested in the scheduling changes in this spec+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [work_package]+ end+ let(:journal_notice) do+ I18n.with_locale(:fr) do+ I18n.t(:'working_days.journal_note.changed',+ changes: I18n.t(:'working_days.journal_note.days.working',+ day: I18n.t('date.day_names')[6]))+ end+ end+ end+ end++ context 'when turning Sunday into a working day' do+ let_schedule(<<~CHART)+ days | MTWTFSSm |+ work_package | X▓▓X |+ CHART++ before do+ set_working_week_days('Sunday')+ end++ # Not interested in the scheduling changes in this spec+ it_behaves_like 'journal updates with note' do+ let(:changed_work_packages) do+ [work_package]+ end+ let(:journal_notice) do+ "**Working days** changed (Sunday is now working)."+ end+ endendendend@@ -578,7 +1097,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dobefore doActiveJob::QueueAdapters::DelayedJobAdapter.new- .enqueue(described_class.new(user_id: 5, previous_working_days: [1, 2]))+ .enqueue(described_class.new(user_id: 5, previous_non_working_days: [1, 2]))endit 'is true' do