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

convert_to_bigint_spec.rb « migration_helpers « database « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1ff157b51d4954b4afcee66b84e8992905e51252 (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
66
67
68
69
70
71
72
73
74
75
76
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Database::MigrationHelpers::ConvertToBigint, feature_category: :database do
  let(:migration) do
    Class
      .new
      .include(described_class)
      .include(Gitlab::Database::MigrationHelpers)
      .new
  end

  describe '#com_or_dev_or_test_but_not_jh?' do
    using RSpec::Parameterized::TableSyntax

    where(:dot_com, :dev_or_test, :jh, :expectation) do
      true  | true  | true  | true
      true  | false | true  | false
      false | true  | true  | true
      false | false | true  | false
      true  | true  | false | true
      true  | false | false | true
      false | true  | false | true
      false | false | false | false
    end

    with_them do
      it 'returns true for GitLab.com (but not JH), dev, or test' do
        allow(Gitlab).to receive(:com?).and_return(dot_com)
        allow(Gitlab).to receive(:dev_or_test_env?).and_return(dev_or_test)
        allow(Gitlab).to receive(:jh?).and_return(jh)

        expect(migration.com_or_dev_or_test_but_not_jh?).to eq(expectation)
      end
    end
  end

  describe '#temp_column_removed?' do
    it 'return true when column is not present' do
      expect(migration).to receive(:column_exists?).with('test_table', 'id_convert_to_bigint').and_return(false)

      expect(migration.temp_column_removed?(:test_table, :id)).to eq(true)
    end

    it 'return false when column present' do
      expect(migration).to receive(:column_exists?).with('test_table', 'id_convert_to_bigint').and_return(true)

      expect(migration.temp_column_removed?(:test_table, :id)).to eq(false)
    end
  end

  describe '#columns_swapped?' do
    it 'returns true if columns are already swapped' do
      columns = [
        Struct.new(:name, :sql_type).new('id', 'bigint'),
        Struct.new(:name, :sql_type).new('id_convert_to_bigint', 'integer')
      ]

      expect(migration).to receive(:columns).with('test_table').and_return(columns)

      expect(migration.columns_swapped?(:test_table, :id)).to eq(true)
    end

    it 'returns false if columns are not yet swapped' do
      columns = [
        Struct.new(:name, :sql_type).new('id', 'integer'),
        Struct.new(:name, :sql_type).new('id_convert_to_bigint', 'bigint')
      ]

      expect(migration).to receive(:columns).with('test_table').and_return(columns)

      expect(migration.columns_swapped?(:test_table, :id)).to eq(false)
    end
  end
end