Sha256: fca33de992b5c5fb56c2b7a098e52253c6b817c0858fc8f846e3aa39ddd3afb3

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

require_relative '../../test_helper'

class TemplateTagTest < ActiveSupport::TestCase

  def test_initialize_tag
    assert tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
      comfy_cms_pages(:default), '{{ cms:template:template_name }}'
    )
    assert_equal 'template_name', tag.identifier
    assert tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
      comfy_cms_pages(:default), '{{cms:template:path/to/template}}'
    )
    assert_equal 'path/to/template', tag.identifier
    assert tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
      comfy_cms_pages(:default), '{{cms:template:path/to/dashed-template}}'
    )
    assert_equal 'path/to/dashed-template', tag.identifier
  end

  def test_initialize_tag_failure
    [
      '{{cms:template}}',
      '{{cms:not_template:label}}',
      '{not_a_tag}'
    ].each do |tag_signature|
      assert_nil ComfortableMexicanSofa::Tag::Template.initialize_tag(
        comfy_cms_pages(:default), tag_signature
      )
    end
  end

  def test_content_and_render
    tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
      comfy_cms_pages(:default), '{{cms:template:path/to/template}}'
    )
    assert_equal "<%= render :template => 'path/to/template' %>", tag.content
    assert_equal "<%= render :template => 'path/to/template' %>", tag.render
  end

  def test_whitelisted_paths
    ComfortableMexicanSofa.config.allowed_templates = ['safe/path']

    tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
      comfy_cms_pages(:default), '{{cms:template:safe/path}}'
    )
    assert_equal "<%= render :template => 'safe/path' %>", tag.content
    assert_equal "<%= render :template => 'safe/path' %>", tag.render

    tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
      comfy_cms_pages(:default), '{{cms:template:unsafe/path}}'
    )
    assert_equal "<%= render :template => 'unsafe/path' %>", tag.content
    assert_nil tag.render
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.12.11 test/lib/tags/template_test.rb
comfortable_mexican_sofa-1.12.10 test/lib/tags/template_test.rb