diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-10 10:53:40 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-10 10:53:40 +0300 |
commit | cfc792b9ca064990e6540cb742e80529ea669a81 (patch) | |
tree | 147cd4256319990cebbc02fe8e4fbbbe06f5720a /spec/migrations | |
parent | 93c6764dacd4c605027ef1cd367d3aebe420b223 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/migrate_ops_feature_flags_scopes_target_user_ids_spec.rb | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/spec/migrations/migrate_ops_feature_flags_scopes_target_user_ids_spec.rb b/spec/migrations/migrate_ops_feature_flags_scopes_target_user_ids_spec.rb new file mode 100644 index 00000000000..5f865579c96 --- /dev/null +++ b/spec/migrations/migrate_ops_feature_flags_scopes_target_user_ids_spec.rb @@ -0,0 +1,137 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20191118211629_migrate_ops_feature_flags_scopes_target_user_ids.rb') + +describe MigrateOpsFeatureFlagsScopesTargetUserIds, :migration do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:flags) { table(:operations_feature_flags) } + let(:scopes) { table(:operations_feature_flag_scopes) } + + def setup + namespace = namespaces.create!(name: 'foo', path: 'foo') + project = projects.create!(namespace_id: namespace.id) + flag = flags.create!(project_id: project.id, active: true, name: 'test_flag') + + flag + end + + it 'migrates successfully when there are no scopes in the database' do + setup + + disable_migrations_output { migrate! } + + expect(scopes.count).to eq(0) + end + + it 'migrates a disabled scope with gradualRolloutUserId and userWithId strategies' do + flag = setup + scope = scopes.create!(feature_flag_id: flag.id, active: false, strategies: [ + { name: 'gradualRolloutUserId', parameters: { groupId: 'default', percentage: '50' } }, + { name: 'userWithId', parameters: { userIds: '5' } } + ]) + + disable_migrations_output { migrate! } + + scope.reload + expect(scope.active).to eq(true) + expect(scope.strategies).to eq([{ 'name' => 'userWithId', 'parameters' => { 'userIds' => '5' } }]) + end + + it 'migrates a disabled scope with default and userWithId strategies' do + flag = setup + scope = scopes.create!(feature_flag_id: flag.id, active: false, strategies: [ + { name: 'default', parameters: {} }, + { name: 'userWithId', parameters: { userIds: 'amy@gmail.com,karen@gmail.com' } } + ]) + + disable_migrations_output { migrate! } + + scope.reload + expect(scope.active).to eq(true) + expect(scope.strategies).to eq([{ 'name' => 'userWithId', 'parameters' => { 'userIds' => 'amy@gmail.com,karen@gmail.com' } }]) + end + + it 'migrates an enabled scope with default and userWithId strategies' do + flag = setup + scope = scopes.create!(feature_flag_id: flag.id, active: true, strategies: [ + { name: 'default', parameters: {} }, + { name: 'userWithId', parameters: { userIds: 'tim' } } + ]) + + disable_migrations_output { migrate! } + + scope.reload + expect(scope.active).to eq(true) + expect(scope.strategies).to eq([{ 'name' => 'default', 'parameters' => {} }]) + end + + it 'does not alter an enabled scope with gradualRolloutUserId and userWithId strategies' do + flag = setup + scope = scopes.create!(feature_flag_id: flag.id, active: true, strategies: [ + { name: 'gradualRolloutUserId', parameters: { groupId: 'default', percentage: '50' } }, + { name: 'userWithId', parameters: { userIds: '5' } } + ]) + + disable_migrations_output { migrate! } + + scope.reload + expect(scope.active).to eq(true) + expect(scope.strategies).to eq([ + { 'name' => 'gradualRolloutUserId', 'parameters' => { 'groupId' => 'default', 'percentage' => '50' } }, + { 'name' => 'userWithId', 'parameters' => { 'userIds' => '5' } } + ]) + end + + it 'does not alter a disabled scope without a userWithId strategy' do + flag = setup + scope = scopes.create!(feature_flag_id: flag.id, active: false, strategies: [ + { name: 'gradualRolloutUserId', parameters: { percentage: '60' } } + ]) + + disable_migrations_output { migrate! } + + scope.reload + expect(scope.active).to eq(false) + expect(scope.strategies).to eq([ + { 'name' => 'gradualRolloutUserId', 'parameters' => { 'percentage' => '60' } } + ]) + end + + it 'does not alter an enabled scope without a userWithId strategy' do + flag = setup + scope = scopes.create!(feature_flag_id: flag.id, active: true, strategies: [ + { name: 'default', parameters: {} } + ]) + + disable_migrations_output { migrate! } + + scope.reload + expect(scope.active).to eq(true) + expect(scope.strategies).to eq([ + { 'name' => 'default', 'parameters' => {} } + ]) + end + + it 'migrates multiple scopes' do + flag = setup + scope_a = scopes.create!(feature_flag_id: flag.id, active: false, strategies: [ + { name: 'gradualRolloutUserId', parameters: { groupId: 'default', percentage: '50' } }, + { name: 'userWithId', parameters: { userIds: '5,6,7' } } + ]) + scope_b = scopes.create!(feature_flag_id: flag.id, active: false, environment_scope: 'production', strategies: [ + { name: 'default', parameters: {} }, + { name: 'userWithId', parameters: { userIds: 'lisa,carol' } } + ]) + + disable_migrations_output { migrate! } + + scope_a.reload + scope_b.reload + expect(scope_a.active).to eq(true) + expect(scope_a.strategies).to eq([{ 'name' => 'userWithId', 'parameters' => { 'userIds' => '5,6,7' } }]) + expect(scope_b.active).to eq(true) + expect(scope_b.strategies).to eq([{ 'name' => 'userWithId', 'parameters' => { 'userIds' => 'lisa,carol' } }]) + end +end |