summaryrefslogtreecommitdiff
path: root/spec/policies/application_setting_policy_spec.rb
blob: f5f02d25c64401ffa578d90ea9ddfa4a83a1376d (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
40
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ApplicationSettingPolicy do
  let(:current_user) { create(:user) }
  let(:user) { create(:user) }

  subject { described_class.new(current_user, [user]) }

  describe 'update_runners_registration_token' do
    context 'when anonymous' do
      let(:current_user) { nil }

      it { is_expected.not_to be_allowed(:update_runners_registration_token) }
    end

    context 'regular user' do
      it { is_expected.not_to be_allowed(:update_runners_registration_token) }
    end

    context 'when external' do
      let(:current_user) { build(:user, :external) }

      it { is_expected.not_to be_allowed(:update_runners_registration_token) }
    end

    context 'admin' do
      let(:current_user) { create(:admin) }

      context 'when admin mode is enabled', :enable_admin_mode do
        it { is_expected.to be_allowed(:update_runners_registration_token) }
      end

      context 'when admin mode is disabled' do
        it { is_expected.to be_disallowed(:update_runners_registration_token) }
      end
    end
  end
end