diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-22 15:09:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-22 15:09:49 +0300 |
commit | 4b074c5f634f8e1e550107f9e8237f07878ca0e8 (patch) | |
tree | 00afed4a6853548ec97203f3f807d954180b547d /spec/experiments/concerns | |
parent | b81fd57f3d62db4455108c8de4b8d7b8d403de35 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/experiments/concerns')
-rw-r--r-- | spec/experiments/concerns/project_commit_count_spec.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/experiments/concerns/project_commit_count_spec.rb b/spec/experiments/concerns/project_commit_count_spec.rb new file mode 100644 index 00000000000..5616f167cb4 --- /dev/null +++ b/spec/experiments/concerns/project_commit_count_spec.rb @@ -0,0 +1,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 |