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 the Settings::WorkingDaysUpdateService to schedule the WorkPackages::ApplyWorkingDaysChangeJob on a successful settings change
Dombi Attilab0c02dced7a8
diff --git a/app/services/settings/working_days_update_service.rb b/app/services/settings/working_days_update_service.rbindex dfc94ca927f..ccf314964a5 100644--- a/app/services/settings/working_days_update_service.rb+++ b/app/services/settings/working_days_update_service.rb@@ -30,6 +30,8 @@ class Settings::WorkingDaysUpdateService < Settings::UpdateServicedef call(params)params = params.to_h.deep_symbolize_keysself.non_working_days_params = params.delete(:non_working_days) || []+ self.previous_working_days = Setting[:working_days]+ self.previous_non_working_days = NonWorkingDay.pluck(:date)superend@@ -54,9 +56,19 @@ class Settings::WorkingDaysUpdateService < Settings::UpdateServiceresultsend+ def after_perform(call)+ super.tap do+ WorkPackages::ApplyWorkingDaysChangeJob.perform_later(+ user_id: User.current.id,+ previous_working_days:,+ previous_non_working_days:+ )+ end+ end+private- attr_accessor :non_working_days_params+ attr_accessor :non_working_days_params, :previous_working_days, :previous_non_working_daysdef persist_non_working_days# We don't support update for nowdiff --git a/spec/services/settings/working_days_update_service_spec.rb b/spec/services/settings/working_days_update_service_spec.rbindex 6ced425dab7..3878e0ca666 100644--- a/spec/services/settings/working_days_update_service_spec.rb+++ b/spec/services/settings/working_days_update_service_spec.rb@@ -74,15 +74,39 @@ describe Settings::WorkingDaysUpdateService dodescribe '#call' dosubject { instance.call(params) }+ shared_examples 'successful working days settings call' do+ include_examples 'successful call'++ it 'calls the WorkPackages::ApplyWorkingDaysChangeJob' do+ previous_working_days = Setting[:working_days]+ previous_non_working_days = NonWorkingDay.pluck(:date)++ allow(WorkPackages::ApplyWorkingDaysChangeJob).to receive(:perform_later)++ subject++ expect(WorkPackages::ApplyWorkingDaysChangeJob)+ .to have_received(:perform_later)+ .with(user_id: user.id, previous_working_days:, previous_non_working_days:)+ end+ end+shared_examples 'unsuccessful working days settings call' doinclude_examples 'unsuccessful call'it 'does not persists the non working days' doexpect { subject }.not_to change(NonWorkingDay, :count)end++ it 'does not calls the WorkPackages::ApplyWorkingDaysChangeJob' do+ allow(WorkPackages::ApplyWorkingDaysChangeJob).to receive(:perform_later)+ subject++ expect(WorkPackages::ApplyWorkingDaysChangeJob).not_to have_received(:perform_later)+ endend- include_examples 'successful call'+ include_examples 'successful working days settings call'context 'when non working days are present' dolet!(:existing_nwd) { create(:non_working_day, name: 'Existing NWD') }@@ -96,7 +120,7 @@ describe Settings::WorkingDaysUpdateService do]end- include_examples 'successful call'+ include_examples 'successful working days settings call'it 'persists (create/delete) the non working days' doexpect { subject }.to change(NonWorkingDay, :count).by(1)@@ -137,7 +161,7 @@ describe Settings::WorkingDaysUpdateService do]end- include_examples 'successful call'+ include_examples 'successful working days settings call'it 'persists (create/delete) the non working days' doexpect { subject }.not_to change(NonWorkingDay, :count)