diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2019-08-07 17:50:05 -0300 |
---|---|---|
committer | Samantha Ming <sming@gitlab.com> | 2019-08-09 13:16:11 -0700 |
commit | 3c7dcfaf42ad90a7ed93e410fb74c3a609403cc5 (patch) | |
tree | 0c743abde227cd1b8001f986e3ea8c2d5fff64cc | |
parent | f7c26231e4b6ddd470cb1cc963bfc1008a6d09eb (diff) | |
download | gitlab-ce-58035-expand-mr-diff.tar.gz |
Avoid returning bottom match when reaching bottom limit58035-expand-mr-diff
-rw-r--r-- | app/presenters/blobs/unfold_presenter.rb | 1 | ||||
-rw-r--r-- | spec/presenters/blobs/unfold_presenter_spec.rb | 37 |
2 files changed, 36 insertions, 2 deletions
diff --git a/app/presenters/blobs/unfold_presenter.rb b/app/presenters/blobs/unfold_presenter.rb index 5976f730314..4c6dd6895cf 100644 --- a/app/presenters/blobs/unfold_presenter.rb +++ b/app/presenters/blobs/unfold_presenter.rb @@ -81,6 +81,7 @@ module Blobs def add_match_line(diff_lines) return unless unfold? + return if bottom? && to >= all_lines_size if bottom? && to < all_lines_size old_pos = to - offset diff --git a/spec/presenters/blobs/unfold_presenter_spec.rb b/spec/presenters/blobs/unfold_presenter_spec.rb index 46be9fe87eb..ab3f8080257 100644 --- a/spec/presenters/blobs/unfold_presenter_spec.rb +++ b/spec/presenters/blobs/unfold_presenter_spec.rb @@ -98,8 +98,9 @@ describe Blobs::UnfoldPresenter do end end - context 'when since is greater than 1' do - let(:params) { { since: 5, to: 10, offset: 10 } } + context 'when "since" is greater than 1' do + let(:default_params) { { since: 5, to: 10, offset: 10 } } + let(:params) { default_params } it 'adds top match line' do line = subject.diff_lines.first @@ -108,6 +109,38 @@ describe Blobs::UnfoldPresenter do expect(line.old_pos).to eq(5) expect(line.new_pos).to eq(5) end + + context '"to" is higher than blob size' do + let(:params) { default_params.merge(to: total_lines + 10, bottom: true) } + + it 'does not add bottom match line' do + line = subject.diff_lines.last + + expect(line.type).to be_nil + end + end + + context '"to" is equal to blob size' do + let(:params) { default_params.merge(to: total_lines, bottom: true) } + + it 'does not add bottom match line' do + line = subject.diff_lines.last + + expect(line.type).to be_nil + end + end + + context '"to" is less than blob size' do + let(:params) { default_params.merge(to: total_lines - 3, bottom: true) } + + it 'adds bottom match line' do + line = subject.diff_lines.last + + expect(line.type).to eq('match') + expect(line.old_pos).to eq(total_lines - 3 - params[:offset]) + expect(line.new_pos).to eq(total_lines - 3) + end + end end context 'when "to" is less than blob size' do |