Fixed issue #2663: DB migration blocks update when records with 'current_user.id' in selector of Job or Trigger exist.
This commit is contained in:
parent
b361c422f8
commit
3424416809
2 changed files with 20 additions and 0 deletions
|
@ -4,6 +4,10 @@ class Issue2541FixNotificationEmailWithoutBody < ActiveRecord::Migration[5.1]
|
|||
# return if it's a new setup
|
||||
return if !Setting.find_by(name: 'system_init_done')
|
||||
|
||||
# there might be Job/Trigger selectors referencing the current user
|
||||
# that get e.g. validated in callbacks
|
||||
UserInfo.current_user_id = 1
|
||||
|
||||
# update jobs and triggers
|
||||
[::Job, ::Trigger].each do |model|
|
||||
model.where(active: true).each do |record|
|
||||
|
|
|
@ -44,7 +44,23 @@ RSpec.describe Issue2541FixNotificationEmailWithoutBody, type: :db_migration do
|
|||
it "updates empty perform['notification.email']['body'] attribute" do
|
||||
expect { migrate }.to change { job.reload.perform['notification.email']['body'] }.from('').to('-')
|
||||
end
|
||||
|
||||
context 'when selector contains current_user.id' do
|
||||
subject(:job) do
|
||||
UserInfo.ensure_current_user_id do
|
||||
|
||||
create(:job, condition: { 'ticket.owner_id' => { 'operator' => 'is', 'pre_condition' => 'current_user.id', 'value' => '', 'value_completion' => '' } } )
|
||||
end
|
||||
end
|
||||
|
||||
let(:type) { 'notification.email' }
|
||||
|
||||
it "updates empty perform['notification.email']['body'] attribute" do
|
||||
expect { migrate }.to change { job.reload.perform['notification.email']['body'] }.from('').to('-')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'scheduler management' do
|
||||
|
|
Loading…
Reference in a new issue