#!/usr/bin/env ruby require 'test/unit' currentPath = File.dirname(__FILE__) require File.join( currentPath, '../../lib/masterview' ) #require File.join( currentPath, '../../lib/masterview/directives/form') require File.join( currentPath, '../directive_test_helper' ) DirectiveTestHelpers.load_masterview_directive('form') class TestForm < Test::Unit::TestCase include DirectiveTestHelpers Form = MasterView::Directives::Form # test subject ELEMENT_TAG = 'form' def test_metadata assert_equal MasterView::ConfigSettings.namespace_prefix, Form.namespace_prefix assert_equal 'form', Form.attribute_name end def test_default create_template_element ELEMENT_TAG attr_value = ":action => 'create'" create_directive Form, attr_value assert_equal "<%= form_tag( :action => 'create' ) %>", render_element_event(:stag) assert_equal "", render_element_event(:etag) end def test_get create_template_element ELEMENT_TAG, :attributes => { 'method' => 'get' } attr_value = ":action => 'create'" create_directive Form, attr_value assert_equal "<%= form_tag( { :action => 'create' }, :method => \"get\" ) %>", render_element_event(:stag) end def test_get_uppercase create_template_element ELEMENT_TAG, :attributes => { 'method' => 'GET'} attr_value = ":action => 'create'" create_directive Form, attr_value assert_equal "<%= form_tag( { :action => 'create' }, :method => \"GET\" ) %>", render_element_event(:stag) end def test_post create_template_element ELEMENT_TAG, :attributes => { 'method' => 'post' } attr_value = ":action => 'create'" create_directive Form, attr_value assert_equal "<%= form_tag( { :action => 'create' }, :method => \"post\" ) %>", render_element_event(:stag) end def test_post_uppercase create_template_element ELEMENT_TAG, :attributes => { 'method' => 'POST' } attr_value = ":action => 'create'" create_directive Form, attr_value assert_equal "<%= form_tag( { :action => 'create' }, :method => \"POST\" ) %>", render_element_event(:stag) end def test_put create_template_element ELEMENT_TAG, :attributes => { 'method' => 'put' } attr_value = ":action => 'update'" create_directive Form, attr_value assert_equal "<%= form_tag( { :action => 'update' }, :method => \"put\" ) %>", render_element_event(:stag) end def test_put_uppercase create_template_element ELEMENT_TAG, :attributes => { 'method' => 'PUT' } attr_value = ":action => 'update'" create_directive Form, attr_value assert_equal "<%= form_tag( { :action => 'update' }, :method => \"PUT\" ) %>", render_element_event(:stag) end def test_multipart_form create_template_element ELEMENT_TAG, :attributes => { 'method' => 'post', 'enctype' => 'multipart/form-data' } attr_value = ":action => 'create'" create_directive Form, attr_value assert_equal "<%= form_tag( { :action => 'create' }, :method => \"post\", :multipart => true ) %>", render_element_event(:stag) end def test_multipart_form_uppercase create_template_element ELEMENT_TAG, :attributes => { 'method' => 'post', 'enctype' => 'MULTIPART/FORM-DATA' } attr_value = ":action => 'create'" create_directive Form, attr_value assert_equal "<%= form_tag( { :action => 'create' }, :method => \"post\", :multipart => true ) %>", render_element_event(:stag) end # test for using string for action def test_string_action create_template_element ELEMENT_TAG attr_value = "'/create'" create_directive Form, attr_value assert_equal "<%= form_tag( '/create' ) %>", render_element_event(:stag) assert_equal "", render_element_event(:etag) end def test_string_action2 create_template_element ELEMENT_TAG attr_value = "'/create/foo'" create_directive Form, attr_value assert_equal "<%= form_tag( '/create/foo' ) %>", render_element_event(:stag) assert_equal "", render_element_event(:etag) end def test_string_action_get create_template_element ELEMENT_TAG, :attributes => { 'method' => 'get' } attr_value = "'/foo/create'" create_directive Form, attr_value assert_equal "<%= form_tag( '/foo/create', :method => \"get\" ) %>", render_element_event(:stag) end # test for using parameters def test_params create_template_element ELEMENT_TAG, :attributes => { 'method' => 'get' } attr_value = "{:action => 'create'}, {}, foo, bar" create_directive Form, attr_value assert_equal "<%= form_tag( {:action => 'create'}, {:method => \"get\"}, foo, bar ) %>", render_element_event(:stag) end end