debian-mirror-gitlab/spec/lib/gitlab/git/commit_stats_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
896 B
Ruby
Raw Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
require "spec_helper"
2022-10-11 01:57:18 +05:30
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']) }
2021-10-27 15:23:28 +05:30
def verify_stats!
stats = described_class.new(repository, commit)
expect(stats).to have_attributes(
2022-10-11 01:57:18 +05:30
additions: eq(5),
deletions: eq(0),
total: eq(5)
2021-10-27 15:23:28 +05:30
)
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!
2022-10-11 01:57:18 +05:30
expect(Rails.cache.fetch("commit_stats:#{repository.gl_project_path}:#{commit.id}")).to eq([5, 0])
2021-10-27 15:23:28 +05:30
expect(repository.gitaly_commit_client).not_to receive(:commit_stats)
verify_stats!
end
end