Welcome to mirror list, hosted at ThFree Co, Russian Federation.

diverging_commit_counts_service_spec.rb « branches « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bfdbebdb7c1c9b7a0b00de6191e933e2942ce34a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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