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

20220128155814_fix_approval_rules_code_owners_rule_type_index_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1558facdf96d736a05478101bacbdade3243eb68 (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
27
28
29
30
31
32
33
# frozen_string_literal: true

require 'spec_helper'
require_migration!('fix_approval_rules_code_owners_rule_type_index')

RSpec.describe FixApprovalRulesCodeOwnersRuleTypeIndex, :migration do
  let(:table_name) { :approval_merge_request_rules }
  let(:index_name) { 'index_approval_rules_code_owners_rule_type' }

  it 'correctly migrates up and down' do
    reversible_migration do |migration|
      migration.before -> {
        expect(subject.index_exists_by_name?(table_name, index_name)).to be_truthy
      }

      migration.after -> {
        expect(subject.index_exists_by_name?(table_name, index_name)).to be_truthy
      }
    end
  end

  context 'when the index already exists' do
    before do
      subject.add_concurrent_index table_name, :merge_request_id, where: 'rule_type = 2', name: index_name
    end

    it 'keeps the index' do
      migrate!

      expect(subject.index_exists_by_name?(table_name, index_name)).to be_truthy
    end
  end
end