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

trigger working days update job after setting change - dirty

ulferts3e3df2e80dcd
diff --git a/app/services/settings/update_service.rb b/app/services/settings/update_service.rb
index 8821cb0a4bb..4ee8c20efde 100644
--- a/app/services/settings/update_service.rb
+++ b/app/services/settings/update_service.rb
@@ -49,6 +49,11 @@ class Settings::UpdateService < ::BaseServices::BaseContracted
Setting[name] = derive_value(value)
end
+ if params.has_key?(:working_days)
+ WorkPackages::ApplyWorkingDaysChangeJob
+ .perform_later(user_id: user.id)
+ end
+
call
end
diff --git a/spec/features/admin/working_days_spec.rb b/spec/features/admin/working_days_spec.rb
index 75e37e591a6..f60809525e7 100644
--- a/spec/features/admin/working_days_spec.rb
+++ b/spec/features/admin/working_days_spec.rb
@@ -31,13 +31,20 @@ require 'spec_helper'
describe 'Working Days', type: :feature, js: true do
shared_let(:week_days) { week_with_saturday_and_sunday_as_weekend }
shared_let(:admin) { create :admin }
+ shared_let(:work_package) { create :work_package, start_date: Date.parse('2022-09-19'), due_date: Date.parse('2022-09-23') }
let(:dialog) { ::Components::ConfirmationDialog.new }
+ current_user { admin }
+
before do
- login_as(admin)
visit admin_settings_working_days_path
end
+ # Using this way instead of Setting.working_days as that is cached.
+ def working_days_setting
+ Setting.find_by(name: :working_days).value
+ end
+
it 'contains all defined days from the settings' do
WeekDay.all.each do |day|
expect(page).to have_selector('label', text: day.name)
@@ -48,26 +55,39 @@ describe 'Working Days', type: :feature, js: true do
end
it 'rejects the updates when cancelling the dialog' do
- expect(Setting.working_days).to eq([1, 2, 3, 4, 5])
+ expect(working_days_setting).to eq([1, 2, 3, 4, 5])
+
uncheck 'Monday'
uncheck 'Friday'
click_on 'Save'
- dialog.cancel
+ perform_enqueued_jobs do
+ dialog.cancel
+ end
+
expect(page).to have_no_selector('.flash.notice')
- expect(Setting.working_days).to eq([1, 2, 3, 4, 5])
+ expect(working_days_setting).to eq([1, 2, 3, 4, 5])
+
+ expect(work_package.reload.start_date)
+ .to eql(Date.parse('2022-09-19'))
+
+ expect(work_package.due_date)
+ .to eql(Date.parse('2022-09-23'))
end
it 'updates the values and saves the settings' do
- expect(Setting.working_days).to eq([1, 2, 3, 4, 5])
+ expect(working_days_setting).to eq([1, 2, 3, 4, 5])
+
uncheck 'Monday'
uncheck 'Friday'
click_on 'Save'
- dialog.confirm
+ perform_enqueued_jobs do
+ dialog.confirm
+ end
expect(page).to have_selector('.flash.notice', text: 'Successful update.')
expect(page).to have_unchecked_field 'Monday'
@@ -78,11 +98,16 @@ describe 'Working Days', type: :feature, js: true do
expect(page).to have_checked_field 'Wednesday'
expect(page).to have_checked_field 'Thursday'
- RequestStore.clear!
- expect(Setting.working_days).to eq([2, 3, 4])
+ expect(working_days_setting).to eq([2, 3, 4])
+
+ expect(work_package.reload.start_date)
+ .to eql(Date.parse('2022-09-20'))
+
+ expect(work_package.due_date)
+ .to eql(Date.parse('2022-09-28'))
end
- it 'shows error when no working days are set' do
+ it 'shows error when non working days are set' do
uncheck 'Monday'
uncheck 'Tuesday'
uncheck 'Wednesday'
@@ -91,7 +116,9 @@ describe 'Working Days', type: :feature, js: true do
click_on 'Save'
- dialog.confirm
+ perform_enqueued_jobs do
+ dialog.confirm
+ end
expect(page).to have_selector('.flash.error', text: 'At least one working day needs to be specified.')
# Restore the checkboxes to their valid state
@@ -102,6 +129,12 @@ describe 'Working Days', type: :feature, js: true do
expect(page).to have_checked_field 'Friday'
expect(page).to have_unchecked_field 'Saturday'
expect(page).to have_unchecked_field 'Sunday'
- expect(Setting.working_days).to eq([1, 2, 3, 4, 5])
+ expect(working_days_setting).to eq([1, 2, 3, 4, 5])
+
+ expect(work_package.reload.start_date)
+ .to eql(Date.parse('2022-09-19'))
+
+ expect(work_package.due_date)
+ .to eql(Date.parse('2022-09-23'))
end
end