summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorOswaldo Ferreira <oswaldo@gitlab.com>2018-09-19 12:26:28 +0000
committerNick Thomas <nick@gitlab.com>2018-09-19 12:26:28 +0000
commit5dce096cf8b645d430bfdce8add8a577b595dc23 (patch)
tree69ac2bf5373bffd1e869d9b1c9f54e2c912cb767 /spec/support
parent3172de0df3801125c23d1811a53d1467dec45645 (diff)
downloadgitlab-ce-5dce096cf8b645d430bfdce8add8a577b595dc23.tar.gz
Use standalone diff stats RPC on every comparison view
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/shared_examples/diff_file_collections.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/support/shared_examples/diff_file_collections.rb b/spec/support/shared_examples/diff_file_collections.rb
new file mode 100644
index 00000000000..55ce160add0
--- /dev/null
+++ b/spec/support/shared_examples/diff_file_collections.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+shared_examples 'diff statistics' do |test_include_stats_flag: true|
+ def stub_stats_find_by_path(path, stats_mock)
+ expect_next_instance_of(Gitlab::Git::DiffStatsCollection) do |collection|
+ allow(collection).to receive(:find_by_path).and_call_original
+ expect(collection).to receive(:find_by_path).with(path).and_return(stats_mock)
+ end
+ end
+
+ context 'when should request diff stats' do
+ it 'Repository#diff_stats is called' do
+ subject = described_class.new(diffable, collection_default_args)
+
+ expect(diffable.project.repository)
+ .to receive(:diff_stats)
+ .with(diffable.diff_refs.base_sha, diffable.diff_refs.head_sha)
+ .and_call_original
+
+ subject.diff_files
+ end
+
+ it 'Gitlab::Diff::File is initialized with diff stats' do
+ subject = described_class.new(diffable, collection_default_args)
+
+ stats_mock = double(Gitaly::DiffStats, path: '.gitignore', additions: 758, deletions: 120)
+ stub_stats_find_by_path(stub_path, stats_mock)
+
+ diff_file = subject.diff_files.find { |file| file.new_path == stub_path }
+
+ expect(diff_file.added_lines).to eq(stats_mock.additions)
+ expect(diff_file.removed_lines).to eq(stats_mock.deletions)
+ end
+ end
+
+ context 'when should not request diff stats' do
+ it 'Repository#diff_stats is not called' do
+ collection_default_args[:diff_options][:include_stats] = false
+
+ subject = described_class.new(diffable, collection_default_args)
+
+ expect(diffable.project.repository).not_to receive(:diff_stats)
+
+ subject.diff_files
+ end
+ end
+end