Sha256: 789ad329f65a37969dbcb0c5f7bb1755bccd2cc7292ef4d256fbd0da942aa2a7

Contents?: true

Size: 1.79 KB

Versions: 6

Compression:

Stored size: 1.79 KB

Contents

#!/usr/bin/env ruby

require 'test/unit'
currentPath = File.dirname(__FILE__)
require File.join( currentPath, '../../lib/masterview' )
require File.join( currentPath, '../../lib/masterview/directives/attr')

class TestAttr < Test::Unit::TestCase
  include MasterView::Directives

  def setup
    @directives = MasterView::DirectiveSet.new
    @tag = MasterView::Tag.new(@directives, 'foo', {'bar' => 'cat'}, :normal, nil)
  end

  def test_hello
    @directives.directives = []
    attr_value = "{:hello => 'world'}"
    @directives << Attr.new(attr_value)
    dcs = @directives.determine_dcs(:stag)
    dcs.context = @tag.create_context
    assert_equal '', dcs.render.join
    assert_equal 'cat', dcs.context[:tag].attributes['bar']
    assert_equal 'world', dcs.context[:tag].attributes['hello']
  end

  def test_hello_hi
    @directives.directives = []
    attr_value = ":hello => 'world', :hi => 'there'"
    @directives << Attr.new(attr_value)
    dcs = @directives.determine_dcs(:stag)
    dcs.context = @tag.create_context
    assert_equal '', dcs.render.join
    assert_equal 'cat', dcs.context[:tag].attributes['bar']
    assert_equal 'world', dcs.context[:tag].attributes['hello']
    assert_equal 'there', dcs.context[:tag].attributes['hi']
  end

  def test_hello_erb
    @directives.directives = []
    attr_value = %q":hello => 'world', :hi => 'there', :wow => #{h product.name}"
    @directives << Attr.new(attr_value)
    dcs = @directives.determine_dcs(:stag)
    dcs.context = @tag.create_context
    assert_equal '', dcs.render.join
    assert_equal 'cat', dcs.context[:tag].attributes['bar']
    assert_equal 'world', dcs.context[:tag].attributes['hello']
    assert_equal 'there', dcs.context[:tag].attributes['hi']
    assert_equal '{{{= h product.name }}}', dcs.context[:tag].attributes['wow']
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
masterview-0.2.1 test/unit/directive_attr_test.rb
masterview-0.2.0 test/unit/directive_attr_test.rb
masterview-0.2.2 test/unit/directive_attr_test.rb
masterview-0.2.3 test/unit/directive_attr_test.rb
masterview-0.2.4 test/unit/directive_attr_test.rb
masterview-0.2.5 test/unit/directive_attr_test.rb