summaryrefslogtreecommitdiff
path: root/spec/lib/banzai/filter/output_safety_spec.rb
blob: 5ffe591c9a46cd41ea75c278c52a15accbb7f5b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

require 'spec_helper'

describe Banzai::Filter::OutputSafety do
  subject do
    Class.new do
      include Banzai::Filter::OutputSafety
    end.new
  end

  let(:content) { '<pre><code>foo</code></pre>' }

  context 'when given HTML is safe' do
    let(:html) { content.html_safe }

    it 'returns safe HTML' do
      expect(subject.escape_once(html)).to eq(html)
    end
  end

  context 'when given HTML is not safe' do
    let(:html) { content }

    it 'returns escaped HTML' do
      expect(subject.escape_once(html)).to eq(ERB::Util.html_escape_once(html))
    end
  end
end