Commit 925da3fd authored by Douwe Maan's avatar Douwe Maan

Merge branch 'rs-wiki-pipeline-spec' into 'master'

Add a spec for WikiPipeline

Removes the specs from GollumTagsFilter that were more like integration
tests for the pipeline than unit tests of the filter.

See merge request !3054
parents 3231ea10 def6446d
...@@ -26,6 +26,10 @@ module Banzai ...@@ -26,6 +26,10 @@ module Banzai
# * [[http://example.com/images/logo.png]] # * [[http://example.com/images/logo.png]]
# * [[http://example.com/images/logo.png|alt=Logo]] # * [[http://example.com/images/logo.png|alt=Logo]]
# #
# - Insert a Table of Contents list:
#
# * [[_TOC_]]
#
# Based on Gollum::Filter::Tags # Based on Gollum::Filter::Tags
# #
# Context options: # Context options:
...@@ -61,8 +65,6 @@ module Banzai ...@@ -61,8 +65,6 @@ module Banzai
# before this one, it will be converted into `[[<em>TOC</em>]]`, so it # before this one, it will be converted into `[[<em>TOC</em>]]`, so it
# needs special-case handling # needs special-case handling
if toc_tag?(node) if toc_tag?(node)
next unless result[:toc].present?
process_toc_tag(node) process_toc_tag(node)
else else
content = node.content content = node.content
...@@ -85,7 +87,7 @@ module Banzai ...@@ -85,7 +87,7 @@ module Banzai
# Replace an entire `[[<em>TOC</em>]]` node with the result generated by # Replace an entire `[[<em>TOC</em>]]` node with the result generated by
# TableOfContentsFilter # TableOfContentsFilter
def process_toc_tag(node) def process_toc_tag(node)
node.parent.parent.replace(result[:toc]) node.parent.parent.replace(result[:toc].presence || '')
end end
# Process a single tag into its final HTML form. # Process a single tag into its final HTML form.
......
...@@ -88,54 +88,17 @@ describe Banzai::Filter::GollumTagsFilter, lib: true do ...@@ -88,54 +88,17 @@ describe Banzai::Filter::GollumTagsFilter, lib: true do
end end
context 'table of contents' do context 'table of contents' do
let(:pipeline) { Banzai::Pipeline[:wiki] } it 'replaces [[<em>TOC</em>]] with ToC result' do
doc = described_class.call("<p>[[<em>TOC</em>]]</p>", { project_wiki: project_wiki }, { toc: "FOO" })
it 'replaces the tag with the TableOfContentsFilter result' do expect(doc.to_html).to eq("FOO")
markdown = <<-MD.strip_heredoc
[[_TOC_]]
## Header
Foo
MD
result = pipeline.call(markdown, project_wiki: project_wiki, project: project)
aggregate_failures do
expect(result[:output].text).not_to include '[[_TOC_]]'
expect(result[:output].text).not_to include '[['
expect(result[:output].to_html).to include(result[:toc])
end
end
it 'is case-sensitive' do
markdown = <<-MD.strip_heredoc
[[_toc_]]
# Header 1
Foo
MD
output = pipeline.to_html(markdown, project_wiki: project_wiki, project: project)
expect(output).to include('[[<em>toc</em>]]')
end end
it 'handles an empty pipeline result' do it 'handles an empty ToC result' do
# No Markdown headers in this doc, so `result[:toc]` will be empty input = "<p>[[<em>TOC</em>]]</p>"
markdown = <<-MD.strip_heredoc doc = described_class.call(input, project_wiki: project_wiki)
[[_TOC_]]
Foo
MD
output = pipeline.to_html(markdown, project_wiki: project_wiki, project: project)
aggregate_failures do expect(doc.to_html).to eq ''
expect(output).not_to include('<ul>')
expect(output).to include('[[<em>TOC</em>]]')
end
end end
end end
end end
require 'rails_helper'
describe Banzai::Pipeline::WikiPipeline do
describe 'TableOfContents' do
it 'replaces the tag with the TableOfContentsFilter result' do
markdown = <<-MD.strip_heredoc
[[_TOC_]]
## Header
Foo
MD
result = described_class.call(markdown, project: spy, project_wiki: double)
aggregate_failures do
expect(result[:output].text).not_to include '[['
expect(result[:output].text).not_to include 'TOC'
expect(result[:output].to_html).to include(result[:toc])
end
end
it 'is case-sensitive' do
markdown = <<-MD.strip_heredoc
[[_toc_]]
# Header 1
Foo
MD
output = described_class.to_html(markdown, project: spy, project_wiki: double)
expect(output).to include('[[<em>toc</em>]]')
end
it 'handles an empty pipeline result' do
# No Markdown headers in this doc, so `result[:toc]` will be empty
markdown = <<-MD.strip_heredoc
[[_TOC_]]
Foo
MD
output = described_class.to_html(markdown, project: spy, project_wiki: double)
aggregate_failures do
expect(output).not_to include('<ul>')
expect(output).not_to include('[[<em>TOC</em>]]')
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment