From 32f9cf8ce3dd337bf3b1683c5872171c253f0d27 Mon Sep 17 00:00:00 2001 From: Mark Chao Date: Thu, 6 Sep 2018 17:48:57 +0800 Subject: Add BlobPresenter for highlighting Force FoundBlob to use BlobPresenter --- spec/presenters/blob_presenter_spec.rb | 60 ++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 spec/presenters/blob_presenter_spec.rb (limited to 'spec/presenters') diff --git a/spec/presenters/blob_presenter_spec.rb b/spec/presenters/blob_presenter_spec.rb new file mode 100644 index 00000000000..5c83fa39d80 --- /dev/null +++ b/spec/presenters/blob_presenter_spec.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe BlobPresenter, :seed_helper do + let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '') } + + let(:git_blob) do + Gitlab::Git::Blob.find( + repository, + 'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6', + 'files/ruby/regex.rb' + ) + end + let(:blob) { Blob.new(git_blob) } + + describe '#highlight' 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: false, language: nil) + + subject.highlight + end + + context 'with :plain' do + it 'returns plain content when no_highlighting? is true' do + allow(blob).to receive(:no_highlighting?).and_return(true) + + 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) + + subject.highlight(plain: true) + end + + it 'returns plain content when :plain is false, but no_highlighting? is true' do + allow(blob).to receive(:no_highlighting?).and_return(true) + + expect(Gitlab::Highlight).to receive(:highlight).with('files/ruby/regex.rb', git_blob.data, plain: true, language: nil) + + subject.highlight(plain: false) + 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: false, language: 'ruby') + + subject.highlight + end + end + end +end -- cgit v1.2.1