2019-10-08 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-09 07:17:42 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe DiffHelper do
|
2014-09-09 07:17:42 -04:00
|
|
|
include RepoHelpers
|
|
|
|
|
2017-08-01 14:51:52 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-01-08 19:57:51 -05:00
|
|
|
let(:repository) { project.repository }
|
2015-04-21 09:13:40 -04:00
|
|
|
let(:commit) { project.commit(sample_commit.id) }
|
2016-07-27 13:00:34 -04:00
|
|
|
let(:diffs) { commit.raw_diffs }
|
2015-04-27 12:06:51 -04:00
|
|
|
let(:diff) { diffs.first }
|
2017-06-06 17:28:06 -04:00
|
|
|
let(:diff_refs) { commit.diff_refs }
|
2016-06-20 12:51:48 -04:00
|
|
|
let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: diff_refs, repository: repository) }
|
2014-09-09 07:17:42 -04:00
|
|
|
|
2016-04-14 17:32:46 -04:00
|
|
|
describe 'diff_view' do
|
2017-07-28 08:59:57 -04:00
|
|
|
it 'uses the view param over the cookie' do
|
|
|
|
controller.params[:view] = 'parallel'
|
|
|
|
helper.request.cookies[:diff_view] = 'inline'
|
|
|
|
|
|
|
|
expect(helper.diff_view).to eq :parallel
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the default value when the view param is invalid' do
|
|
|
|
controller.params[:view] = 'invalid'
|
|
|
|
|
|
|
|
expect(helper.diff_view).to eq :inline
|
|
|
|
end
|
|
|
|
|
2016-04-14 17:32:46 -04:00
|
|
|
it 'returns a valid value when cookie is set' do
|
|
|
|
helper.request.cookies[:diff_view] = 'parallel'
|
|
|
|
|
2016-07-21 14:44:12 -04:00
|
|
|
expect(helper.diff_view).to eq :parallel
|
2016-04-14 17:32:46 -04:00
|
|
|
end
|
|
|
|
|
2017-07-28 08:59:57 -04:00
|
|
|
it 'returns the default value when cookie is invalid' do
|
2016-04-14 17:32:46 -04:00
|
|
|
helper.request.cookies[:diff_view] = 'invalid'
|
|
|
|
|
2016-07-21 14:44:12 -04:00
|
|
|
expect(helper.diff_view).to eq :inline
|
2016-04-14 17:32:46 -04:00
|
|
|
end
|
|
|
|
|
2017-07-28 08:59:57 -04:00
|
|
|
it 'returns the default value when cookie is nil' do
|
2016-04-14 17:32:46 -04:00
|
|
|
expect(helper.request.cookies).to be_empty
|
|
|
|
|
2016-07-21 14:44:12 -04:00
|
|
|
expect(helper.diff_view).to eq :inline
|
2016-04-14 17:32:46 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-21 14:44:12 -04:00
|
|
|
|
2016-03-03 12:38:44 -05:00
|
|
|
describe 'diff_options' do
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'returns no collapse false' do
|
2017-05-26 19:27:30 -04:00
|
|
|
expect(diff_options).to include(expanded: false)
|
2016-07-15 03:04:18 -04:00
|
|
|
end
|
|
|
|
|
2017-05-26 19:27:30 -04:00
|
|
|
it 'returns no collapse true if expanded' do
|
|
|
|
allow(controller).to receive(:params) { { expanded: true } }
|
|
|
|
expect(diff_options).to include(expanded: true)
|
2016-07-15 03:04:18 -04:00
|
|
|
end
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'returns no collapse true if action name diff_for_path' do
|
2016-07-15 03:04:18 -04:00
|
|
|
allow(controller).to receive(:action_name) { 'diff_for_path' }
|
2017-05-26 19:27:30 -04:00
|
|
|
expect(diff_options).to include(expanded: true)
|
2016-07-15 03:04:18 -04:00
|
|
|
end
|
2016-07-27 13:00:34 -04:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns paths if action name diff_for_path and param old path' do
|
2016-07-27 13:00:34 -04:00
|
|
|
allow(controller).to receive(:params) { { old_path: 'lib/wadus.rb' } }
|
|
|
|
allow(controller).to receive(:action_name) { 'diff_for_path' }
|
|
|
|
expect(diff_options[:paths]).to include('lib/wadus.rb')
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'returns paths if action name diff_for_path and param new path' do
|
2016-07-27 13:00:34 -04:00
|
|
|
allow(controller).to receive(:params) { { new_path: 'lib/wadus.rb' } }
|
|
|
|
allow(controller).to receive(:action_name) { 'diff_for_path' }
|
|
|
|
expect(diff_options[:paths]).to include('lib/wadus.rb')
|
|
|
|
end
|
2015-04-27 12:06:51 -04:00
|
|
|
end
|
|
|
|
|
2016-01-30 06:53:12 -05:00
|
|
|
describe '#diff_line_content' do
|
2016-12-02 03:48:32 -05:00
|
|
|
context 'when the line is empty' do
|
|
|
|
it 'returns a non breaking space' do
|
|
|
|
expect(diff_line_content(nil)).to eq(' ')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an HTML-safe string' do
|
|
|
|
expect(diff_line_content(nil)).to be_html_safe
|
|
|
|
end
|
2014-09-09 07:17:42 -04:00
|
|
|
end
|
|
|
|
|
2016-12-02 03:48:32 -05:00
|
|
|
context 'when the line is not empty' do
|
|
|
|
context 'when the line starts with +, -, or a space' do
|
|
|
|
it 'strips the first character' do
|
|
|
|
expect(diff_line_content('+new line')).to eq('new line')
|
|
|
|
expect(diff_line_content('-new line')).to eq('new line')
|
|
|
|
expect(diff_line_content(' new line')).to eq('new line')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the line is HTML-safe' do
|
|
|
|
it 'returns an HTML-safe string' do
|
|
|
|
expect(diff_line_content('+new line'.html_safe)).to be_html_safe
|
|
|
|
expect(diff_line_content('-new line'.html_safe)).to be_html_safe
|
|
|
|
expect(diff_line_content(' new line'.html_safe)).to be_html_safe
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the line is not HTML-safe' do
|
|
|
|
it 'returns a non-HTML-safe string' do
|
|
|
|
expect(diff_line_content('+new line')).not_to be_html_safe
|
|
|
|
expect(diff_line_content('-new line')).not_to be_html_safe
|
|
|
|
expect(diff_line_content(' new line')).not_to be_html_safe
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the line does not start with a +, -, or a space' do
|
|
|
|
it 'returns the string' do
|
|
|
|
expect(diff_line_content('@@ -6,12 +6,18 @@ module Popen')).to eq('@@ -6,12 +6,18 @@ module Popen')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the line is HTML-safe' do
|
|
|
|
it 'returns an HTML-safe string' do
|
|
|
|
expect(diff_line_content('@@ -6,12 +6,18 @@ module Popen'.html_safe)).to be_html_safe
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the line is not HTML-safe' do
|
|
|
|
it 'returns a non-HTML-safe string' do
|
|
|
|
expect(diff_line_content('@@ -6,12 +6,18 @@ module Popen')).not_to be_html_safe
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-01-14 16:38:37 -05:00
|
|
|
end
|
2016-01-30 06:53:12 -05:00
|
|
|
end
|
|
|
|
|
2020-11-12 13:09:26 -05:00
|
|
|
describe "#diff_link_number" do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
let(:line) do
|
|
|
|
double(:line, type: line_type)
|
|
|
|
end
|
|
|
|
|
|
|
|
# This helper is used to generate the line numbers on the
|
|
|
|
# diff lines. It essentially just returns a blank string
|
|
|
|
# on the old/new lines. The following table tests all the
|
|
|
|
# possible permutations for clarity.
|
|
|
|
|
|
|
|
where(:line_type, :match, :line_number, :expected_return_value) do
|
|
|
|
"new" | "new" | 1 | " "
|
|
|
|
"new" | "old" | 2 | 2
|
|
|
|
"old" | "new" | 3 | 3
|
|
|
|
"old" | "old" | 4 | " "
|
|
|
|
"new-nonewline" | "new" | 5 | 5
|
|
|
|
"new-nonewline" | "old" | 6 | 6
|
|
|
|
"old-nonewline" | "new" | 7 | 7
|
|
|
|
"old-nonewline" | "old" | 8 | 8
|
|
|
|
"match" | "new" | 9 | 9
|
|
|
|
"match" | "old" | 10 | 10
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it "returns the expected value" do
|
|
|
|
expect(helper.diff_link_number(line.type, match, line_number)).to eq(expected_return_value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-30 06:53:12 -05:00
|
|
|
describe "#mark_inline_diffs" do
|
|
|
|
let(:old_line) { %{abc 'def'} }
|
|
|
|
let(:new_line) { %{abc "def"} }
|
|
|
|
|
|
|
|
it "returns strings with marked inline diffs" do
|
|
|
|
marked_old_line, marked_new_line = mark_inline_diffs(old_line, new_line)
|
2016-01-14 16:38:37 -05:00
|
|
|
|
2021-02-01 07:09:03 -05:00
|
|
|
expect(marked_old_line).to eq(%q{abc <span class="idiff left deletion">'</span>def<span class="idiff right deletion">'</span>})
|
2017-09-12 13:42:40 -04:00
|
|
|
expect(marked_old_line).to be_html_safe
|
2021-02-01 07:09:03 -05:00
|
|
|
expect(marked_new_line).to eq(%q{abc <span class="idiff left addition">"</span>def<span class="idiff right addition">"</span>})
|
2017-09-12 13:42:40 -04:00
|
|
|
expect(marked_new_line).to be_html_safe
|
2014-09-09 07:17:42 -04:00
|
|
|
end
|
2018-04-03 05:57:31 -04:00
|
|
|
|
|
|
|
context 'when given HTML' do
|
|
|
|
it 'sanitizes it' do
|
|
|
|
old_line = %{test.txt}
|
|
|
|
new_line = %{<img src=x onerror=alert(document.domain)>}
|
|
|
|
|
|
|
|
marked_old_line, marked_new_line = mark_inline_diffs(old_line, new_line)
|
|
|
|
|
|
|
|
expect(marked_old_line).to eq(%q{<span class="idiff left right deletion">test.txt</span>})
|
|
|
|
expect(marked_old_line).to be_html_safe
|
|
|
|
expect(marked_new_line).to eq(%q{<span class="idiff left right addition"><img src=x onerror=alert(document.domain)></span>})
|
|
|
|
expect(marked_new_line).to be_html_safe
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sanitizes the entire line, not just the changes' do
|
|
|
|
old_line = %{<img src=x onerror=alert(document.domain)>}
|
|
|
|
new_line = %{<img src=y onerror=alert(document.domain)>}
|
|
|
|
|
|
|
|
marked_old_line, marked_new_line = mark_inline_diffs(old_line, new_line)
|
|
|
|
|
|
|
|
expect(marked_old_line).to eq(%q{<img src=<span class="idiff left right deletion">x</span> onerror=alert(document.domain)>})
|
|
|
|
expect(marked_old_line).to be_html_safe
|
|
|
|
expect(marked_new_line).to eq(%q{<img src=<span class="idiff left right addition">y</span> onerror=alert(document.domain)>})
|
|
|
|
expect(marked_new_line).to be_html_safe
|
|
|
|
end
|
|
|
|
end
|
2014-09-09 07:17:42 -04:00
|
|
|
end
|
2016-07-21 14:44:12 -04:00
|
|
|
|
2017-05-30 16:38:06 -04:00
|
|
|
describe '#parallel_diff_discussions' do
|
2017-06-01 05:07:06 -04:00
|
|
|
let(:discussion) { { 'abc_3_3' => 'comment' } }
|
|
|
|
let(:diff_file) { double(line_code: 'abc_3_3') }
|
|
|
|
|
|
|
|
before do
|
2017-05-30 16:38:06 -04:00
|
|
|
helper.instance_variable_set(:@grouped_diff_discussions, discussion)
|
2017-06-01 05:07:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not put comments on nonewline lines' do
|
2017-05-30 16:38:06 -04:00
|
|
|
left = Gitlab::Diff::Line.new('\\nonewline', 'old-nonewline', 3, 3, 3)
|
|
|
|
right = Gitlab::Diff::Line.new('\\nonewline', 'new-nonewline', 3, 3, 3)
|
|
|
|
|
|
|
|
result = helper.parallel_diff_discussions(left, right, diff_file)
|
|
|
|
|
|
|
|
expect(result).to eq([nil, nil])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'puts comments on added lines' do
|
|
|
|
left = Gitlab::Diff::Line.new('\\nonewline', 'old-nonewline', 3, 3, 3)
|
2017-06-19 12:25:21 -04:00
|
|
|
right = Gitlab::Diff::Line.new('new line', 'new', 3, 3, 3)
|
2017-05-30 16:38:06 -04:00
|
|
|
|
|
|
|
result = helper.parallel_diff_discussions(left, right, diff_file)
|
|
|
|
|
|
|
|
expect(result).to eq([nil, 'comment'])
|
|
|
|
end
|
2017-06-19 12:25:21 -04:00
|
|
|
|
|
|
|
it 'puts comments on unchanged lines' do
|
|
|
|
left = Gitlab::Diff::Line.new('unchanged line', nil, 3, 3, 3)
|
|
|
|
right = Gitlab::Diff::Line.new('unchanged line', nil, 3, 3, 3)
|
|
|
|
|
|
|
|
result = helper.parallel_diff_discussions(left, right, diff_file)
|
|
|
|
|
|
|
|
expect(result).to eq(['comment', nil])
|
|
|
|
end
|
2017-05-30 16:38:06 -04:00
|
|
|
end
|
|
|
|
|
2016-07-21 14:44:12 -04:00
|
|
|
describe "#diff_match_line" do
|
|
|
|
let(:old_pos) { 40 }
|
|
|
|
let(:new_pos) { 50 }
|
|
|
|
let(:text) { 'some_text' }
|
|
|
|
|
2016-08-11 11:30:18 -04:00
|
|
|
it "generates foldable top match line for inline view with empty text by default" do
|
2016-07-21 14:44:12 -04:00
|
|
|
output = diff_match_line old_pos, new_pos
|
|
|
|
|
|
|
|
expect(output).to be_html_safe
|
|
|
|
expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.old_line[data-linenumber='#{old_pos}']", text: '...'
|
|
|
|
expect(output).to have_css "td:nth-child(2):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.new_line[data-linenumber='#{new_pos}']", text: '...'
|
|
|
|
expect(output).to have_css 'td:nth-child(3):not(.parallel).line_content.match', text: ''
|
|
|
|
end
|
|
|
|
|
2016-08-11 11:30:18 -04:00
|
|
|
it "allows to define text and bottom option" do
|
2016-07-21 14:44:12 -04:00
|
|
|
output = diff_match_line old_pos, new_pos, text: text, bottom: true
|
|
|
|
|
|
|
|
expect(output).to be_html_safe
|
|
|
|
expect(output).to have_css "td:nth-child(1).diff-line-num.unfold.js-unfold.js-unfold-bottom.old_line[data-linenumber='#{old_pos}']", text: '...'
|
|
|
|
expect(output).to have_css "td:nth-child(2).diff-line-num.unfold.js-unfold.js-unfold-bottom.new_line[data-linenumber='#{new_pos}']", text: '...'
|
|
|
|
expect(output).to have_css 'td:nth-child(3):not(.parallel).line_content.match', text: text
|
|
|
|
end
|
|
|
|
|
2016-08-11 11:30:18 -04:00
|
|
|
it "generates match line for parallel view" do
|
2016-07-21 14:44:12 -04:00
|
|
|
output = diff_match_line old_pos, new_pos, text: text, view: :parallel
|
|
|
|
|
|
|
|
expect(output).to be_html_safe
|
|
|
|
expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.old_line[data-linenumber='#{old_pos}']", text: '...'
|
|
|
|
expect(output).to have_css 'td:nth-child(2).line_content.match.parallel', text: text
|
|
|
|
expect(output).to have_css "td:nth-child(3):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.new_line[data-linenumber='#{new_pos}']", text: '...'
|
|
|
|
expect(output).to have_css 'td:nth-child(4).line_content.match.parallel', text: text
|
|
|
|
end
|
|
|
|
|
2016-08-11 11:30:18 -04:00
|
|
|
it "allows to generate only left match line for parallel view" do
|
2016-07-21 14:44:12 -04:00
|
|
|
output = diff_match_line old_pos, nil, text: text, view: :parallel
|
|
|
|
|
|
|
|
expect(output).to be_html_safe
|
|
|
|
expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.old_line[data-linenumber='#{old_pos}']", text: '...'
|
|
|
|
expect(output).to have_css 'td:nth-child(2).line_content.match.parallel', text: text
|
|
|
|
expect(output).not_to have_css 'td:nth-child(3)'
|
|
|
|
end
|
|
|
|
|
2016-08-11 11:30:18 -04:00
|
|
|
it "allows to generate only right match line for parallel view" do
|
2016-07-21 14:44:12 -04:00
|
|
|
output = diff_match_line nil, new_pos, text: text, view: :parallel
|
|
|
|
|
|
|
|
expect(output).to be_html_safe
|
|
|
|
expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.new_line[data-linenumber='#{new_pos}']", text: '...'
|
|
|
|
expect(output).to have_css 'td:nth-child(2).line_content.match.parallel', text: text
|
|
|
|
expect(output).not_to have_css 'td:nth-child(3)'
|
|
|
|
end
|
|
|
|
end
|
2017-06-06 17:28:06 -04:00
|
|
|
|
2020-02-06 16:08:48 -05:00
|
|
|
describe '#render_overflow_warning?' do
|
2021-04-14 11:09:04 -04:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
2019-12-16 16:08:00 -05:00
|
|
|
let(:diffs_collection) { instance_double(Gitlab::Diff::FileCollection::MergeRequestDiff, raw_diff_files: diff_files) }
|
2019-11-29 10:06:43 -05:00
|
|
|
let(:diff_files) { Gitlab::Git::DiffCollection.new(files) }
|
|
|
|
let(:safe_file) { { too_large: false, diff: '' } }
|
|
|
|
let(:large_file) { { too_large: true, diff: '' } }
|
|
|
|
let(:files) { [safe_file, safe_file] }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(diff_files).to receive(:overflow?).and_return(false)
|
2021-04-14 11:09:04 -04:00
|
|
|
allow(diff_files).to receive(:overflow_max_bytes?).and_return(false)
|
|
|
|
allow(diff_files).to receive(:overflow_max_files?).and_return(false)
|
|
|
|
allow(diff_files).to receive(:overflow_max_lines?).and_return(false)
|
|
|
|
allow(diff_files).to receive(:collapsed_safe_bytes?).and_return(false)
|
|
|
|
allow(diff_files).to receive(:collapsed_safe_files?).and_return(false)
|
|
|
|
allow(diff_files).to receive(:collapsed_safe_lines?).and_return(false)
|
2019-11-29 10:06:43 -05:00
|
|
|
end
|
|
|
|
|
2021-04-14 11:09:04 -04:00
|
|
|
context 'when no limits are hit' do
|
2019-11-29 10:06:43 -05:00
|
|
|
it 'returns false and does not log any overflow events' do
|
|
|
|
expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_collection_limits)
|
|
|
|
expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_single_file_limits)
|
2021-04-14 11:09:04 -04:00
|
|
|
expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_max_bytes_limits)
|
|
|
|
expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_max_files_limits)
|
|
|
|
expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_max_lines_limits)
|
|
|
|
expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_collapsed_bytes_limits)
|
|
|
|
expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_collapsed_files_limits)
|
|
|
|
expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_collapsed_lines_limits)
|
|
|
|
|
|
|
|
expect(render_overflow_warning?(diffs_collection)).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
where(:overflow_method, :event_name) do
|
|
|
|
:overflow_max_bytes? | :diffs_overflow_max_bytes_limits
|
|
|
|
:overflow_max_files? | :diffs_overflow_max_files_limits
|
|
|
|
:overflow_max_lines? | :diffs_overflow_max_lines_limits
|
|
|
|
:collapsed_safe_bytes? | :diffs_overflow_collapsed_bytes_limits
|
|
|
|
:collapsed_safe_files? | :diffs_overflow_collapsed_files_limits
|
|
|
|
:collapsed_safe_lines? | :diffs_overflow_collapsed_lines_limits
|
|
|
|
end
|
2019-11-29 10:06:43 -05:00
|
|
|
|
2021-04-14 11:09:04 -04:00
|
|
|
with_them do
|
|
|
|
it 'returns false and only logs the correct collection overflow event' do
|
|
|
|
allow(diff_files).to receive(overflow_method).and_return(true)
|
|
|
|
expect(Gitlab::Metrics).to receive(:add_event).with(event_name).once
|
2019-11-29 10:06:43 -05:00
|
|
|
expect(render_overflow_warning?(diffs_collection)).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the file collection has an overflow' do
|
|
|
|
before do
|
|
|
|
allow(diff_files).to receive(:overflow?).and_return(true)
|
|
|
|
end
|
|
|
|
|
2021-04-14 11:09:04 -04:00
|
|
|
it 'returns true and only logs all the correct collection overflow event' do
|
|
|
|
expect(Gitlab::Metrics).to receive(:add_event).with(:diffs_overflow_collection_limits).once
|
2019-11-29 10:06:43 -05:00
|
|
|
|
|
|
|
expect(render_overflow_warning?(diffs_collection)).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when two individual files are too big' do
|
|
|
|
let(:files) { [safe_file, large_file, large_file] }
|
|
|
|
|
|
|
|
it 'returns false and only logs single file overflow events' do
|
|
|
|
expect(Gitlab::Metrics).to receive(:add_event).with(:diffs_overflow_single_file_limits).exactly(:once)
|
|
|
|
expect(Gitlab::Metrics).not_to receive(:add_event).with(:diffs_overflow_collection_limits)
|
|
|
|
|
|
|
|
expect(render_overflow_warning?(diffs_collection)).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-02 11:09:08 -04:00
|
|
|
describe '#diff_file_html_data' do
|
|
|
|
let(:project) { build(:project) }
|
|
|
|
let(:path) { 'path/to/file' }
|
|
|
|
let(:sha) { '1234567890' }
|
|
|
|
|
|
|
|
subject do
|
|
|
|
helper.diff_file_html_data(project, path, sha)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns data for project files' do
|
|
|
|
expect(subject).to include(blob_diff_path: helper.project_blob_diff_path(project, "#{sha}/#{path}"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-06 16:08:48 -05:00
|
|
|
describe '#diff_file_path_text' do
|
2018-01-08 05:45:56 -05:00
|
|
|
it 'returns full path by default' do
|
|
|
|
expect(diff_file_path_text(diff_file)).to eq(diff_file.new_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns truncated path' do
|
|
|
|
expect(diff_file_path_text(diff_file, max: 10)).to eq("...open.rb")
|
|
|
|
end
|
|
|
|
end
|
2021-02-03 16:09:17 -05:00
|
|
|
|
|
|
|
describe "#collapsed_diff_url" do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
controller: "projects/commit",
|
|
|
|
action: "show",
|
|
|
|
namespace_id: "foo",
|
|
|
|
project_id: "bar",
|
|
|
|
id: commit.sha
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { helper.collapsed_diff_url(diff_file) }
|
|
|
|
|
|
|
|
it "returns a valid URL" do
|
|
|
|
allow(helper).to receive(:safe_params).and_return(params)
|
|
|
|
|
|
|
|
expect(subject).to match(/foo\/bar\/-\/commit\/#{commit.sha}\/diff_for_path/)
|
|
|
|
end
|
|
|
|
end
|
2021-02-16 10:09:50 -05:00
|
|
|
|
|
|
|
describe "#render_fork_suggestion" do
|
|
|
|
subject { helper.render_fork_suggestion }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "user signed in" do
|
|
|
|
let(:current_user) { build(:user) }
|
|
|
|
|
|
|
|
it "renders the partial" do
|
|
|
|
expect(helper).to receive(:render).with(partial: "projects/fork_suggestion").exactly(:once)
|
|
|
|
|
|
|
|
5.times { subject }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "guest" do
|
|
|
|
let(:current_user) { nil }
|
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
|
|
|
end
|
2014-09-09 07:17:42 -04:00
|
|
|
end
|