diff options
Diffstat (limited to 'spec/presenters/snippet_blob_presenter_spec.rb')
-rw-r--r-- | spec/presenters/snippet_blob_presenter_spec.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/presenters/snippet_blob_presenter_spec.rb b/spec/presenters/snippet_blob_presenter_spec.rb new file mode 100644 index 00000000000..2a113e353c8 --- /dev/null +++ b/spec/presenters/snippet_blob_presenter_spec.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe SnippetBlobPresenter do + describe '#highlighted_data' do + let(:snippet) { build(:personal_snippet) } + + subject { described_class.new(snippet.blob).highlighted_data } + + it 'returns nil when the snippet blob is binary' do + allow(snippet.blob).to receive(:binary?).and_return(true) + + expect(subject).to be_nil + end + + it 'returns markdown content when snippet file is markup' do + snippet.file_name = 'test.md' + snippet.content = '*foo*' + + expect(subject).to eq '<p data-sourcepos="1:1-1:5" dir="auto"><em>foo</em></p>' + end + + it 'returns syntax highlighted content' do + snippet.file_name = 'test.rb' + snippet.content = 'class Foo;end' + + expect(subject) + .to eq '<span id="LC1" class="line" lang="ruby"><span class="k">class</span> <span class="nc">Foo</span><span class="p">;</span><span class="k">end</span></span>' + end + + it 'returns plain text highlighted content' do + snippet.file_name = 'test' + snippet.content = 'foo' + + expect(described_class.new(snippet.blob).highlighted_data).to eq '<span id="LC1" class="line" lang="plaintext">foo</span>' + end + end + + describe '#raw_path' do + subject { described_class.new(snippet.blob).raw_path } + + context 'with ProjectSnippet' do + let!(:project) { create(:project) } + let(:snippet) { build(:project_snippet, project: project, id: 1) } + + it 'returns the raw path' do + expect(subject).to eq "/#{snippet.project.full_path}/snippets/1/raw" + end + end + + context 'with PersonalSnippet' do + let(:snippet) { build(:personal_snippet, id: 1) } + + it 'returns the raw path' do + expect(subject).to eq "/snippets/1/raw" + end + end + end +end |