summaryrefslogtreecommitdiff
path: root/spec/migrations/remove_orphan_service_hooks_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/migrations/remove_orphan_service_hooks_spec.rb')
-rw-r--r--spec/migrations/remove_orphan_service_hooks_spec.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/migrations/remove_orphan_service_hooks_spec.rb b/spec/migrations/remove_orphan_service_hooks_spec.rb
new file mode 100644
index 00000000000..c06a8b97738
--- /dev/null
+++ b/spec/migrations/remove_orphan_service_hooks_spec.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require_migration!
+require Rails.root.join('db', 'migrate', '20201119125730_add_web_hooks_service_foreign_key.rb')
+
+RSpec.describe RemoveOrphanServiceHooks, schema: 20201203123201 do
+ let(:web_hooks) { table(:web_hooks) }
+ let(:services) { table(:services) }
+
+ before do
+ services.create!
+ web_hooks.create!(service_id: services.first.id, type: 'ServiceHook')
+ web_hooks.create!(service_id: nil)
+
+ AddWebHooksServiceForeignKey.new.down
+ web_hooks.create!(service_id: non_existing_record_id, type: 'ServiceHook')
+ AddWebHooksServiceForeignKey.new.up
+ end
+
+ it 'removes service hooks where the referenced service does not exist', :aggregate_failures do
+ expect { RemoveOrphanServiceHooks.new.up }.to change { web_hooks.count }.by(-1)
+ expect(web_hooks.where.not(service_id: services.select(:id)).count).to eq(0)
+ end
+end