summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/lib/gitlab/migration_helpers_shared_examples.rb
blob: 8893ed5504be6a0af764ef4f90f4134443d01786 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

RSpec.shared_examples 'skips validation' do |validation_option|
  it 'skips validation' do
    expect(model).not_to receive(:disable_statement_timeout)
    expect(model).to receive(:execute).with(/ADD CONSTRAINT/)
    expect(model).not_to receive(:execute).with(/VALIDATE CONSTRAINT/)

    model.add_concurrent_foreign_key(*args, **options.merge(validation_option))
  end
end

RSpec.shared_examples 'performs validation' do |validation_option|
  it 'performs validation' do
    expect(model).to receive(:disable_statement_timeout).and_call_original
    expect(model).to receive(:execute).with(/statement_timeout/)
    expect(model).to receive(:execute).ordered.with(/NOT VALID/)
    expect(model).to receive(:execute).ordered.with(/VALIDATE CONSTRAINT/)
    expect(model).to receive(:execute).with(/RESET ALL/)

    model.add_concurrent_foreign_key(*args, **options.merge(validation_option))
  end
end