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

project_commit_count_spec.rb « concerns « experiments « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5616f167cb404f0e226e3960c00a4dbf89b01248 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ProjectCommitCount do
  let(:klass) { Class.include(ProjectCommitCount) }
  let(:instance) { klass.new }

  describe '#commit_count_for' do
    subject { instance.commit_count_for(project, default_count: 42, caller_info: :identifiable) }

    let(:project) { create(:project, :repository) }

    context 'when a root_ref exists' do
      it 'returns commit count from GitlayClient' do
        allow(Gitlab::GitalyClient).to receive(:call).and_call_original
        allow(Gitlab::GitalyClient).to receive(:call).with(anything, :commit_service, :count_commits, anything, anything)
          .and_return(double(count: 4))

        expect(subject).to eq(4)
      end
    end

    context 'when a root_ref does not exist' do
      let(:project) { create(:project, :empty_repo) }

      it 'returns the default_count' do
        expect(subject).to eq(42)
      end
    end

    it "handles exceptions by logging them with exception_details and returns the default_count" do
      allow(Gitlab::GitalyClient).to receive(:call).and_call_original
      allow(Gitlab::GitalyClient).to receive(:call).with(anything, :commit_service, :count_commits, anything, anything).and_raise(e = StandardError.new('_message_'))

      expect(Gitlab::ErrorTracking).to receive(:track_exception).with(e, caller_info: :identifiable)

      expect(subject).to eq(42)
    end
  end
end