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

45 lines
1.1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
require "spec_helper"
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Git::DiffStatsCollection do
2018-12-05 23:21:45 +05:30
let(:stats_a) do
2020-07-28 23:09:34 +05:30
Gitaly::DiffStats.new(additions: 10, deletions: 15, path: 'foo')
2018-12-05 23:21:45 +05:30
end
let(:stats_b) do
2020-07-28 23:09:34 +05:30
Gitaly::DiffStats.new(additions: 5, deletions: 1, path: 'bar')
2018-12-05 23:21:45 +05:30
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
2020-04-22 19:07:51 +05:30
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
2022-01-26 12:08:38 +05:30
allow(::Commit).to receive(:diff_max_files).and_return(1)
2020-04-22 19:07:51 +05:30
expect(collection.real_size).to eq('1+')
end
end
2018-12-05 23:21:45 +05:30
end