Fixed issue #2541 - Existing scheduler email notification without body
will raise an exception.
This commit is contained in:
parent
9a0df2729b
commit
668e272cfd
2 changed files with 90 additions and 0 deletions
|
@ -0,0 +1,29 @@
|
||||||
|
class Issue2541FixNotificationEmailWithoutBody < ActiveRecord::Migration[5.1]
|
||||||
|
def up
|
||||||
|
|
||||||
|
# return if it's a new setup
|
||||||
|
return if !Setting.find_by(name: 'system_init_done')
|
||||||
|
|
||||||
|
# update jobs and triggers
|
||||||
|
[::Job, ::Trigger].each do |model|
|
||||||
|
model.all.each do |record|
|
||||||
|
next if record.perform.blank?
|
||||||
|
|
||||||
|
%w[notification.email notification.sms].each do |action|
|
||||||
|
next if record.perform[action].blank?
|
||||||
|
next if record.perform[action]['body'].present?
|
||||||
|
|
||||||
|
record.perform[action]['body'] = '-'
|
||||||
|
record.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# re-enable jobs again
|
||||||
|
scheduler = Scheduler.find_by(method: 'Job.run')
|
||||||
|
return if !scheduler
|
||||||
|
return if scheduler.active?
|
||||||
|
|
||||||
|
scheduler.update!(active: true)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,61 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Issue2541FixNotificationEmailWithoutBody, type: :db_migration do
|
||||||
|
|
||||||
|
context 'when migrating Triggers' do
|
||||||
|
|
||||||
|
before(:all) { Trigger.skip_callback(:create, :before, :validate_perform) }
|
||||||
|
|
||||||
|
it "updates empty perform['notification.email']['body'] attribute" do
|
||||||
|
trigger = create(:trigger,
|
||||||
|
perform: {
|
||||||
|
'notification.email' => {
|
||||||
|
'body' => '',
|
||||||
|
'recipient' => 'article_last_sender',
|
||||||
|
'subject' => 'Thanks for your inquiry (#{ticket.title})', # rubocop:disable Lint/InterpolationCheck
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect { migrate }.to change { trigger.reload.perform['notification.email']['body'] }.from('').to('-')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "updates empty perform['notification.sms']['body'] attribute" do
|
||||||
|
trigger = create(:trigger,
|
||||||
|
perform: {
|
||||||
|
'notification.sms' => {
|
||||||
|
'body' => '',
|
||||||
|
'recipient' => 'article_last_sender',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect { migrate }.to change { trigger.reload.perform['notification.sms']['body'] }.from('').to('-')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when migrating Jobs' do
|
||||||
|
|
||||||
|
before(:all) { Job.skip_callback(:create, :before, :validate_perform) }
|
||||||
|
|
||||||
|
it "updates empty perform['notification.email']['body'] attribute" do
|
||||||
|
|
||||||
|
job = create(:job,
|
||||||
|
perform: {
|
||||||
|
'notification.email' => {
|
||||||
|
'body' => '',
|
||||||
|
'recipient' => 'article_last_sender',
|
||||||
|
'subject' => 'Thanks for your inquiry (#{ticket.title})', # rubocop:disable Lint/InterpolationCheck
|
||||||
|
},
|
||||||
|
},)
|
||||||
|
|
||||||
|
expect { migrate }.to change { job.reload.perform['notification.email']['body'] }.from('').to('-')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "re-enables 'Job.run' Scheduler" do
|
||||||
|
scheduler = Scheduler.find_by(method: 'Job.run')
|
||||||
|
scheduler.update!(active: false)
|
||||||
|
|
||||||
|
expect { migrate }.to change { scheduler.reload.active }.to(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in a new issue