Welcome to mirror list, hosted at ThFree Co, Russian Federation.

remove_orphan_service_hooks_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 71e70daf1e64799aec12662ec33127e46bb75152 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

require 'spec_helper'

require_migration!
require_migration!('add_web_hooks_service_foreign_key')

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