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

20210218040814_add_environment_scope_to_group_variables_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 039ce53cac47960cbf881edf6b31c562d3c0d70c (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
# frozen_string_literal: true

require 'spec_helper'
require_migration!

RSpec.describe AddEnvironmentScopeToGroupVariables do
  let(:migration) { described_class.new }
  let(:ci_group_variables) { table(:ci_group_variables) }
  let(:group) { table(:namespaces).create!(name: 'group', path: 'group') }

  def create_variable!(group, key:, environment_scope: '*')
    table(:ci_group_variables).create!(
      group_id: group.id,
      key: key,
      environment_scope: environment_scope
    )
  end

  describe '#down' do
    context 'group has variables with duplicate keys' do
      it 'deletes all but the first record' do
        migration.up

        remaining_variable = create_variable!(group, key: 'key')
        create_variable!(group, key: 'key', environment_scope: 'staging')
        create_variable!(group, key: 'key', environment_scope: 'production')

        migration.down

        expect(ci_group_variables.pluck(:id)).to eq [remaining_variable.id]
      end
    end

    context 'group does not have variables with duplicate keys' do
      it 'does not delete any records' do
        migration.up

        create_variable!(group, key: 'key')
        create_variable!(group, key: 'staging')
        create_variable!(group, key: 'production')

        expect { migration.down }.not_to change { ci_group_variables.count }
      end
    end
  end
end