diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-11-23 00:11:42 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-12-08 19:28:56 +0100 |
commit | 350ea9c55ab6b980ac5ec74d2a34b9cbac915e20 (patch) | |
tree | 0f5bb6e6adac068f25ed063d86c6f013ea1cd9ee /spec | |
parent | d307dccbc60f088496fb727f40530ba3003b61fb (diff) | |
download | gitlab-ce-350ea9c55ab6b980ac5ec74d2a34b9cbac915e20.tar.gz |
Implement Repository#ambiguous_ref?
This implements Repository#ambiguous_ref? and checks if a ref is
ambiguous before trying to resolve the ref in Project#protected_for?
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/project_spec.rb | 23 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 68 |
2 files changed, 57 insertions, 34 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 25560ddea8d..18ad69a1bda 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2565,14 +2565,23 @@ describe Project do describe '#protected_for?' do let(:project) { create(:project, :repository) } - subject { project.protected_for?('ref') } + subject { project.protected_for?(ref) } - before do - allow(project.repository).to receive(:resolve_ref).and_return(ref) + context 'when ref is nil' do + let(:ref) { nil } + + it 'returns false' do + is_expected.to be_falsey + end end context 'when ref is ambiguous' do - let(:ref) { nil } + let(:ref) { 'ref' } + + before do + project.repository.add_branch(project.creator, ref, 'master') + project.repository.add_tag(project.creator, ref, 'master') + end it 'returns false' do is_expected.to be_falsey @@ -2580,7 +2589,7 @@ describe Project do end context 'when the ref is not protected' do - let(:ref) { 'refs/heads/master' } + let(:ref) { 'master' } before do stub_application_setting( @@ -2593,7 +2602,7 @@ describe Project do end context 'when the ref is a protected branch' do - let(:ref) { 'refs/heads/master' } + let(:ref) { 'master' } before do create(:protected_branch, name: 'master', project: project) @@ -2605,7 +2614,7 @@ describe Project do end context 'when the ref is a protected tag' do - let(:ref) { 'refs/tags/v1.0.0' } + let(:ref) { 'v1.0.0' } before do create(:protected_tag, name: 'v1.0.0', project: project) diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 3d6cf2cbc19..cdececd49e0 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1005,7 +1005,36 @@ describe Repository do end end + describe '#ambiguous_ref?' do + let(:ref) { 'ref' } + + subject { repository.ambiguous_ref?(ref) } + + context 'when ref is ambiguous' do + before do + repository.add_tag(project.creator, ref, 'master') + repository.add_branch(project.creator, ref, 'master') + end + + it 'should be true' do + is_expected.to eq(true) + end + end + + context 'when ref is not ambiguous' do + before do + repository.add_tag(project.creator, ref, 'master') + end + + it 'should be false' do + is_expected.to eq(false) + end + end + end + describe '#resolve_ref' do + let(:ref) { 'ref' } + subject { repository.resolve_ref(ref) } context 'when ref is full ref' do @@ -1016,38 +1045,23 @@ describe Repository do end end - context 'when ref is a tag or branch name' do - let(:ref) { 'ref' } - - context 'when ref is ambiguous' do - before do - repository.add_tag(project.creator, ref, 'master') - repository.add_branch(project.creator, ref, 'master') - end - - it 'returns nil' do - is_expected.to eq(nil) - end + context 'when ref is tag name' do + before do + repository.add_tag(project.creator, ref, 'master') end - context 'when ref is tag name' do - before do - repository.add_tag(project.creator, ref, 'master') - end - - it 'returns the tag ref' do - is_expected.to eq("refs/tags/#{ref}") - end + it 'returns the tag ref' do + is_expected.to eq("refs/tags/#{ref}") end + end - context 'when ref is branch name' do - before do - repository.add_branch(project.creator, ref, 'master') - end + context 'when ref is branch name' do + before do + repository.add_branch(project.creator, ref, 'master') + end - it 'returns the branch ref' do - is_expected.to eq("refs/heads/#{ref}") - end + it 'returns the branch ref' do + is_expected.to eq("refs/heads/#{ref}") end end end |