diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/migrations/20210218040814_add_environment_scope_to_group_variables_spec.rb | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) | |
download | gitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/migrations/20210218040814_add_environment_scope_to_group_variables_spec.rb')
-rw-r--r-- | spec/migrations/20210218040814_add_environment_scope_to_group_variables_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/migrations/20210218040814_add_environment_scope_to_group_variables_spec.rb b/spec/migrations/20210218040814_add_environment_scope_to_group_variables_spec.rb new file mode 100644 index 00000000000..e525101f3a0 --- /dev/null +++ b/spec/migrations/20210218040814_add_environment_scope_to_group_variables_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration!('add_environment_scope_to_group_variables') + +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 |