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 WorkPackages::ApplyWorkingDaysChangeJob adding the previous_non_working_days and specs
Dombi Attilac8da1e33280b
diff --git a/app/workers/work_packages/apply_working_days_change_job.rb b/app/workers/work_packages/apply_working_days_change_job.rbindex 1a5a38509a4..a4bb329c32b 100644--- a/app/workers/work_packages/apply_working_days_change_job.rb+++ b/app/workers/work_packages/apply_working_days_change_job.rb@@ -30,18 +30,19 @@ class WorkPackages::ApplyWorkingDaysChangeJob < ApplicationJobqueue_with_priority :above_normalinclude ::ScheduledJob- def perform(user_id:, previous_working_days:)+ def perform(user_id:, previous_working_days:, previous_non_working_days:)user = User.find(user_id)User.execute_as user do- updated_work_package_ids = collect_id_for_each(applicable_work_package(previous_working_days)) do |work_package|+ updated_work_package_ids = collect_id_for_each(applicable_work_package(previous_working_days,+ previous_non_working_days)) do |work_package|apply_change_to_work_package(user, work_package)endupdated_work_package_ids += collect_id_for_each(applicable_predecessor(updated_work_package_ids)) do |predecessor|apply_change_to_predecessor(user, predecessor)end- set_journal_notice(updated_work_package_ids, previous_working_days)+ set_journal_notice(updated_work_package_ids, previous_working_days, previous_non_working_days)endend@@ -68,11 +69,11 @@ class WorkPackages::ApplyWorkingDaysChangeJob < ApplicationJobendend- def applicable_work_package(previous_working_days)- changed_days = changed_days(previous_working_days)-+ def applicable_work_package(previous_working_days, previous_non_working_days)+ days_of_week = changed_days(previous_working_days)+ dates = changed_non_working_days(previous_non_working_days)WorkPackage- .covering_dates_and_days_of_week(changed_days)+ .covering_dates_and_days_of_week(days_of_week:, dates:).order(WorkPackage.arel_table[:start_date].asc.nulls_first,WorkPackage.arel_table[:due_date].asc)end@@ -86,15 +87,25 @@ class WorkPackages::ApplyWorkingDaysChangeJob < ApplicationJob(previous ^ current).to_aend+ def changed_non_working_days(previous_non_working_days)+ previous = Set.new(previous_non_working_days)+ current = Set.new(NonWorkingDay.pluck(:date))++ # `^` is a Set method returning a new set containing elements exclusive to+ # each other+ (previous ^ current).to_a+ end+def applicable_predecessor(excluded)WorkPackage.where(id: Relation.follows_with_delay.select(:to_id)).where.not(id: excluded)end- def set_journal_notice(updated_work_package_ids, previous_working_days)+ def set_journal_notice(updated_work_package_ids, previous_working_days, previous_non_working_days)day_changes = changed_days(previous_working_days).index_with { |day| Setting.working_days.include?(day) }- journal_note = journal_notice_text(day_changes)+ date_changes = changed_non_working_days(previous_non_working_days).index_with { |day| !NonWorkingDay.exists?(date: day) }+ journal_note = journal_notice_text(day_changes, date_changes)WorkPackage.where(id: updated_work_package_ids.uniq)@@ -105,10 +116,12 @@ class WorkPackages::ApplyWorkingDaysChangeJob < ApplicationJobendend- def journal_notice_text(day_changes)+ def journal_notice_text(day_changes, date_changes)I18n.with_locale(Setting.default_language) do+ day_changes_messages = day_changes.collect { |day, working| working_day_change_message(day, working) }+ date_changes_messages = date_changes.collect { |date, working| working_date_change_message(date, working) }I18n.t(:'working_days.journal_note.changed',- changes: day_changes.collect { |day, working| working_day_change_message(day, working) }.join(', '))+ changes: (day_changes_messages + date_changes_messages).join(', '))endend@@ -117,6 +130,10 @@ class WorkPackages::ApplyWorkingDaysChangeJob < ApplicationJobday: WeekDay.find_by!(day:).name)end+ def working_date_change_message(date, working)+ I18n.t(:"working_days.journal_note.dates.#{working ? :working : :non_working}", date:)+ end+def collect_id_for_each(scope)scope.pluck(:id).map do |id|yield(WorkPackage.find(id)).pluck(:id)diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 29d20aa2949..b510b8eb9a2 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3159,6 +3159,9 @@ en:days:working: "%{day} is now working"non_working: "%{day} is now non-working"+ dates:+ working: "%{date} is now working"+ non_working: "%{date} is now non-working"nothing_to_preview: "Nothing to preview"api_v3:diff --git a/spec/support/non_working_days.rb b/spec/support/non_working_days.rbnew file mode 100644index 00000000000..6dce3af9d8e--- /dev/null+++ b/spec/support/non_working_days.rb@@ -0,0 +1,48 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++def week_with_saturday_and_sunday_as_non_working_day(monday: Date.current.monday, weeks_size: 4)+ weeks_size.times.map do |week_count|+ [+ create(:non_working_day, date: monday.next_occurring(:saturday) + week_count.weeks),+ create(:non_working_day, date: monday.next_occurring(:sunday) + week_count.weeks)+ ]+ end.flatten.pluck(:date)+end++def week_without_non_working_days(monday: Date.current.monday, weeks_size: 4)+ NonWorkingDay.where(date: monday...monday + weeks_size.weeks).destroy_all+end++def set_non_working_days(*dates)+ dates.map { |date| create(:non_working_day, date:) }+end++def set_working_days(*dates)+ NonWorkingDay.where(date: dates).destroy_all+enddiff --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 b09f7958c36..36f31c99927 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@@ -34,10 +34,13 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dosubject(:job) { described_class }shared_let(:user) { create(:user) }+ shared_let(:next_monday) { Date.current.next_occurring(:monday) }+ shared_let(:monday) { Date.current.monday }let(:work_week) { week_with_saturday_and_sunday_as_weekend }# This must run before any working days are changed, hence the `let!` formlet!(:previous_working_days) { work_week }+ let!(:previous_non_working_days) { [] }shared_examples_for 'journal updates with note' dolet(:changed_work_packages) { [] }@@ -45,7 +48,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dolet(:journal_notice) { raise 'need to specify note' }it 'adds journal entries to changed work packages' do- job.perform_now(user_id: user.id, previous_working_days:)+ subjectchanged_work_packages.each do |work_package|expect(work_package.journals.count)@@ -62,6 +65,8 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doenddescribe '#perform' do+ subject { job.perform_now(user_id: user.id, previous_working_days:, previous_non_working_days:) }+context 'with non-working weekday settings' docontext 'when a work package includes a date that is now a non-working day' dolet_schedule(<<~CHART)@@ -78,7 +83,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit '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:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |@@ -114,7 +119,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doit '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:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |work_package | ░XX░░ |@@ -140,7 +145,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit '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:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | fssMTWTFSS |work_package | XX▓X ░ |@@ -167,7 +172,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit 'moves the follower start date by consequence of the predecessor dates shift [#31992]' do- job.perform_now(user_id: user.id, previous_working_days:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |predecessor | X▓X ░░ |@@ -195,7 +200,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit 'moves the follower start date forward to keep the delay to 1 day' do- job.perform_now(user_id: user.id, previous_working_days:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |predecessor | XX░ ░░ |@@ -226,7 +231,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit 'does not move anything (obviously) and does not crash either' do- job.perform_now(user_id: user.id, previous_working_days:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |predecessor | ░ ░░ |@@ -255,7 +260,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit 'correctly handles the changes' do- job.perform_now(user_id: user.id, previous_working_days:)+ subjectexpect_schedule(WorkPackage.all, <<~CHART)days | MTWTFSS |predecessor | X░ ░░ |@@ -283,7 +288,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit 'does not move the follower backwards' do- job.perform_now(user_id: user.id, previous_working_days:)+ subjectexpect_schedule(WorkPackage.all, <<~CHART)days | MTWTFSS |@@ -316,7 +321,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit 'does not move the follower' do- job.perform_now(user_id: user.id, previous_working_days:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |predecessor | XX |@@ -342,7 +347,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit 'does not move any dates' do- job.perform_now(user_id: user.id, previous_working_days:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |work_package | XXXX ░░ |@@ -367,7 +372,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit 'does not change anything' do- job.perform_now(user_id: user.id, previous_working_days:)+ subjectexpect(work_package.duration).to eq(3)end@@ -391,7 +396,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit 'updates them only once most of the time' do- expect { job.perform_now(user_id: user.id, previous_working_days:) }+ expect { subject }.to change { WorkPackage.pluck(:lock_version) }.from([0, 0, 0]).to([1, 1, 1])@@ -434,7 +439,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit 'can update some followers twice sometimes' do- expect { job.perform_now(user_id: user.id, previous_working_days:) }+ expect { subject }.to change { WorkPackage.order(:subject).pluck(:lock_version) }.from([0, 0, 0]).to([1, 1, 2])@@ -471,7 +476,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit 'keeps the same start dates and updates them only once' do- job.perform_now(user_id: user.id, previous_working_days:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSSmtwtfssmtwtfss |wp1 | ░░ ░░XXX ░░ | follows wp2@@ -507,7 +512,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendit 'updates all of them correctly' do- expect { job.perform_now(user_id: user.id, previous_working_days:) }+ expect { subject }.to change { WorkPackage.pluck(:lock_version) }.from([0, 0, 0]).to([1, 1, 1])@@ -577,6 +582,9 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doendcontext 'with non-working days' do+ let(:work_week) { week_with_all_days_working }+ let!(:previous_non_working_days) { week_with_saturday_and_sunday_as_non_working_day }+context 'when a work package includes a date that is now a non-working day' dolet_schedule(<<~CHART)days | MTWTFSS |@@ -588,11 +596,11 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doCHARTbefore do- create(:non_working_day, date: Date.current.next_occurring(:wednesday))+ set_non_working_days(next_monday.next_occurring(:wednesday))endit '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:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |@@ -612,7 +620,9 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dowp_start_only,wp_due_only]end- let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }+ let(:journal_notice) do+ "**Working days** changed (#{next_monday.next_occurring(:wednesday)} is now non-working)."+ endendend@@ -623,12 +633,12 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doCHARTbefore do- create(:non_working_day, date: Date.current.next_occurring(:wednesday))+ set_non_working_days(next_monday.next_occurring(:wednesday))endit '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:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |work_package | ░XX░░ |@@ -639,7 +649,9 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dolet(:changed_work_packages) do[work_package]end- let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }+ let(:journal_notice) do+ "**Working days** changed (#{next_monday.next_occurring(:wednesday)} is now non-working)."+ endendend@@ -650,11 +662,11 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doCHARTbefore do- set_working_week_days('saturday')+ set_working_days(monday.next_occurring(:saturday))endit '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:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | fssMTWTFSS |work_package | XX▓X ░ |@@ -665,7 +677,10 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dolet(:changed_work_packages) do[work_package]end- let(:journal_notice) { "**Working days** changed (Saturday is now working)." }++ let(:journal_notice) do+ "**Working days** changed (#{monday.next_occurring(:saturday)} is now working)."+ endendend@@ -677,11 +692,11 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doCHARTbefore do- create(:non_working_day, date: Date.current.next_occurring(:wednesday))+ set_non_working_days(next_monday.next_occurring(:wednesday))endit '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:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |predecessor | X▓X ░░ |@@ -693,7 +708,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dolet(:changed_work_packages) do[predecessor, follower]end- let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }+ let(:journal_notice) { "**Working days** changed (#{next_monday.next_occurring(:wednesday)} is now non-working)." }endend@@ -705,11 +720,11 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doCHARTbefore do- create(:non_working_day, date: Date.current.next_occurring(:wednesday))+ set_non_working_days(next_monday.next_occurring(:wednesday))endit '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:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |predecessor | XX░ ░░ |@@ -724,7 +739,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dolet(:unchanged_work_packages) do[predecessor]end- let(:journal_notice) { "**Working days** changed (Wednesday is now non-working)." }+ let(:journal_notice) { "**Working days** changed (#{next_monday.next_occurring(:wednesday)} is now non-working)." }endend@@ -736,11 +751,11 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doCHARTbefore do- set_non_working_week_days('wednesday')+ set_non_working_days(next_monday.next_occurring(:wednesday))endit 'does not move anything (obviously) and does not crash either' do- job.perform_now(user_id: user.id, previous_non_working_days:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |predecessor | ░ ░░ |@@ -761,16 +776,20 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dopredecessor | X ░ ░░ |follower | ░ X░░ | follows predecessor with delay 2CHART- let(:work_week) { set_work_week('monday', 'tuesday', 'thursday', 'friday') }++ let(:non_working_day) { create(:non_working_day, date: next_monday.next_occurring(:wednesday)) }++ let!(:previous_non_working_days) do+ week_with_saturday_and_sunday_as_non_working_day + [non_working_day.date]+ endbefore do- create(:non_working_day, date: Date.current.next_occurring(:tuesday))- # set_non_working_week_days('tuesday')- # set_working_week_days('wednesday')+ set_non_working_days(next_monday.next_occurring(:tuesday))+ set_working_days(non_working_day.date)endit 'correctly handles the changes' do- job.perform_now(user_id: user.id, previous_non_working_days:)+ subjectexpect_schedule(WorkPackage.all, <<~CHART)days | MTWTFSS |predecessor | X░ ░░ |@@ -791,14 +810,18 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dopredecessor | X▓X ░░ | working days work weekfollower | ░ XXX | working days include weekends, follows predecessorCHART- let(:work_week) { set_work_week('monday', 'tuesday', 'thursday', 'friday') }++ let(:non_working_day) { create(:non_working_day, date: next_monday.next_occurring(:wednesday)) }+ let!(:previous_non_working_days) do+ week_with_saturday_and_sunday_as_non_working_day + [non_working_day.date]+ endbefore do- set_working_week_days('wednesday')+ set_working_days(non_working_day.date)endit 'does not move the follower backwards' do- job.perform_now(user_id: user.id, previous_non_working_days:)+ subjectexpect_schedule(WorkPackage.all, <<~CHART)days | MTWTFSS |@@ -814,7 +837,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dolet(:unchanged_work_packages) do[follower]end- let(:journal_notice) { "**Working days** changed (Wednesday is now working)." }+ let(:journal_notice) { "**Working days** changed (#{next_monday.next_occurring(:wednesday)} is now working)." }endend@@ -824,14 +847,18 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dopredecessor | XX░ ░░ |follower | ░XX░░ | follows predecessorCHART- let(:work_week) { set_work_week('monday', 'tuesday', 'thursday', 'friday') }++ let(:non_working_day) { create(:non_working_day, date: next_monday.next_occurring(:wednesday)) }+ let!(:previous_non_working_days) do+ week_with_saturday_and_sunday_as_non_working_day + [non_working_day.date]+ endbefore do- set_working_week_days('wednesday')+ set_working_days(non_working_day.date)endit 'does not move the follower' do- job.perform_now(user_id: user.id, previous_non_working_days:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |predecessor | XX |@@ -853,11 +880,11 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doCHARTbefore do- set_non_working_week_days('wednesday')+ set_non_working_days(next_monday.next_occurring(:wednesday))endit 'does not move any dates' do- job.perform_now(user_id: user.id, previous_non_working_days:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSS |work_package | XXXX ░░ |@@ -878,11 +905,11 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob doCHARTbefore do- set_non_working_week_days('wednesday')+ set_non_working_days(next_monday.next_occurring(:wednesday))endit 'does not change anything' do- job.perform_now(user_id: user.id, previous_non_working_days:)+ subjectexpect(work_package.duration).to eq(3)end@@ -901,12 +928,22 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dowp3 | XXX ░░ |CHART+ let(:non_working_days) do+ [+ next_monday.next_occurring(:tuesday), next_monday.next_occurring(:wednesday),+ next_monday.next_occurring(:friday), next_monday.next_occurring(:tuesday) + 1.week,+ next_monday.next_occurring(:wednesday) + 1.week, next_monday.next_occurring(:friday) + 1.week,+ next_monday.next_occurring(:tuesday) + 2.weeks, next_monday.next_occurring(:wednesday) + 2.weeks,+ next_monday.next_occurring(:friday) + 2.weeks+ ]+ end+before do- set_non_working_week_days('tuesday', 'wednesday', 'friday')+ set_non_working_days(*non_working_days)endit 'updates them only once most of the time' do- expect { job.perform_now(user_id: user.id, previous_non_working_days:) }+ expect { subject }.to change { WorkPackage.pluck(:lock_version) }.from([0, 0, 0]).to([1, 1, 1])@@ -923,7 +960,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do[wp1, wp2, wp3]endlet(:journal_notice) do- "**Working days** changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."+ "**Working days** changed (#{non_working_days.map { |day| "#{day} is now non-working" }.join(', ')})."endendend@@ -944,12 +981,20 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dowp3 | X░░ | follows wp1, follows wp2CHART+ let(:non_working_days) do+ [+ next_monday.next_occurring(:tuesday), next_monday.next_occurring(:wednesday),+ next_monday.next_occurring(:friday), next_monday.next_occurring(:tuesday) + 1.week,+ next_monday.next_occurring(:wednesday) + 1.week, next_monday.next_occurring(:friday) + 1.week+ ]+ end+before do- set_non_working_week_days('tuesday', 'wednesday', 'friday')+ set_non_working_days(*non_working_days)endit 'can update some followers twice sometimes' do- expect { job.perform_now(user_id: user.id, previous_non_working_days:) }+ expect { subject }.to change { WorkPackage.order(:subject).pluck(:lock_version) }.from([0, 0, 0]).to([1, 1, 2])@@ -966,7 +1011,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do[wp1, wp2, wp3]endlet(:journal_notice) do- "**Working days** changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."+ "**Working days** changed (#{non_working_days.map { |day| "#{day} is now non-working" }.join(', ')})."endendend@@ -979,14 +1024,26 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dowp3 | X▓▓X▓▓▓X░░ ░░░ ░░ ░░░ |CHART- let(:work_week) { set_work_week('monday', 'thursday') }+ let(:non_working_days) do+ [+ next_monday.next_occurring(:tuesday), next_monday.next_occurring(:wednesday),+ next_monday.next_occurring(:friday), next_monday.next_occurring(:tuesday) + 1.week,+ next_monday.next_occurring(:wednesday) + 1.week, next_monday.next_occurring(:friday) + 1.week,+ next_monday.next_occurring(:tuesday) + 2.weeks, next_monday.next_occurring(:wednesday) + 2.weeks,+ next_monday.next_occurring(:friday) + 2.weeks+ ]+ end+ let!(:previous_non_working_days) do+ week_with_saturday_and_sunday_as_non_working_day ++ set_non_working_days(*non_working_days).pluck(:date)+ endbefore do- set_working_week_days('tuesday', 'wednesday', 'friday')+ set_working_days(*non_working_days)endit 'keeps the same start dates and updates them only once' do- job.perform_now(user_id: user.id, previous_non_working_days:)+ subjectexpect(WorkPackage.all).to match_schedule(<<~CHART)days | MTWTFSSmtwtfssmtwtfss |wp1 | ░░ ░░XXX ░░ | follows wp2@@ -1004,7 +1061,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do[wp2]endlet(:journal_notice) do- "**Working days** changed (Tuesday is now working, Wednesday is now working, Friday is now working)."+ "**Working days** changed (#{non_working_days.map { |day| "#{day} is now working" }.join(', ')})."endendend@@ -1017,12 +1074,22 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dowp3 | ] ░░ |CHART+ let(:non_working_days) do+ [+ next_monday.next_occurring(:tuesday), next_monday.next_occurring(:wednesday),+ next_monday.next_occurring(:friday), next_monday.next_occurring(:tuesday) + 1.week,+ next_monday.next_occurring(:wednesday) + 1.week, next_monday.next_occurring(:friday) + 1.week,+ next_monday.next_occurring(:tuesday) + 2.weeks, next_monday.next_occurring(:wednesday) + 2.weeks,+ next_monday.next_occurring(:friday) + 2.weeks+ ]+ end+before do- set_non_working_week_days('tuesday', 'wednesday', 'friday')+ set_non_working_days(*non_working_days)endit 'updates all of them correctly' do- expect { job.perform_now(user_id: user.id, previous_non_working_days:) }+ expect { subject }.to change { WorkPackage.pluck(:lock_version) }.from([0, 0, 0]).to([1, 1, 1])@@ -1039,7 +1106,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do[wp1, wp2, wp3]endlet(:journal_notice) do- "**Working days** changed (Tuesday is now non-working, Wednesday is now non-working, Friday is now non-working)."+ "**Working days** changed (#{non_working_days.map { |day| "#{day} is now non-working" }.join(', ')})."endendend@@ -1050,8 +1117,13 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dowork_package | X▓▓XX ░░ |CHART+ let(:non_working_days) do+ [monday.next_occurring(:saturday), next_monday.next_occurring(:saturday)]+ end+before do- set_working_week_days('saturday')+ # Make 'saturday' a working day+ set_working_days(*non_working_days)end# Not interested in the scheduling changes in this spec@@ -1062,8 +1134,9 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dolet(:journal_notice) doI18n.with_locale(:fr) doI18n.t(:'working_days.journal_note.changed',- changes: I18n.t(:'working_days.journal_note.days.working',- day: I18n.t('date.day_names')[6]))+ changes: non_working_days.map do |date|+ I18n.t(:'working_days.journal_note.dates.working', date:)+ end.join(", "))endendend@@ -1075,8 +1148,13 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob dowork_package | X▓▓X |CHART+ let(:non_working_days) do+ [monday.next_occurring(:sunday), next_monday.next_occurring(:sunday)]+ end+before do- set_working_week_days('Sunday')+ # Make 'sunday' a working weekday+ set_working_days(*non_working_days)end# Not interested in the scheduling changes in this spec@@ -1085,7 +1163,10 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do[work_package]endlet(:journal_notice) do- "**Working days** changed (Sunday is now working)."+ I18n.t(:'working_days.journal_note.changed',+ changes: non_working_days.map do |date|+ I18n.t(:'working_days.journal_note.dates.working', date:)+ end.join(", "))endendend