Commit 86c0558c authored by Matija Čupić's avatar Matija Čupić

Refactor Project#protected_for? specs

This refactors the Project#protected_for? specs to separate them into
two contexts: when the ref is a full ref and when the ref is a ref name.
parent 93d3c61e
......@@ -2567,6 +2567,37 @@ describe Project do
subject { project.protected_for?(ref) }
shared_examples 'ref is not protected' do
before do
stub_application_setting(
default_branch_protection: Gitlab::Access::PROTECTION_NONE)
end
it 'returns false' do
is_expected.to be_falsey
end
end
shared_examples 'ref is protected branch' do
before do
create(:protected_branch, name: 'master', project: project)
end
it 'returns true' do
is_expected.to be_truthy
end
end
shared_examples 'ref is protected tag' do
before do
create(:protected_tag, name: 'v1.0.0', project: project)
end
it 'returns true' do
is_expected.to be_truthy
end
end
context 'when ref is nil' do
let(:ref) { nil }
......@@ -2575,12 +2606,13 @@ describe Project do
end
end
context 'when ref is ref name' do
context 'when ref is ambiguous' do
let(:ref) { 'ref' }
before do
project.repository.add_branch(project.creator, ref, 'master')
project.repository.add_tag(project.creator, ref, 'master')
project.repository.add_branch(project.creator, 'ref', 'master')
project.repository.add_tag(project.creator, 'ref', 'master')
end
it 'raises an error' do
......@@ -2591,70 +2623,53 @@ describe Project do
context 'when the ref is not protected' do
let(:ref) { 'master' }
before do
stub_application_setting(
default_branch_protection: Gitlab::Access::PROTECTION_NONE)
end
it 'returns false' do
is_expected.to be_falsey
end
it_behaves_like 'ref is not protected'
end
context 'when the ref is a protected branch' do
let(:ref) { 'master' }
before do
create(:protected_branch, name: 'master', project: project)
end
it 'returns true' do
is_expected.to be_truthy
end
it_behaves_like 'ref is protected branch'
end
context 'when the ref is a protected tag' do
let(:ref) { 'v1.0.0' }
before do
create(:protected_tag, name: 'v1.0.0', project: project)
end
it 'returns true' do
is_expected.to be_truthy
it_behaves_like 'ref is protected tag'
end
end
context 'when ref is a full ref' do
context 'when ref is full ref' do
context 'when the ref is not protected' do
let(:ref) { 'refs/heads/master' }
context 'when ref is not protected' do
it 'returns false' do
is_expected.to be_falsey
end
it_behaves_like 'ref is not protected'
end
context 'when ref is protected' do
before do
create(:protected_branch, name: 'master', project: project)
end
context 'when the ref is a protected branch' do
let(:ref) { 'refs/heads/master' }
it 'returns true' do
is_expected.to be_truthy
end
it_behaves_like 'ref is protected branch'
end
context 'when the ref is a protected tag' do
let(:ref) { 'refs/tags/v1.0.0' }
it_behaves_like 'ref is protected tag'
end
context 'when ref name is a full tag ref' do
context 'when branch ref name is a full tag ref' do
let(:ref) { 'refs/tags/something' }
before do
project.repository.add_branch(project.creator, ref, 'master')
end
context 'when ref is not protected' do
it 'returns false' do
is_expected.to be_falsey
end
end
context 'when ref is a protected branch' do
before do
......@@ -2667,6 +2682,7 @@ describe Project do
end
end
end
end
describe '#update_project_statistics' do
let(:project) { create(:project) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment