diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-03-07 22:29:12 -0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-03-07 22:46:29 -0300 |
commit | c6273ec50c019a115b11a8ef1032a64710f0a46a (patch) | |
tree | ce1a808bafc98f2181a621b75e293c4c27d1899e /spec | |
parent | 7734e85bc6592c5ad3330c611c5f83a051b680b0 (diff) | |
download | gitlab-ce-c6273ec50c019a115b11a8ef1032a64710f0a46a.tar.gz |
Avoid re-fetching merge-base SHA from Gitaly unnecessarily
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/compare_spec.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/models/compare_spec.rb b/spec/models/compare_spec.rb index 04f3cecae00..4200af0e0f5 100644 --- a/spec/models/compare_spec.rb +++ b/spec/models/compare_spec.rb @@ -59,6 +59,36 @@ describe Compare do end end + describe '#base_commit_sha' do + it 'returns @base_sha if it is present' do + expect(project).not_to receive(:merge_base_commit) + + sha = double + service = described_class.new(raw_compare, project, base_sha: sha) + + expect(service.base_commit_sha).to eq(sha) + end + + it 'fetches merge base SHA from repo when @base_sha is nil' do + expect(project).to receive(:merge_base_commit) + .with(start_commit.id, head_commit.id) + .once + .and_call_original + + expect(subject.base_commit_sha) + .to eq(project.repository.merge_base(start_commit.id, head_commit.id)) + end + + it 'is memoized on first call' do + expect(project).to receive(:merge_base_commit) + .with(start_commit.id, head_commit.id) + .once + .and_call_original + + 3.times { subject.base_commit_sha } + end + end + describe '#diff_refs' do it 'uses base_commit sha as base_sha' do expect(subject).to receive(:base_commit).at_least(:once).and_call_original |