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

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.rb
index 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::UpdateService
def call(params)
params = params.to_h.deep_symbolize_keys
self.non_working_days_params = params.delete(:non_working_days) || []
+ self.previous_working_days = Setting[:working_days]
+ self.previous_non_working_days = NonWorkingDay.pluck(:date)
super
end
@@ -54,9 +56,19 @@ class Settings::WorkingDaysUpdateService < Settings::UpdateService
results
end
+ 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_days
def persist_non_working_days
# We don't support update for now
diff --git a/spec/services/settings/working_days_update_service_spec.rb b/spec/services/settings/working_days_update_service_spec.rb
index 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 do
describe '#call' do
subject { 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' do
include_examples 'unsuccessful call'
it 'does not persists the non working days' do
expect { 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)
+ end
end
- include_examples 'successful call'
+ include_examples 'successful working days settings call'
context 'when non working days are present' do
let!(: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' do
expect { 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' do
expect { subject }.not_to change(NonWorkingDay, :count)