#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../../lib/masterview' ) #require File.join( currentPath, '../../lib/masterview/directives/text_area') require File.join( currentPath, '../directive_test_helper' ) DirectiveTestHelpers.load_masterview_directive('text_area') class TestTextArea < Test::Unit::TestCase include DirectiveTestHelpers TextArea = MasterView::Directives::TextArea # test subject ELEMENT_TAG = 'input' def test_metadata assert_equal MasterView::ConfigSettings.namespace_prefix, TextArea.namespace_prefix assert_equal 'text_area', TextArea.attribute_name end def create_element_with_text_area_directive(obj, method, other_attr_values, attributes) attr_value = "#{obj}, #{method}" attr_value << ', ' << other_attr_values unless other_attr_values.nil? input_tag = create_template_element ELEMENT_TAG, :attributes => attributes, :content => 'hello world' create_directive TextArea, attr_value assert_equal '', render_element_event(:stag) end def test_normal obj = ':product' method = ':price' create_element_with_text_area_directive(obj, method, nil, {} ) expected_content = "<%= text_area( #{obj}, #{method} ) %>" assert_equal expected_content, render_element_event(:etag) end def test_rows obj = ':product' method = ':price' create_element_with_text_area_directive(obj, method, nil, { 'rows' => '4'} ) expected_content = "<%= text_area( #{obj}, #{method}, :rows => 4 ) %>" assert_equal expected_content, render_element_event(:etag) end def test_cols obj = ':product' method = ':price' create_element_with_text_area_directive(obj, method, nil, { 'cols' => 6 } ) expected_content = "<%= text_area( #{obj}, #{method}, :cols => 6 ) %>" assert_equal expected_content, render_element_event(:etag) end def test_all obj = ':product' method = ':price' create_element_with_text_area_directive(obj, method, nil, { 'rows' => 4, 'cols' => 6, 'disabled' => 'disabled', 'readonly' => 'readonly', 'class' => 'classfoo', 'style' => 'stylebar', 'tabindex' => 'tab1', 'accesskey' => 'ak2' } ) expected_content = "<%= text_area( #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :cols => 6, :disabled => true, :readonly => true, :rows => 4, :style => \"stylebar\", :tabindex => \"tab1\" ) %>" assert_equal expected_content, render_element_event(:etag) end def test_all_uc obj = ':product' method = ':price' create_element_with_text_area_directive(obj, method, nil, { 'ROWS' => 4, 'COLS' => 6, 'DISABLED' => 'DISABLED', 'READONLY' => 'readonly', 'CLASS' => 'classfoo', 'STYLE' => 'stylebar', 'TABINDEX' => 'tab1', 'ACCESSKEY' => 'ak2' } ) expected_content = "<%= text_area( #{obj}, #{method}, :accesskey => \"ak2\", :class => \"classfoo\", :cols => 6, :disabled => true, :readonly => true, :rows => 4, :style => \"stylebar\", :tabindex => \"tab1\" ) %>" assert_equal expected_content, render_element_event(:etag) end end