blob: 5203e772d158c152013aeccb35718c6b74c67de9 (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# frozen_string_literal: true
require "spec_helper"
require_migration!
RSpec.describe AddTmpPartialIndexOnVulnerabilityReportTypes2, feature_category: :vulnerability_management do
let(:async_index) { Gitlab::Database::AsyncIndexes::PostgresAsyncIndex }
let(:index_name) { described_class::INDEX_NAME }
before do
allow_any_instance_of(ActiveRecord::ConnectionAdapters::SchemaStatements) # rubocop:disable RSpec/AnyInstanceOf
.to receive(:index_exists?)
.with("vulnerability_occurrences", :id, hash_including(name: index_name))
.and_return(index_exists)
end
context "with index absent" do
let(:index_exists) { false }
it "schedules the index" do
reversible_migration do |migration|
migration.before -> do
expect(async_index.where(name: index_name).count).to be(0)
end
migration.after -> do
expect(async_index.where(name: index_name).count).to be(1)
end
end
end
end
context "with index present" do
let(:index_exists) { true }
it "does not schedule the index" do
reversible_migration do |migration|
migration.before -> do
expect(async_index.where(name: index_name).count).to be(0)
end
migration.after -> do
expect(async_index.where(name: index_name).count).to be(0)
end
end
end
end
end
|