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

trigger_validators_shared_examples.rb « shared_examples « support « spec « gitlab-schema-validation « gems - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 45ed87082bbd43d51e8b2e8c60d5de381a7752b1 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.shared_examples 'trigger validators' do |validator, expected_result|
  subject(:result) { validator.new(structure_file, database).execute }

  let(:structure_file_path) { 'spec/fixtures/structure.sql' }
  let(:structure_file) { Gitlab::Schema::Validation::Sources::StructureSql.new(structure_file_path, schema) }
  let(:inconsistency_type) { validator.to_s }
  let(:database_name) { 'main' }
  let(:schema) { 'public' }
  let(:database) { Gitlab::Schema::Validation::Sources::Database.new(connection) }

  # rubocop:disable RSpec/VerifiedDoubleReference
  let(:connection) { instance_double('connection', select_rows: database_triggers, current_schema: 'public') }
  # rubocop:enable RSpec/VerifiedDoubleReference

  let(:database_triggers) do
    [
      ['trigger', 'CREATE TRIGGER trigger AFTER INSERT ON public.t1 FOR EACH ROW EXECUTE FUNCTION t1()'],
      ['wrong_trigger', 'CREATE TRIGGER wrong_trigger BEFORE UPDATE ON public.t2 FOR EACH ROW EXECUTE FUNCTION t2()'],
      ['extra_trigger', 'CREATE TRIGGER extra_trigger BEFORE INSERT ON public.t4 FOR EACH ROW EXECUTE FUNCTION t4()']
    ]
  end

  it 'returns trigger inconsistencies' do
    expect(result.map(&:object_name)).to match_array(expected_result)
    expect(result.map(&:type)).to all(eql inconsistency_type)
  end
end