Sha256: 6ba35cbc8877ce3612d0d8f3cf28477fa9253ec4702eea9c074ed26e7c89a5c3

Contents?: true

Size: 1.92 KB

Versions: 6

Compression:

Stored size: 1.92 KB

Contents

require File.expand_path('../../test_helper', File.dirname(__FILE__))

class HelperTagTest < ActiveSupport::TestCase
  
  def test_initialize_tag
    assert tag = ComfortableMexicanSofa::Tag::Helper.initialize_tag(
      cms_pages(:default), '{{ cms:helper:method_name }}'
    )
    assert_equal 'method_name', tag.identifier
    assert tag = ComfortableMexicanSofa::Tag::Helper.initialize_tag(
      cms_pages(:default), '{{ cms:helper:method-name }}'
    )
    assert_equal 'method-name', tag.identifier
  end
  
  def test_initialize_tag_with_parameters
    assert tag = ComfortableMexicanSofa::Tag::Helper.initialize_tag(
      cms_pages(:default), '{{ cms:helper:method_name:param1:param2 }}'
    )
    assert_equal 'method_name', tag.identifier
    assert_equal ['param1', 'param2'], tag.params
  end

  def test_initialize_tag_with_complex_parameters
    assert tag = ComfortableMexicanSofa::Tag::Helper.initialize_tag(
      cms_pages(:default), '{{ cms:helper:method_name:param1:"param:2" }}'
    )
    assert_equal 'method_name', tag.identifier
    assert_equal ['param1', 'param:2'], tag.params

  end
  
  def test_initialize_tag_failure
    [
      '{{cms:helper}}',
      '{{cms:not_helper:method_name}}',
      '{not_a_tag}'
    ].each do |tag_signature|
      assert_nil ComfortableMexicanSofa::Tag::Helper.initialize_tag(
        cms_pages(:default), tag_signature
      )
    end
  end
  
  def test_content_and_render
    tag = ComfortableMexicanSofa::Tag::Helper.initialize_tag(
      cms_pages(:default), '{{cms:helper:method_name}}'
    )
    assert_equal "<%= method_name() %>", tag.content
    assert_equal "<%= method_name() %>", tag.render
    
    tag = ComfortableMexicanSofa::Tag::Helper.initialize_tag(
      cms_pages(:default), '{{cms:helper:method_name:param1:param2}}'
    )
    assert_equal "<%= method_name('param1', 'param2') %>", tag.content
    assert_equal "<%= method_name('param1', 'param2') %>", tag.render
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.6.11 test/unit/tags/helper_test.rb
comfortable_mexican_sofa-1.6.10 test/unit/tags/helper_test.rb
comfortable_mexican_sofa-1.6.9 test/unit/tags/helper_test.rb
comfortable_mexican_sofa-1.6.8 test/unit/tags/helper_test.rb
comfortable_mexican_sofa-1.6.7 test/unit/tags/helper_test.rb
comfortable_mexican_sofa-1.6.6 test/unit/tags/helper_test.rb