summaryrefslogtreecommitdiff
path: root/spec/migrations/20220802204737_remove_deactivated_user_highest_role_stats_spec.rb
blob: 36c65612bb99cf1e10c547fdfbb3091394168f55 (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
# frozen_string_literal: true

require 'spec_helper'
require_migration!

RSpec.describe RemoveDeactivatedUserHighestRoleStats, feature_category: :subscription_cost_management 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