Browse Source

Fixed issue #2663: DB migration blocks update when records with 'current_user.id' in selector of Job or Trigger exist.

Thorsten Eckel 5 years ago
parent
commit
3424416809

+ 4 - 0
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|

+ 16 - 0
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