From dfac1cea3d851000116a23ab14c2b1ae981f7a12 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 6 Mar 2005 11:50:41 +0000 Subject: Fixed that form helpers would treat string and symbol keys differently in html_options (and possibly create duplicate entries) #112 [bitsweat] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@833 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../test/template/active_record_helper_test.rb | 2 +- actionpack/test/template/form_helper_test.rb | 57 ++++++++++++---------- .../test/template/form_options_helper_test.rb | 24 +++++---- actionpack/test/template/form_tag_helper_test.rb | 5 +- actionpack/test/template/tag_helper_test.rb | 13 +++-- actionpack/test/template/text_helper_test.rb | 14 +++--- actionpack/test/template/url_helper_test.rb | 23 ++++++--- 7 files changed, 80 insertions(+), 58 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb index e650b4f0b8..67001082b8 100644 --- a/actionpack/test/template/active_record_helper_test.rb +++ b/actionpack/test/template/active_record_helper_test.rb @@ -48,7 +48,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase @controller = Class.new do def url_for(options, *parameters_for_method_reference) - options[:action] + options[:action] || options["action"] end end @controller = @controller.new diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 6b1deb575e..7f7f473564 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -15,7 +15,7 @@ class FormHelperTest < Test::Unit::TestCase $VERBOSE = old_verbose def setup - @post = Post.new + @post = Post.new def @post.errors() Class.new{ def on(field) field == "author_name" end }.new end def @post.id; 123; end @@ -47,31 +47,29 @@ class FormHelperTest < Test::Unit::TestCase end def test_text_field_with_options - assert_equal( - '', - text_field("post", "title", "size" => "35") - ) + expected = '' + assert_equal expected, text_field("post", "title", "size" => 35) + assert_equal expected, text_field("post", "title", :size => 35) end - + def test_text_field_assuming_size - assert_equal( - '', - text_field("post", "title", "maxlength" => 35) - ) + expected = '' + assert_equal expected, text_field("post", "title", "maxlength" => 35) + assert_equal expected, text_field("post", "title", :maxlength => 35) end - + def test_check_box assert_equal( '', check_box("post", "secret") ) - + @post.secret = 0 assert_equal( '', - check_box("post", "secret") + check_box("post", "secret") ) - + @post.secret = true assert_equal( '', @@ -81,20 +79,20 @@ class FormHelperTest < Test::Unit::TestCase def test_radio_button assert_equal('', - radio_button("post", "title", "Hello World") + radio_button("post", "title", "Hello World") ) assert_equal('', - radio_button("post", "title", "Goodbye World") + radio_button("post", "title", "Goodbye World") ) end - + def test_text_area assert_equal( '', text_area("post", "body") ) end - + def test_text_area_with_escapes @post.body = "Back to the hill and over it again!" assert_equal( @@ -109,12 +107,11 @@ class FormHelperTest < Test::Unit::TestCase text_area("post", "body") ) end - - + def test_explicit_name assert_equal( '', text_field("post", "title", "name" => "dont guess") - ) + ) assert_equal( '', text_area("post", "body", "name" => "really!") @@ -123,12 +120,18 @@ class FormHelperTest < Test::Unit::TestCase '', check_box("post", "secret", "name" => "i mean it") ) + assert_equal text_field("post", "title", "name" => "dont guess"), + text_field("post", "title", :name => "dont guess") + assert_equal text_area("post", "body", "name" => "really!"), + text_area("post", "body", :name => "really!") + assert_equal check_box("post", "secret", "name" => "i mean it"), + check_box("post", "secret", :name => "i mean it") end - + def test_explicit_id assert_equal( '', text_field("post", "title", "id" => "dont guess") - ) + ) assert_equal( '', text_area("post", "body", "id" => "really!") @@ -137,6 +140,12 @@ class FormHelperTest < Test::Unit::TestCase '', check_box("post", "secret", "id" => "i mean it") ) + assert_equal text_field("post", "title", "id" => "dont guess"), + text_field("post", "title", :id => "dont guess") + assert_equal text_area("post", "body", "id" => "really!"), + text_area("post", "body", :id => "really!") + assert_equal check_box("post", "secret", "id" => "i mean it"), + check_box("post", "secret", :id => "i mean it") end def test_auto_index @@ -159,7 +168,5 @@ class FormHelperTest < Test::Unit::TestCase assert_equal("", radio_button("post[]", "title", "Goodbye World") ) - end - end diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 4203ab7079..a94f81a728 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -46,7 +46,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase ) end - + def test_collection_options_with_preselected_value @posts = [ Post.new(" went home", "", "To a little house", "shh!"), @@ -75,14 +75,14 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_array_options_for_select assert_equal( - "\n\n", + "\n\n", options_for_select([ "", "USA", "Sweden" ]) ) end def test_array_options_for_select_with_selection assert_equal( - "\n\n", + "\n\n", options_for_select([ "Denmark", "", "Sweden" ], "") ) end @@ -96,21 +96,21 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_hash_options_for_select assert_equal( - "\n", + "\n", options_for_select({ "$" => "Dollar", "" => "" }) ) end def test_hash_options_for_select_with_selection assert_equal( - "\n", + "\n", options_for_select({ "$" => "Dollar", "" => "" }, "Dollar") ) end def test_hash_options_for_select_with_selection assert_equal( - "\n", + "\n", options_for_select({ "$" => "Dollar", "" => "" }, [ "Dollar", "" ]) ) end @@ -197,7 +197,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase @post = Post.new @post.category = "" assert_equal( - "", + "", select("post", "category", %w( abe hest)) ) end @@ -206,7 +206,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase @post = Post.new @post.category = "" assert_equal( - "", + "", select("post", "category", %w( abe hest), :include_blank => true) ) end @@ -222,7 +222,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase @post.author_name = "Babe" assert_equal( - "", + "", collection_select("post", "author_name", @posts, "author_name", "author_name") ) end @@ -238,7 +238,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase @post.author_name = "Babe" assert_equal( - "", + "", collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px") ) end @@ -291,6 +291,8 @@ class FormOptionsHelperTest < Test::Unit::TestCase "" + "", html + assert_equal html, time_zone_select("firm", "time_zone", nil, {}, + :style => "color: red") end def test_time_zone_select_with_blank_and_style @@ -306,6 +308,8 @@ class FormOptionsHelperTest < Test::Unit::TestCase "" + "", html + assert_equal html, time_zone_select("firm", "time_zone", nil, + { :include_blank => true }, :style => "color: red") end def test_time_zone_select_with_priority_zones diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 6036dd4b50..8fd6300b82 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -11,12 +11,13 @@ class FormTagHelperTest < Test::Unit::TestCase %(hidden_field_tag "id", 3) => %(), %(password_field_tag) => %(), %(text_area_tag("body", "hello world", :size => "20x40")) => %(), + %(text_area_tag("body", "hello world", "size" => "20x40")) => %(), %(check_box_tag("admin")) => %(), %(radio_button_tag("people", "david")) => %(), %(select_tag("people", "")) => %(), } def test_tags - MethodToTag.each { |method, tag| assert_equal(eval(method), tag) } + MethodToTag.each { |method, tag| assert_equal(tag, eval(method)) } end -end \ No newline at end of file +end diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb index 2db1bac238..9d8d2644e8 100644 --- a/actionpack/test/template/tag_helper_test.rb +++ b/actionpack/test/template/tag_helper_test.rb @@ -8,23 +8,26 @@ class TagHelperTest < Test::Unit::TestCase def test_tag assert_equal "

", tag("p", "class" => "show") + assert_equal tag("p", "class" => "show"), tag("p", :class => "show") end - + def test_content_tag assert_equal "Create", content_tag("a", "Create", "href" => "create") + assert_equal content_tag("a", "Create", "href" => "create"), + content_tag("a", "Create", :href => "create") end def test_mail_to_with_javascript - assert_equal "", mail_to("me@domain.com", "My email", :encode => "javascript") + assert_equal "", mail_to("me@domain.com", "My email", :encode => "javascript") end def test_mail_to_with_hex - assert_equal "My email", mail_to("me@domain.com", "My email", :encode => "hex") + assert_equal "My email", mail_to("me@domain.com", "My email", :encode => "hex") end def test_mail_to - assert_equal "My email", mail_to("me@domain.com", "My email") + assert_equal "My email", mail_to("me@domain.com", "My email") end # FIXME: Test form tag -end \ No newline at end of file +end diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 2082f4aae8..aba0d99699 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -8,11 +8,11 @@ class TextHelperTest < Test::Unit::TestCase assert_equal "Hello World!", truncate("Hello World!", 12) assert_equal "Hello Worl...", truncate("Hello World!!", 12) end - + def test_strip_links assert_equal "on my mind", strip_links("on my mind") end - + def test_highlighter assert_equal( "This is a beautiful morning", @@ -29,7 +29,7 @@ class TextHelperTest < Test::Unit::TestCase highlight("This is a beautiful morning, but also a beautiful day", "beautiful", '\1') ) end - + def test_highlighter_with_regexp assert_equal( "This is a beautiful! morning", @@ -46,7 +46,7 @@ class TextHelperTest < Test::Unit::TestCase highlight("This is a beautiful? morning", "beautiful? morning") ) end - + def test_excerpt assert_equal("...is a beautiful morni...", excerpt("This is a beautiful morning", "beautiful", 5)) assert_equal("This is a...", excerpt("This is a beautiful morning", "this", 5)) @@ -54,16 +54,16 @@ class TextHelperTest < Test::Unit::TestCase assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", 5)) assert_nil excerpt("This is a beautiful morning", "day") end - + def test_pluralization assert_equal("1 count", pluralize(1, "count")) assert_equal("2 counts", pluralize(2, "count")) end - + def test_auto_linking assert_equal %(hello david@loudthinking.com), auto_link("hello david@loudthinking.com", :email_addresses) assert_equal %(Go to http://www.rubyonrails.com), auto_link("Go to http://www.rubyonrails.com", :urls) assert_equal %(Go to http://www.rubyonrails.com), auto_link("Go to http://www.rubyonrails.com", :email_addresses) assert_equal %(Go to http://www.rubyonrails.com and say hello to david@loudthinking.com), auto_link("Go to http://www.rubyonrails.com and say hello to david@loudthinking.com") end -end \ No newline at end of file +end diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 6e94d98ebe..379db0b9b7 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -21,26 +21,31 @@ class UrlHelperTest < Test::Unit::TestCase def test_link_tag_with_straight_url assert_equal "Hello", link_to("Hello", "http://www.world.com") end - + def test_link_tag_with_javascript_confirm assert_equal( - "Hello", + "Hello", link_to("Hello", "http://www.world.com", :confirm => "Are you sure?") ) end - + def test_link_to_image assert_equal( - "\"Rss\"", + "\"Rss\"", link_to_image("rss", "http://www.world.com", "size" => "30x45") ) assert_equal( - "\"Feed\"", + "\"Feed\"", link_to_image("rss.gif", "http://www.world.com", "size" => "30x45", "alt" => "Feed", "class" => "admin") ) + + assert_equal link_to_image("rss", "http://www.world.com", "size" => "30x45"), + link_to_image("rss", "http://www.world.com", :size => "30x45") + assert_equal link_to_image("rss.gif", "http://www.world.com", "size" => "30x45", "alt" => "Feed", "class" => "admin"), + link_to_image("rss.gif", "http://www.world.com", :size => "30x45", :alt => "Feed", :class => "admin") end - + def test_link_unless_current @request = RequestMock.new("http://www.world.com") assert_equal "Showing", link_to_unless_current("Showing", :action => "show", :controller => "weblog") @@ -55,11 +60,13 @@ class UrlHelperTest < Test::Unit::TestCase assert_equal "david@loudthinking.com", mail_to("david@loudthinking.com") assert_equal "David Heinemeier Hansson", mail_to("david@loudthinking.com", "David Heinemeier Hansson") assert_equal( - "David Heinemeier Hansson", + "David Heinemeier Hansson", mail_to("david@loudthinking.com", "David Heinemeier Hansson", "class" => "admin") ) + assert_equal mail_to("david@loudthinking.com", "David Heinemeier Hansson", "class" => "admin"), + mail_to("david@loudthinking.com", "David Heinemeier Hansson", :class => "admin") end - + def test_link_with_nil_html_options assert_equal "Hello", link_to("Hello", {:action => 'myaction'}, nil) end -- cgit v1.2.3