From 3424416809bebb43bfd6f3f751e543fff3cc6d8b Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 12 Jul 2019 16:02:22 +0200 Subject: [PATCH] Fixed issue #2663: DB migration blocks update when records with 'current_user.id' in selector of Job or Trigger exist. --- ...e_2541_fix_notification_email_without_body.rb | 4 ++++ ...1_fix_notification_email_without_body_spec.rb | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/db/migrate/20190408000001_issue_2541_fix_notification_email_without_body.rb b/db/migrate/20190408000001_issue_2541_fix_notification_email_without_body.rb index d94f51688..a5d067ef6 100644 --- a/db/migrate/20190408000001_issue_2541_fix_notification_email_without_body.rb +++ b/db/migrate/20190408000001_issue_2541_fix_notification_email_without_body.rb @@ -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| diff --git a/spec/db/migrate/issue_2541_fix_notification_email_without_body_spec.rb b/spec/db/migrate/issue_2541_fix_notification_email_without_body_spec.rb index 244469a01..9d70b17dc 100644 --- a/spec/db/migrate/issue_2541_fix_notification_email_without_body_spec.rb +++ b/spec/db/migrate/issue_2541_fix_notification_email_without_body_spec.rb @@ -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