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

foreign_key_structure_sql_adapter_spec.rb « adapters « schema_validation « database « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f7ae0c0f892593f90443e9025e58a7dbdffcc495 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Database::SchemaValidation::Adapters::ForeignKeyStructureSqlAdapter, feature_category: :database do
  subject(:adapter) { described_class.new(stmt) }

  let(:stmt) { PgQuery.parse(sql).tree.stmts.first.stmt.alter_table_stmt }

  where(:sql, :name, :table_name, :statement) do
    [
      [
        'ALTER TABLE ONLY public.issues ADD CONSTRAINT fk_05f1e72feb FOREIGN KEY (author_id) REFERENCES users (id) ' \
        'ON DELETE SET NULL',
        'public.fk_05f1e72feb',
        'issues',
        'FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL'
      ],
      [
        'ALTER TABLE public.import_failures ADD CONSTRAINT fk_9a9b9ba21c FOREIGN KEY (user_id) REFERENCES users(id) ' \
        'ON DELETE CASCADE',
        'public.fk_9a9b9ba21c',
        'import_failures',
        'FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE'
      ]
    ]
  end

  with_them do
    describe '#name' do
      it { expect(adapter.name).to eq(name) }
    end

    describe '#table_name' do
      it { expect(adapter.table_name).to eq(table_name) }
    end

    describe '#statement' do
      it { expect(adapter.statement).to eq(statement) }
    end
  end
end