Commit 8065adcc authored by Alejandro Rodríguez's avatar Alejandro Rodríguez

Improve Gitlab::Git::Repository specs for #branches

parent 432bb223
...@@ -911,8 +911,34 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -911,8 +911,34 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
end end
describe '#branches with deleted branch' do describe '#branches' do
before(:each) do subject { repository.branches }
context 'with local and remote branches' do
let(:repository) do
Gitlab::Git::Repository.new('default', File.join(TEST_MUTABLE_REPO_PATH, '.git'))
end
before do
create_remote_branch(repository, 'joe', 'remote_branch', 'master')
repository.create_branch('local_branch', 'master')
end
after do
FileUtils.rm_rf(TEST_MUTABLE_REPO_PATH)
ensure_seeds
end
it 'returns the local and remote branches' do
expect(subject.any? { |b| b.name == 'joe/remote_branch' }).to eq(true)
expect(subject.any? { |b| b.name == 'local_branch' }).to eq(true)
end
end
# With Gitaly enabled, Gitaly just doesn't return deleted branches.
context 'with deleted branch with Gitaly disabled' do
before do
allow(Gitlab::GitalyClient).to receive(:feature_enabled?).and_return(false)
ref = double() ref = double()
allow(ref).to receive(:name) { 'bad-branch' } allow(ref).to receive(:name) { 'bad-branch' }
allow(ref).to receive(:target) { raise Rugged::ReferenceError } allow(ref).to receive(:target) { raise Rugged::ReferenceError }
...@@ -921,8 +947,7 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -921,8 +947,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
allow(repository.rugged).to receive(:branches) { branches } allow(repository.rugged).to receive(:branches) { branches }
end end
it 'should return empty branches' do it { is_expected.to eq([]) }
expect(repository.branches).to eq([])
end end
end end
...@@ -1070,7 +1095,7 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1070,7 +1095,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
it 'returns the local branches' do it 'returns the local branches' do
create_remote_branch('joe', 'remote_branch', 'master') create_remote_branch(@repo, 'joe', 'remote_branch', 'master')
@repo.create_branch('local_branch', 'master') @repo.create_branch('local_branch', 'master')
expect(@repo.local_branches.any? { |branch| branch.name == 'remote_branch' }).to eq(false) expect(@repo.local_branches.any? { |branch| branch.name == 'remote_branch' }).to eq(false)
...@@ -1097,9 +1122,9 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -1097,9 +1122,9 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
end end
def create_remote_branch(remote_name, branch_name, source_branch_name) def create_remote_branch(repository, remote_name, branch_name, source_branch_name)
source_branch = @repo.branches.find { |branch| branch.name == source_branch_name } source_branch = repository.branches.find { |branch| branch.name == source_branch_name }
rugged = @repo.rugged rugged = repository.rugged
rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", source_branch.dereferenced_target.sha) rugged.references.create("refs/remotes/#{remote_name}/#{branch_name}", source_branch.dereferenced_target.sha)
end end
......
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