summaryrefslogtreecommitdiff
path: root/spec/presenters/blob_presenter_spec.rb
diff options
context:
space:
mode:
authorPatrick Bajao <ebajao@gitlab.com>2019-08-05 17:44:13 +0800
committerPatrick Bajao <ebajao@gitlab.com>2019-08-06 09:32:29 +0800
commit46631e102366bd40bdb449b87fae3f10e992ee68 (patch)
tree7dd1ffe71cc632f8175c291638ff35d1f40613e3 /spec/presenters/blob_presenter_spec.rb
parentfa216b0e86433192ba4e39a05f42217fb4685173 (diff)
downloadgitlab-ce-46631e102366bd40bdb449b87fae3f10e992ee68.tar.gz
Support selective highlighting of lines65152-selective-highlight
Instead of highlighting all lines when not all of them are needed, only highlight specific lines. The `BlobPresenter#highlight` method has been updated to support `since` and `to` params. These params will be used to limit the content to be highlighted. Modify `Gitlab::Highlight` to support `since` param which will then be used to determine the starting line number.
Diffstat (limited to 'spec/presenters/blob_presenter_spec.rb')
-rw-r--r--spec/presenters/blob_presenter_spec.rb52
1 files changed, 49 insertions, 3 deletions
diff --git a/spec/presenters/blob_presenter_spec.rb b/spec/presenters/blob_presenter_spec.rb
index eacf383be7d..95db2ba6a0d 100644
--- a/spec/presenters/blob_presenter_spec.rb
+++ b/spec/presenters/blob_presenter_spec.rb
@@ -28,24 +28,70 @@ describe BlobPresenter, :seed_helper do
subject { described_class.new(blob) }
it 'returns highlighted content' do
- expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', git_blob.data, plain: nil, language: nil)
+ expect(Gitlab::Highlight)
+ .to receive(:highlight)
+ .with(
+ 'files/ruby/regex.rb',
+ git_blob.data,
+ since: nil,
+ plain: nil,
+ language: nil
+ )
subject.highlight
end
it 'returns plain content when :plain is true' do
- expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', git_blob.data, plain: true, language: nil)
+ expect(Gitlab::Highlight)
+ .to receive(:highlight)
+ .with(
+ 'files/ruby/regex.rb',
+ git_blob.data,
+ since: nil,
+ plain: true,
+ language: nil
+ )
subject.highlight(plain: true)
end
+ context '"since" and "to" are present' do
+ before do
+ allow(git_blob)
+ .to receive(:data)
+ .and_return("line one\nline two\nline 3\nline 4")
+ end
+
+ it 'returns limited highlighted content' do
+ expect(Gitlab::Highlight)
+ .to receive(:highlight)
+ .with(
+ 'files/ruby/regex.rb',
+ "line two\nline 3\n",
+ since: 2,
+ language: nil,
+ plain: nil
+ )
+
+ subject.highlight(since: 2, to: 3)
+ end
+ end
+
context 'gitlab-language contains a match' do
before do
allow(blob).to receive(:language_from_gitattributes).and_return('ruby')
end
it 'passes language to inner call' do
- expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', git_blob.data, plain: nil, language: 'ruby')
+ expect(Gitlab::Highlight)
+ .to receive(:highlight)
+ .with(
+ 'files/ruby/regex.rb',
+ git_blob.data,
+ since: nil,
+ plain: nil,
+ language: 'ruby'
+ )
subject.highlight
end