2019-10-24 20:06:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-23 14:24:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe ProtectedBranchPolicy do
|
2018-03-23 14:24:06 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:name) { 'feature' }
|
|
|
|
let(:protected_branch) { create(:protected_branch, name: name) }
|
|
|
|
let(:project) { protected_branch.project }
|
|
|
|
|
|
|
|
subject { described_class.new(user, protected_branch) }
|
|
|
|
|
2022-08-30 08:12:25 -04:00
|
|
|
context 'as maintainers' do
|
|
|
|
before do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
end
|
2018-03-23 14:24:06 -04:00
|
|
|
|
2022-08-30 08:12:25 -04:00
|
|
|
it 'can be read' do
|
|
|
|
is_expected.to be_allowed(:read_protected_branch)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be created' do
|
|
|
|
is_expected.to be_allowed(:create_protected_branch)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be updated' do
|
|
|
|
is_expected.to be_allowed(:update_protected_branch)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be destroyed' do
|
|
|
|
is_expected.to be_allowed(:destroy_protected_branch)
|
|
|
|
end
|
2018-03-23 14:24:06 -04:00
|
|
|
end
|
|
|
|
|
2022-08-30 08:12:25 -04:00
|
|
|
context 'as guests' do
|
|
|
|
before do
|
|
|
|
project.add_guest(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be read' do
|
|
|
|
is_expected.to be_disallowed(:read_protected_branch)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be created' do
|
|
|
|
is_expected.to be_disallowed(:create_protected_branch)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can be updated' do
|
|
|
|
is_expected.to be_disallowed(:update_protected_branch)
|
|
|
|
end
|
2018-03-23 14:24:06 -04:00
|
|
|
|
2022-08-30 08:12:25 -04:00
|
|
|
it 'cannot be destroyed' do
|
|
|
|
is_expected.to be_disallowed(:destroy_protected_branch)
|
|
|
|
end
|
2018-03-23 14:24:06 -04:00
|
|
|
end
|
|
|
|
end
|