summaryrefslogtreecommitdiff
path: root/spec/models/repository_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/repository_spec.rb')
-rw-r--r--spec/models/repository_spec.rb46
1 files changed, 31 insertions, 15 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 02d31098cfd..e65214808e1 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -296,24 +296,40 @@ describe Repository do
end
describe '#new_commits' do
- let(:new_refs) do
- double(:git_rev_list, new_refs: %w[
- c1acaa58bbcbc3eafe538cb8274ba387047b69f8
- 5937ac0a7beb003549fc5fd26fc247adbce4a52e
- ])
- end
+ shared_examples 'finding unreferenced commits' do
+ set(:project) { create(:project, :repository) }
+ let(:repository) { project.repository }
- it 'delegates to Gitlab::Git::RevList' do
- expect(Gitlab::Git::RevList).to receive(:new).with(
- repository.raw,
- newrev: 'aaaabbbbccccddddeeeeffffgggghhhhiiiijjjj').and_return(new_refs)
+ subject { repository.new_commits(rev) }
- commits = repository.new_commits('aaaabbbbccccddddeeeeffffgggghhhhiiiijjjj')
+ context 'when there are no new commits' do
+ let(:rev) { repository.commit.id }
- expect(commits).to eq([
- repository.commit('c1acaa58bbcbc3eafe538cb8274ba387047b69f8'),
- repository.commit('5937ac0a7beb003549fc5fd26fc247adbce4a52e')
- ])
+ it 'returns an empty array' do
+ expect(subject).to eq([])
+ end
+ end
+
+ context 'when new commits are found' do
+ let(:branch) { 'orphaned-branch' }
+ let!(:rev) { repository.commit(branch).id }
+
+ it 'returns the commits' do
+ repository.delete_branch(branch)
+
+ expect(subject).not_to be_empty
+ expect(subject).to all( be_a(::Commit) )
+ expect(subject.size).to eq(1)
+ end
+ end
+ end
+
+ context 'when Gitaly handles the request' do
+ it_behaves_like 'finding unreferenced commits'
+ end
+
+ context 'when Gitaly is disabled', :disable_gitaly do
+ it_behaves_like 'finding unreferenced commits'
end
end