Sha256: 1b18f199baadfbe24e180206559d4523c88aec5f7c07e935de4886416bc9e6b6

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

require 'helper'

class HtmlSafeString < String
  def html_safe?
    true
  end
end

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

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

  it 'should keep blocks intact' do
    exp = [:multi, [:block, 'foo']]
    @filter.compile(exp).should.equal exp
  end

  it 'should keep statics intact' do
    exp = [:multi, [:static, '<']]
    @filter.compile(exp).should.equal exp
  end

  it 'should keep dynamic intact' do
    exp = [:multi, [:dynamic, 'foo']]
    @filter.compile(exp).should.equal exp
  end

  it 'should have use_html_safe option' do
    filter = Temple::Filters::EscapeHTML.new(:use_html_safe => true)
    filter.compile([:multi,
      [:escape, :static, HtmlSafeString.new("a < b")],
    ]).should.equal [:multi,
      [:static, "a < b"],
    ]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
temple-0.1.8 test/filters/test_escape_html.rb
temple-0.1.7 test/filters/test_escape_html.rb
temple-0.1.6 test/filters/test_escape_html.rb