Sha256: 450d371445386f355d064e47e3f0f3408aeef726aaa870eaa108c7954b93cbab

Contents?: true

Size: 1.34 KB

Versions: 53

Compression:

Stored size: 1.34 KB

Contents

require 'helper'

class HtmlSafeString < String
  def html_safe?
    true
  end
end

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

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

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

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

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

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

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

Version data entries

53 entries across 53 versions & 2 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
classiccms-0.7.4 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
classiccms-0.7.3 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
classiccms-0.7.2 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
classiccms-0.7.1 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
classiccms-0.7.0 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
temple-0.6.0 test/filters/test_escapable.rb
classiccms-0.6.9 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
classiccms-0.6.8 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
classiccms-0.6.7 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
classiccms-0.6.6 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
classiccms-0.6.5 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
classiccms-0.6.4 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
temple-0.5.5 test/filters/test_escapable.rb
classiccms-0.6.3 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
classiccms-0.6.2 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
classiccms-0.6.1 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
classiccms-0.6.0 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb
temple-0.5.4 test/filters/test_escapable.rb
classiccms-0.5.17 vendor/bundle/gems/temple-0.4.0/test/filters/test_escapable.rb