summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/git/commit_stats_spec.rb
blob: 81d9dda4b8ff6824f3e0af30a76852570f7cb30e (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
# frozen_string_literal: true

require "spec_helper"

RSpec.describe Gitlab::Git::CommitStats do
  let_it_be(:project) { create(:project, :repository) }
  let_it_be(:repository) { project.repository.raw }

  let(:commit) { Gitlab::Git::Commit.find(repository, TestEnv::BRANCH_SHA['feature']) }

  def verify_stats!
    stats = described_class.new(repository, commit)

    expect(stats).to have_attributes(
      additions: eq(5),
      deletions: eq(0),
      total: eq(5)
    )
  end

  it 'returns commit stats and caches them', :use_clean_rails_redis_caching do
    expect(repository.gitaly_commit_client).to receive(:commit_stats).with(commit.id).and_call_original

    verify_stats!

    expect(Rails.cache.fetch("commit_stats:#{repository.gl_project_path}:#{commit.id}")).to eq([5, 0])

    expect(repository.gitaly_commit_client).not_to receive(:commit_stats)

    verify_stats!
  end
end