diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-15 18:12:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-15 18:12:51 +0000 |
commit | efbd20fd1ecd091f1270f73d617822a32c94376f (patch) | |
tree | 98bc700b5eaabb510d9af3a7ca6ddc847de9ac42 /spec/migrations | |
parent | 51d5328e82229d69456d3a43dd2cf10518bf64c7 (diff) | |
download | gitlab-ce-efbd20fd1ecd091f1270f73d617822a32c94376f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/20220802204737_remove_deactivated_user_highest_role_stats_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/migrations/20220802204737_remove_deactivated_user_highest_role_stats_spec.rb b/spec/migrations/20220802204737_remove_deactivated_user_highest_role_stats_spec.rb new file mode 100644 index 00000000000..3ea286ca138 --- /dev/null +++ b/spec/migrations/20220802204737_remove_deactivated_user_highest_role_stats_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe RemoveDeactivatedUserHighestRoleStats do + let!(:users) { table(:users) } + let!(:user_highest_roles) { table(:user_highest_roles) } + + let!(:user1) do + users.create!(username: 'user1', email: 'user1@example.com', projects_limit: 10, state: 'active') + end + + let!(:user2) do + users.create!(username: 'user2', email: 'user2@example.com', projects_limit: 10, state: 'deactivated') + end + + let!(:highest_role1) { user_highest_roles.create!(user_id: user1.id) } + let!(:highest_role2) { user_highest_roles.create!(user_id: user2.id) } + + describe '#up' do + context 'when on gitlab.com' do + it 'does not change user highest role records' do + allow(Gitlab).to receive(:com?).and_return(true) + expect { migrate! }.not_to change(user_highest_roles, :count) + end + end + + context 'when not on gitlab.com' do + it 'removes all user highest role records for deactivated users' do + allow(Gitlab).to receive(:com?).and_return(false) + migrate! + expect(user_highest_roles.pluck(:user_id)).to contain_exactly( + user1.id + ) + end + end + end +end |