2018-04-04 19:43:41 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe DeployTokenPolicy do
|
|
|
|
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
|
|
|
|
context 'when user is master' do
|
|
|
|
before do
|
|
|
|
project.add_master(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:create_deploy_token) }
|
|
|
|
end
|
2018-04-05 13:22:34 -04:00
|
|
|
|
2018-04-04 19:43:41 -04:00
|
|
|
context 'when user is not master' do
|
|
|
|
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
|
|
|
|
context 'when user is master' do
|
|
|
|
before do
|
|
|
|
project.add_master(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_allowed(:update_deploy_token) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not master' do
|
|
|
|
before do
|
|
|
|
project.add_developer(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_disallowed(:update_deploy_token) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|