File: escapable_spec.rb

package info (click to toggle)
ruby-temple 0.10.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 476 kB
  • sloc: ruby: 3,347; makefile: 6
file content (49 lines) | stat: -rw-r--r-- 1,361 bytes parent folder | download | duplicates (2)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'spec_helper'

describe Temple::Filters::Escapable do
  before do
    @filter = Temple::Filters::Escapable.new
  end

  it 'should handle escape expressions' do
    expect(@filter.call([:escape, true,
                  [:multi,
                   [:static, "a < b"],
                   [:dynamic, "ruby_method"]]
    ])).to eq [:multi,
      [:static, "a &lt; b"],
      [:dynamic, "::Temple::Utils.escape_html((ruby_method))"],
    ]
  end

  it 'should keep codes intact' do
    exp = [:multi, [:code, 'foo']]
    expect(@filter.call(exp)).to eq(exp)
  end

  it 'should keep statics intact' do
    exp = [:multi, [:static, '<']]
    expect(@filter.call(exp)).to eq(exp)
  end

  it 'should keep dynamic intact' do
    exp = [:multi, [:dynamic, 'foo']]
    expect(@filter.call(exp)).to eq(exp)
  end

  it 'should have use_html_safe option' do
    with_html_safe do
      filter = Temple::Filters::Escapable.new(use_html_safe: true)
      expect(filter.call([:escape, true,
        [:static, Temple::HTML::SafeString.new("a < b")]
      ])).to eq [:static, "a < b"]
    end
  end

  it 'should support censoring' do
    filter = Temple::Filters::Escapable.new(escape_code: '(%s).gsub("Temple sucks", "Temple rocks")')
    expect(filter.call([:escape, true,
      [:static, "~~ Temple sucks ~~"]
    ])).to eq [:static, "~~ Temple rocks ~~"]
  end
end