deploy_token_policy_spec.rb 1.07 KB
Newer Older
1 2 3 4 5
require 'spec_helper'

describe DeployTokenPolicy do
  let(:current_user) { create(:user) }
  let(:project) { create(:project) }
6
  let(:deploy_token) { create(:deploy_token, projects: [project]) }
7 8 9 10

  subject { described_class.new(current_user, deploy_token) }

  describe 'creating a deploy key' do
11
    context 'when user is maintainer' do
12
      before do
13
        project.add_maintainer(current_user)
14 15 16 17
      end

      it { is_expected.to be_allowed(:create_deploy_token) }
    end
18

19
    context 'when user is not maintainer' do
20 21 22 23 24 25 26 27 28
      before do
        project.add_developer(current_user)
      end

      it { is_expected.to be_disallowed(:create_deploy_token) }
    end
  end

  describe 'updating a deploy key' do
29
    context 'when user is maintainer' do
30
      before do
31
        project.add_maintainer(current_user)
32 33 34 35 36
      end

      it { is_expected.to be_allowed(:update_deploy_token) }
    end

37
    context 'when user is not maintainer' do
38 39 40 41 42 43 44 45
      before do
        project.add_developer(current_user)
      end

      it { is_expected.to be_disallowed(:update_deploy_token) }
    end
  end
end