Sha256: 451ae9b60401f8806d99d06c401f07743a82d903767eebbb0d0427ac27a7cf49

Contents?: true

Size: 1.88 KB

Versions: 9

Compression:

Stored size: 1.88 KB

Contents

require_relative '../../test_helper'

class TemplateTagTest < ActiveSupport::TestCase

  def test_initialize_tag
    assert tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
      cms_pages(:default), '{{ cms:template:template_name }}'
    )
    assert_equal 'template_name', tag.identifier
    assert tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
      cms_pages(:default), '{{cms:template:path/to/template}}'
    )
    assert_equal 'path/to/template', tag.identifier
    assert tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
      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(
        cms_pages(:default), tag_signature
      )
    end
  end

  def test_content_and_render
    tag = ComfortableMexicanSofa::Tag::Template.initialize_tag(
      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(
      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(
      cms_pages(:default), '{{cms:template:unsafe/path}}'
    )
    assert_equal "<%= render :template => 'unsafe/path' %>", tag.content
    assert_equal nil, tag.render
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.11.2 test/lib/tags/template_test.rb
comfortable_mexican_sofa-1.11.1 test/lib/tags/template_test.rb
comfortable_mexican_sofa-1.11.0 test/lib/tags/template_test.rb
comfortable_mexican_sofa-1.10.3 test/lib/tags/template_test.rb
comfortable_mexican_sofa-1.10.2 test/lib/tags/template_test.rb
comfortable_mexican_sofa-1.10.1 test/lib/tags/template_test.rb
comfortable_mexican_sofa-1.10.0 test/lib/tags/template_test.rb
comfortable_mexican_sofa-1.9.3 test/models/tags/template_test.rb
comfortable_mexican_sofa-1.9.2 test/models/tags/template_test.rb