Welcome to mirror list, hosted at ThFree Co, Russian Federation.

term_policy_spec.rb « application_setting « policies « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fd361c8b649879875039f7a2c3d144edc16855a5 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ApplicationSetting::TermPolicy do
  include TermsHelper

  let_it_be(:term) { create(:term) }

  let(:user) { create(:user) }

  subject(:policy) { described_class.new(user, term) }

  before do
    stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
  end

  it 'has the correct permissions', :aggregate_failures do
    is_expected.to be_allowed(:accept_terms)
    is_expected.to be_allowed(:decline_terms)
  end

  context 'for anonymous users' do
    let(:user) { nil }

    it 'has the correct permissions', :aggregate_failures do
      is_expected.to be_disallowed(:accept_terms)
      is_expected.to be_disallowed(:decline_terms)
    end
  end

  context 'when the terms are not current' do
    before do
      create(:term)
    end

    it 'has the correct permissions', :aggregate_failures do
      is_expected.to be_disallowed(:accept_terms)
      is_expected.to be_disallowed(:decline_terms)
    end
  end

  context 'when the user already accepted the terms' do
    before do
      accept_terms(user)
    end

    it 'has the correct permissions', :aggregate_failures do
      is_expected.to be_disallowed(:accept_terms)
      is_expected.to be_allowed(:decline_terms)
    end
  end
end