summaryrefslogtreecommitdiff
path: root/spec/tasks/admin_mode_spec.rb
blob: 116d47aa503d3ab4fbcb8a0d88639a6281c26884 (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
# frozen_string_literal: true

require 'rake_helper'

RSpec.describe 'admin mode on tasks', :silence_stdout do
  before do
    allow(::Gitlab::Runtime).to receive(:test_suite?).and_return(false)
    allow(::Gitlab::Runtime).to receive(:rake?).and_return(true)
  end

  shared_examples 'verify admin mode' do |state|
    it 'matches the expected admin mode' do
      Rake::Task.define_task :verify_admin_mode do
        expect(Gitlab::Auth::CurrentUserMode.new(user).admin_mode?).to be(state)
      end

      run_rake_task('verify_admin_mode')
    end
  end

  describe 'with a regular user' do
    let(:user) { create(:user) }

    include_examples 'verify admin mode', false
  end

  describe 'with an admin' do
    let(:user) { create(:admin) }

    include_examples 'verify admin mode', true
  end
end