Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added more FormTagHelper test cases #860 [Eric Hodel]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@925 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit f32cbb52a5be6b454d4b718b91910a84bfbc1ee0 1 parent b2cfbc4
@dhh dhh authored
Showing with 78 additions and 16 deletions.
  1. +78 −16 actionpack/test/template/form_tag_helper_test.rb
View
94 actionpack/test/template/form_tag_helper_test.rb
@@ -1,23 +1,85 @@
-require 'test/unit'
-require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_tag_helper'
+require File.dirname(__FILE__) + '/../abstract_unit'
class FormTagHelperTest < Test::Unit::TestCase
+
+ include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::FormTagHelper
- MethodToTag = {
- %(text_field_tag("title", "Hello!")) => %(<input id="title" name="title" type="text" value="Hello!" />),
- %(text_field_tag("title", "Hello!", "class" => "admin")) => %(<input class="admin" id="title" name="title" type="text" value="Hello!" />),
- %(hidden_field_tag "id", 3) => %(<input id="id" name="id" type="hidden" value="3" />),
- %(password_field_tag) => %(<input id="password" name="password" type="password" value="" />),
- %(text_area_tag("body", "hello world", :size => "20x40")) => %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>),
- %(text_area_tag("body", "hello world", "size" => "20x40")) => %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>),
- %(check_box_tag("admin")) => %(<input id="admin" name="admin" type="checkbox" value="1" />),
- %(radio_button_tag("people", "david")) => %(<input id="people" name="people" type="radio" value="david" />),
- %(select_tag("people", "<option>david</option>")) => %(<select id="people" name="people"><option>david</option></select>),
- }
-
- def test_tags
- MethodToTag.each { |method, tag| assert_equal(tag, eval(method)) }
+ def setup
+ @controller = Class.new do
+ def url_for(options, *parameters_for_method_reference)
+ "http://www.example.com"
+ end
+ end
+ @controller = @controller.new
+ end
+
+ def test_check_box_tag
+ actual = check_box_tag "admin"
+ expected = %(<input id="admin" name="admin" type="checkbox" value="1" />)
+ assert_equal expected, actual
+ end
+
+ def test_form_tag
+ actual = form_tag
+ expected = %(<form action="http://www.example.com" method="post">)
+ assert_equal expected, actual
+ end
+
+ def test_form_tag_multipart
+ actual = form_tag({}, { 'multipart' => true })
+ expected = %(<form action="http://www.example.com" enctype="multipart/form-data" method="post">)
+ assert_equal expected, actual
+ end
+
+ def test_hidden_field_tag
+ actual = hidden_field_tag "id", 3
+ expected = %(<input id="id" name="id" type="hidden" value="3" />)
+ assert_equal expected, actual
+ end
+
+ def test_password_field_tag
+ actual = password_field_tag
+ expected = %(<input id="password" name="password" type="password" value="" />)
+ assert_equal expected, actual
+ end
+
+ def test_radio_button_tag
+ actual = radio_button_tag "people", "david"
+ expected = %(<input id="people" name="people" type="radio" value="david" />)
+ assert_equal expected, actual
end
+
+ def test_select_tag
+ actual = select_tag "people", "<option>david</option>"
+ expected = %(<select id="people" name="people"><option>david</option></select>)
+ assert_equal expected, actual
+ end
+
+ def test_text_area_tag_size_string
+ actual = text_area_tag "body", "hello world", "size" => "20x40"
+ expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
+ assert_equal expected, actual
+ end
+
+ def test_text_area_tag_size_symbol
+ actual = text_area_tag "body", "hello world", :size => "20x40"
+ expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
+ assert_equal expected, actual
+ end
+
+ def test_text_field_tag
+ actual = text_field_tag "title", "Hello!"
+ expected = %(<input id="title" name="title" type="text" value="Hello!" />)
+ assert_equal expected, actual
+ end
+
+ def test_text_field_tag_class_string
+ actual = text_field_tag "title", "Hello!", "class" => "admin"
+ expected = %(<input class="admin" id="title" name="title" type="text" value="Hello!" />)
+ assert_equal expected, actual
+ end
+
end
+
Please sign in to comment.
Something went wrong with that request. Please try again.