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

extension_helpers_spec.rb « migrations « database « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fb29e06bc01f7a635c9c76c05862bc1e16e87dc9 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Database::Migrations::ExtensionHelpers do
  let(:model) do
    ActiveRecord::Migration.new.extend(described_class)
  end

  before do
    allow(model).to receive(:puts)
  end

  describe '#create_extension' do
    subject { model.create_extension(extension) }

    let(:extension) { :btree_gist }

    it 'executes CREATE EXTENSION statement' do
      expect(model).to receive(:execute).with(/CREATE EXTENSION IF NOT EXISTS #{extension}/)

      subject
    end

    context 'without proper permissions' do
      before do
        allow(model).to receive(:execute)
          .with(/CREATE EXTENSION IF NOT EXISTS #{extension}/)
          .and_raise(ActiveRecord::StatementInvalid, 'InsufficientPrivilege: permission denied')
      end

      it 'raises an exception and prints an error message' do
        expect { subject }
          .to output(/user is not allowed/).to_stderr
          .and raise_error(ActiveRecord::StatementInvalid, /InsufficientPrivilege/)
      end
    end
  end

  describe '#drop_extension' do
    subject { model.drop_extension(extension) }

    let(:extension) { 'btree_gist' }

    it 'executes CREATE EXTENSION statement' do
      expect(model).to receive(:execute).with(/DROP EXTENSION IF EXISTS #{extension}/)

      subject
    end

    context 'without proper permissions' do
      before do
        allow(model).to receive(:execute)
          .with(/DROP EXTENSION IF EXISTS #{extension}/)
          .and_raise(ActiveRecord::StatementInvalid, 'InsufficientPrivilege: permission denied')
      end

      it 'raises an exception and prints an error message' do
        expect { subject }
          .to output(/user is not allowed/).to_stderr
          .and raise_error(ActiveRecord::StatementInvalid, /InsufficientPrivilege/)
      end
    end
  end
end