diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2019-07-01 08:38:16 +0000 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2019-07-01 08:38:16 +0000 |
commit | 8775e4a1faf13a01451e71ea9ef729dc52e6d3c1 (patch) | |
tree | 8632c5465f6b3dee57bb0ccd64f5162c35b8ab15 /spec/services | |
parent | f63dc06cb4572db92bb91c936e9862c55f1f365e (diff) | |
parent | ca5cd7b7fb5108d30d0f6b74e31da736024592dd (diff) | |
download | gitlab-ce-8775e4a1faf13a01451e71ea9ef729dc52e6d3c1.tar.gz |
Merge branch 'id-stale-branches' into 'master'
Add endpoint for fetching diverging commit counts
See merge request gitlab-org/gitlab-ce!29802
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/branches/diverging_commit_counts_service_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/services/branches/diverging_commit_counts_service_spec.rb b/spec/services/branches/diverging_commit_counts_service_spec.rb new file mode 100644 index 00000000000..bfdbebdb7c1 --- /dev/null +++ b/spec/services/branches/diverging_commit_counts_service_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Branches::DivergingCommitCountsService do + let(:project) { create(:project, :repository) } + let(:repository) { project.repository } + + describe '#call' do + let(:diverged_branch) { repository.find_branch('fix') } + let(:root_ref_sha) { repository.raw_repository.commit(repository.root_ref).id } + let(:diverged_branch_sha) { diverged_branch.dereferenced_target.sha } + + let(:service) { described_class.new(repository) } + + it 'returns the commit counts behind and ahead of default branch' do + result = service.call(diverged_branch) + + expect(result).to eq(behind: 29, ahead: 2) + end + + context 'when gitaly_count_diverging_commits_no_max is enabled' do + before do + stub_feature_flags(gitaly_count_diverging_commits_no_max: true) + end + + it 'calls diverging_commit_count without max count' do + expect(repository.raw_repository) + .to receive(:diverging_commit_count) + .with(root_ref_sha, diverged_branch_sha) + .and_return([29, 2]) + + service.call(diverged_branch) + end + end + + context 'when gitaly_count_diverging_commits_no_max is disabled' do + before do + stub_feature_flags(gitaly_count_diverging_commits_no_max: false) + end + + it 'calls diverging_commit_count with max count' do + expect(repository.raw_repository) + .to receive(:diverging_commit_count) + .with(root_ref_sha, diverged_branch_sha, max_count: Repository::MAX_DIVERGING_COUNT) + .and_return([29, 2]) + + service.call(diverged_branch) + end + end + end +end |