Add spec for #2019 migration (and fix Trigger factory)
This commit is contained in:
parent
0b39137cd7
commit
e64c2f3c9d
3 changed files with 34 additions and 0 deletions
|
@ -2,6 +2,8 @@ class Issue2019FixDoubleDomainLinksInTriggerEmails < ActiveRecord::Migration[5.1
|
|||
DOUBLE_DOMAIN_REGEX = %r{(?<=<a href=")https?://[^"]+(?=(https?|\#{config\.http_type})://.+?".*?>)}
|
||||
|
||||
def up
|
||||
return if !Setting.find_by(name: 'system_init_done')
|
||||
|
||||
Trigger.where('perform LIKE ?', '%notification.email: %')
|
||||
.find_each do |t|
|
||||
email_response = t.perform['notification.email']
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Issue2019FixDoubleDomainLinksInTriggerEmails, type: :db_migration do
|
||||
subject { create(:trigger, perform: { 'notification.email' => { 'body' => faulty_link } }) }
|
||||
|
||||
let(:faulty_link) do
|
||||
'<a href="https://example.com/#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">' \
|
||||
'View ticket' \
|
||||
'</a>'
|
||||
end
|
||||
|
||||
let(:fixed_link) do
|
||||
'<a href="#{config.http_type}://#{config.fqdn}/#ticket/zoom/#{ticket.id}">' \
|
||||
'View ticket' \
|
||||
'</a>'
|
||||
end
|
||||
|
||||
it "removes duplicate domains from Trigger records' notification.email bodies" do
|
||||
expect { migrate }.to change { subject.reload.perform['notification.email']['body'] }
|
||||
.from(faulty_link).to(fixed_link)
|
||||
end
|
||||
end
|
10
spec/factories/trigger.rb
Normal file
10
spec/factories/trigger.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
FactoryBot.define do
|
||||
factory :trigger do
|
||||
sequence(:name) { |n| "Test trigger #{n}" }
|
||||
condition { { 'ticket.state_id' => { 'operator' => 'is not', 'value' => 4 } } }
|
||||
perform { { 'ticket.state_id' => { 'value' => 4 } } }
|
||||
active true
|
||||
created_by_id 1
|
||||
updated_by_id 1
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue