aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/form_helper_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-11-24 01:04:44 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-11-24 01:04:44 +0000
commitdb045dbbf60b53dbe013ef25554fd013baf88134 (patch)
tree257830e3c76458c8ff3d1329de83f32b23926028 /actionpack/test/template/form_helper_test.rb
downloadrails-db045dbbf60b53dbe013ef25554fd013baf88134.tar.gz
rails-db045dbbf60b53dbe013ef25554fd013baf88134.tar.bz2
rails-db045dbbf60b53dbe013ef25554fd013baf88134.zip
Initial
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/template/form_helper_test.rb')
-rw-r--r--actionpack/test/template/form_helper_test.rb124
1 files changed, 124 insertions, 0 deletions
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
new file mode 100644
index 0000000000..8f3d5ebb94
--- /dev/null
+++ b/actionpack/test/template/form_helper_test.rb
@@ -0,0 +1,124 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_helper'
+
+class FormHelperTest < Test::Unit::TestCase
+ include ActionView::Helpers::FormHelper
+
+ old_verbose, $VERBOSE = $VERBOSE, nil
+ Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on)
+ $VERBOSE = old_verbose
+
+ def setup
+ @post = Post.new
+ def @post.errors() Class.new{ def on(field) field == "author_name" end }.new end
+
+ @post.title = "Hello World"
+ @post.author_name = ""
+ @post.body = "Back to the hill and over it again!"
+ @post.secret = 1
+ @post.written_on = Date.new(2004, 6, 15)
+ end
+
+ def test_text_field
+ assert_equal(
+ '<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title")
+ )
+ assert_equal(
+ '<input id="post_title" name="post[title]" size="30" type="password" value="Hello World" />', password_field("post", "title")
+ )
+ assert_equal(
+ '<input id="person_name" name="person[name]" size="30" type="password" value="" />', password_field("person", "name")
+ )
+ end
+
+ def test_text_field_with_escapes
+ @post.title = "<b>Hello World</b>"
+ assert_equal(
+ '<input id="post_title" name="post[title]" size="30" type="text" value="&lt;b&gt;Hello World&lt;/b&gt;" />', text_field("post", "title")
+ )
+ end
+
+ def test_text_field_with_options
+ assert_equal(
+ '<input id="post_title" name="post[title]" size="35" type="text" value="Hello World" />',
+ text_field("post", "title", "size" => "35")
+ )
+ end
+
+ def test_text_field_assuming_size
+ assert_equal(
+ '<input id="post_title" maxlength="35" name="post[title]" size="35" type="text" value="Hello World" />',
+ text_field("post", "title", "maxlength" => 35)
+ )
+ end
+
+ def test_check_box
+ assert_equal(
+ '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
+ check_box("post", "secret")
+ )
+
+ @post.secret = 0
+ assert_equal(
+ '<input id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
+ check_box("post", "secret")
+ )
+
+ @post.secret = true
+ assert_equal(
+ '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
+ check_box("post", "secret")
+ )
+ end
+
+ def test_text_area
+ assert_equal(
+ '<textarea cols="40" id="post_body" name="post[body]" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>',
+ text_area("post", "body")
+ )
+ end
+
+ def test_text_area_with_escapes
+ @post.body = "Back to <i>the</i> hill and over it again!"
+ assert_equal(
+ '<textarea cols="40" id="post_body" name="post[body]" rows="20" wrap="virtual">Back to &lt;i&gt;the&lt;/i&gt; hill and over it again!</textarea>',
+ text_area("post", "body")
+ )
+ end
+
+ def test_date_selects
+ assert_equal(
+ '<textarea cols="40" id="post_body" name="post[body]" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>',
+ text_area("post", "body")
+ )
+ end
+
+
+ def test_explicit_name
+ assert_equal(
+ '<input id="post_title" name="dont guess" size="30" type="text" value="Hello World" />', text_field("post", "title", "name" => "dont guess")
+ )
+ assert_equal(
+ '<textarea cols="40" id="post_body" name="really!" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>',
+ text_area("post", "body", "name" => "really!")
+ )
+ assert_equal(
+ '<input checked="checked" id="post_secret" name="i mean it" type="checkbox" value="1" /><input name="i mean it" type="hidden" value="0" />',
+ check_box("post", "secret", "name" => "i mean it")
+ )
+ end
+
+ def test_explicit_id
+ assert_equal(
+ '<input id="dont guess" name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title", "id" => "dont guess")
+ )
+ assert_equal(
+ '<textarea cols="40" id="really!" name="post[body]" rows="20" wrap="virtual">Back to the hill and over it again!</textarea>',
+ text_area("post", "body", "id" => "really!")
+ )
+ assert_equal(
+ '<input checked="checked" id="i mean it" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
+ check_box("post", "secret", "id" => "i mean it")
+ )
+ end
+end