BigW Consortium Gitlab

description_pipeline_spec.rb 1.04 KB
Newer Older
1 2 3 4 5 6
require 'rails_helper'

describe Banzai::Pipeline::DescriptionPipeline do
  def parse(html)
    # When we pass HTML to Redcarpet, it gets wrapped in `p` tags...
    # ...except when we pass it pre-wrapped text. Rabble rabble.
7
    unwrap = !html.start_with?('<p ')
8 9 10

    output = described_class.to_html(html, project: spy)

11
    output.gsub!(%r{\A<p dir="auto">(.*)</p>(.*)\z}, '\1\2') if unwrap
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

    output
  end

  it 'uses a limited whitelist' do
    doc = parse('# Description')

    expect(doc.strip).to eq 'Description'
  end

  %w(pre code img ol ul li).each do |elem|
    it "removes '#{elem}' elements" do
      act = "<#{elem}>Description</#{elem}>"

      expect(parse(act).strip).to eq 'Description'
    end
  end

30
  %w(b i strong em a ins del sup sub).each do |elem|
31 32 33 34 35 36
    it "still allows '#{elem}' elements" do
      exp = act = "<#{elem}>Description</#{elem}>"

      expect(parse(act).strip).to eq exp
    end
  end
37 38 39 40 41 42

  it "still allows 'p' elements" do
    exp = act = "<p dir=\"auto\">Description</p>"

    expect(parse(act).strip).to eq exp
  end
43
end