From e64c2f3c9d3adb46caf51c146335b47532d67fbb Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Wed, 18 Jul 2018 15:30:50 +0800 Subject: [PATCH] Add spec for #2019 migration (and fix Trigger factory) --- ...x_double_domain_links_in_trigger_emails.rb | 2 ++ ...ble_domain_links_in_trigger_emails_spec.rb | 22 +++++++++++++++++++ spec/factories/trigger.rb | 10 +++++++++ 3 files changed, 34 insertions(+) create mode 100644 spec/db/migrate/issue_2019_fix_double_domain_links_in_trigger_emails_spec.rb create mode 100644 spec/factories/trigger.rb diff --git a/db/migrate/20180716060129_issue_2019_fix_double_domain_links_in_trigger_emails.rb b/db/migrate/20180716060129_issue_2019_fix_double_domain_links_in_trigger_emails.rb index c3386c545..a02c73a45 100644 --- a/db/migrate/20180716060129_issue_2019_fix_double_domain_links_in_trigger_emails.rb +++ b/db/migrate/20180716060129_issue_2019_fix_double_domain_links_in_trigger_emails.rb @@ -2,6 +2,8 @@ class Issue2019FixDoubleDomainLinksInTriggerEmails < ActiveRecord::Migration[5.1 DOUBLE_DOMAIN_REGEX = %r{(?<=)} 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'] diff --git a/spec/db/migrate/issue_2019_fix_double_domain_links_in_trigger_emails_spec.rb b/spec/db/migrate/issue_2019_fix_double_domain_links_in_trigger_emails_spec.rb new file mode 100644 index 000000000..4bbb95c68 --- /dev/null +++ b/spec/db/migrate/issue_2019_fix_double_domain_links_in_trigger_emails_spec.rb @@ -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 + '' \ + 'View ticket' \ + '' + end + + let(:fixed_link) do + '' \ + 'View ticket' \ + '' + 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 diff --git a/spec/factories/trigger.rb b/spec/factories/trigger.rb new file mode 100644 index 000000000..395f1aeba --- /dev/null +++ b/spec/factories/trigger.rb @@ -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