2019-10-24 20:06:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-04 19:43:41 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe DeployTokenPolicy do
|
2018-04-04 19:43:41 -04:00
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
let(:project) { create(:project) }
|
2018-04-05 23:02:13 -04:00
|
|
|
let(:deploy_token) { create(:deploy_token, projects: [project]) }
|
2018-04-04 19:43:41 -04:00
|
|
|
|
|
|
|
subject { described_class.new(current_user, deploy_token) }
|
|
|
|
|
|
|
|
describe 'creating a deploy key' do
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2018-04-04 19:43:41 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(current_user)
|
2018-04-04 19:43:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:create_deploy_token) }
|
|
|
|
end
|
2018-04-05 13:22:34 -04:00
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is not maintainer' do
|
2018-04-04 19:43:41 -04:00
|
|
|
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
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2018-04-04 19:43:41 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(current_user)
|
2018-04-04 19:43:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:update_deploy_token) }
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is not maintainer' do
|
2018-04-04 19:43:41 -04:00
|
|
|
before do
|
|
|
|
project.add_developer(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:update_deploy_token) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|