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

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

require "spec_helper"

RSpec.describe Gitlab::Git::DiffStatsCollection do
  let(:stats_a) do
    Gitaly::DiffStats.new(additions: 10, deletions: 15, path: 'foo')
  end

  let(:stats_b) do
    Gitaly::DiffStats.new(additions: 5, deletions: 1, path: 'bar')
  end

  let(:diff_stats) { [stats_a, stats_b] }
  let(:collection) { described_class.new(diff_stats) }

  describe '#find_by_path' do
    it 'returns stats by path when found' do
      expect(collection.find_by_path('foo')).to eq(stats_a)
    end

    it 'returns nil when stats is not found by path' do
      expect(collection.find_by_path('no-file')).to be_nil
    end
  end

  describe '#paths' do
    it 'returns only modified paths' do
      expect(collection.paths).to eq %w[foo bar]
    end
  end

  describe '#real_size' do
    it 'returns the number of modified files' do
      expect(collection.real_size).to eq('2')
    end

    it 'returns capped number when it is bigger than max_files' do
      allow(::Commit).to receive(:max_diff_options).and_return(max_files: 1)

      expect(collection.real_size).to eq('1+')
    end
  end
end