Fix Issue 2541 migration spec (prevent leaky test setup)
This commit is contained in:
parent
00934ef4f4
commit
cdf4eaf92a
1 changed files with 43 additions and 47 deletions
|
@ -1,61 +1,57 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Issue2541FixNotificationEmailWithoutBody, type: :db_migration do
|
RSpec.describe Issue2541FixNotificationEmailWithoutBody, type: :db_migration do
|
||||||
|
describe '"body" attribute management' do
|
||||||
|
# We use #update_columns to bypass callbacks
|
||||||
|
# that would prevent the record from being saved with an empty body
|
||||||
|
before { subject.update_columns(perform: perform) }
|
||||||
|
|
||||||
context 'when migrating Triggers' do
|
let(:perform) do
|
||||||
|
{
|
||||||
before(:all) { Trigger.skip_callback(:create, :before, :validate_perform) }
|
type => {
|
||||||
|
'body' => '',
|
||||||
it "updates empty perform['notification.email']['body'] attribute" do
|
'recipient' => 'article_last_sender',
|
||||||
trigger = create(:trigger,
|
'subject' => 'Thanks for your inquiry (#{ticket.title})', # rubocop:disable Lint/InterpolationCheck
|
||||||
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
|
end
|
||||||
|
|
||||||
it "updates empty perform['notification.sms']['body'] attribute" do
|
context 'when migrating Triggers' do
|
||||||
trigger = create(:trigger,
|
subject(:trigger) { create(:trigger) }
|
||||||
perform: {
|
|
||||||
'notification.sms' => {
|
|
||||||
'body' => '',
|
|
||||||
'recipient' => 'article_last_sender',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
expect { migrate }.to change { trigger.reload.perform['notification.sms']['body'] }.from('').to('-')
|
context 'for email' do
|
||||||
|
let(:type) { 'notification.email' }
|
||||||
|
|
||||||
|
it "updates empty perform['notification.email']['body'] attribute" do
|
||||||
|
expect { migrate }.to change { trigger.reload.perform['notification.email']['body'] }.from('').to('-')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'for SMS' do
|
||||||
|
let(:type) { 'notification.sms' }
|
||||||
|
|
||||||
|
it "updates empty perform['notification.sms']['body'] attribute" do
|
||||||
|
expect { migrate }.to change { trigger.reload.perform['notification.sms']['body'] }.from('').to('-')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when migrating Jobs' do
|
||||||
|
subject(:job) { create(:job) }
|
||||||
|
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
|
end
|
||||||
|
|
||||||
context 'when migrating Jobs' do
|
describe 'scheduler management' do
|
||||||
|
let(:scheduler) { Scheduler.find_by(method: 'Job.run') }
|
||||||
|
before { scheduler.update!(active: false) }
|
||||||
|
|
||||||
before(:all) { Job.skip_callback(:create, :before, :validate_perform) }
|
it "re-enables 'Job.run' Scheduler" do
|
||||||
|
expect { migrate }.to change { scheduler.reload.active }.to(true)
|
||||||
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
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue