From 7f26415d3c0e4101ce1569a499470e8a32dbfede Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 20 Sep 2005 07:54:55 +0000 Subject: Optimized tag_options to not sort keys, which is no longer necessary when assert_dom_equal and friend is available #1995 [skae]. Added assert_dom_equal and assert_dom_not_equal to compare tags generated by the helpers in an order-indifferent manner #1995 [skae] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2271 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 4 ++ actionpack/lib/action_controller/assertions.rb | 17 +++++- actionpack/lib/action_controller/base.rb | 1 + .../vendor/html-scanner/html/node.rb | 24 +++++++- .../lib/action_view/helpers/asset_tag_helper.rb | 2 +- actionpack/lib/action_view/helpers/tag_helper.rb | 19 +++--- actionpack/lib/action_view/helpers/url_helper.rb | 17 +++--- actionpack/test/controller/base_test.rb | 2 +- .../test/template/active_record_helper_test.rb | 18 +++--- actionpack/test/template/asset_tag_helper_test.rb | 36 ++++++----- actionpack/test/template/form_helper_test.rb | 70 +++++++++++----------- .../test/template/form_options_helper_test.rb | 68 ++++++++++----------- actionpack/test/template/form_tag_helper_test.rb | 30 +++++----- .../template/java_script_macros_helper_test.rb | 8 +-- actionpack/test/template/javascript_helper_test.rb | 56 ++++++++--------- .../test/template/upload_progress_helper_testx.rb | 14 ++--- actionpack/test/template/url_helper_test.rb | 62 +++++++++---------- 17 files changed, 248 insertions(+), 200 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index bec8430478..cfc966fa9c 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,9 @@ *SVN* +* Optimized tag_options to not sort keys, which is no longer necessary when assert_dom_equal and friend is available #1995 [skae] + +* Added assert_dom_equal and assert_dom_not_equal to compare tags generated by the helpers in an order-indifferent manner #1995 [skae] + * Fixed that Request#domain caused an exception if the domain header wasn't set in the original http request #1795 [Michael Koziarski] * Make the truncate() helper multi-byte safe (assuming $KCODE has been set to something other than "NONE") #2103 diff --git a/actionpack/lib/action_controller/assertions.rb b/actionpack/lib/action_controller/assertions.rb index ad70111f3b..1a501bcd74 100644 --- a/actionpack/lib/action_controller/assertions.rb +++ b/actionpack/lib/action_controller/assertions.rb @@ -248,7 +248,22 @@ module Test #:nodoc: tag = find_tag(opts) assert !tag, "expected no tag, but found tag matching #{opts.inspect} in:\n#{@response.body.inspect}" end - + + # test 2 html strings to be equivalent, i.e. identical up to reordering of attributes + def assert_dom_equal(expected, actual, message="") + expected_dom = HTML::Document.new(expected).root + actual_dom = HTML::Document.new(actual).root + full_message = build_message(message, " expected to be == to\n.", expected_dom.to_s, actual_dom.to_s) + assert_block(full_message) { expected_dom == actual_dom } + end + + # negated form of +assert_dom_equivalent+ + def assert_dom_not_equal(expected, actual, message="") + expected_dom = HTML::Document.new(expected).root + actual_dom = HTML::Document.new(actual).root + full_message = build_message(message, " expected to be != to\n.", expected_dom.to_s, actual_dom.to_s) + assert_block(full_message) { expected_dom != actual_dom } + end end end end diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 59160c3e81..9291129e3d 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -838,6 +838,7 @@ module ActionController #:nodoc: end def self.action_methods + #puts "action method: #{public_instance_methods.inspect}" @action_methods ||= (public_instance_methods - hidden_actions).inject({}) { |h, k| h[k] = true; h } end diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb index f0f94d19cc..016603a3e7 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb @@ -122,6 +122,18 @@ module HTML #:nodoc: def validate_conditions(conditions) Conditions === conditions ? conditions : Conditions.new(conditions) end + + def ==(node) + return false unless self.class == node.class && children.size == node.children.size + + equivalent = true + + children.size.times do |i| + equivalent &&= children[i] == node.children[i] + end + + equivalent + end class <tag("br") =>
# * tag("input", { "type" => "text"}) => - def tag(name, options = {}, open = false) - "<#{name}#{tag_options(options)}" + (open ? ">" : " />") + def tag(name, options = nil, open = false) + "<#{name}#{tag_options(options.stringify_keys) if options}" + (open ? ">" : " />") end # Examples: # * content_tag("p", "Hello world!") =>

Hello world!

# * content_tag("div", content_tag("p", "Hello world!"), "class" => "strong") => #

Hello world!

- def content_tag(name, content, options = {}) - "<#{name}#{tag_options(options)}>#{content}" + def content_tag(name, content, options = nil) + "<#{name}#{tag_options(options.stringify_keys) if options}>#{content}" end private def tag_options(options) - cleaned_options = options.reject { |key, value| value.nil? } - unless cleaned_options.empty? - " " + cleaned_options.symbolize_keys.map { |key, value| - %(#{key}="#{html_escape(value.to_s)}") - }.sort.join(" ") + if options + options.inject("") do |html_str, (key, value)| + value.nil? ? html_str : html_str << %( #{key}="#{html_escape(value)}") + end end end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index d154f7c00c..4b7a2270dc 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -39,16 +39,15 @@ module ActionView # link_to "Busy loop", { :action => "busy" }, :popup => ['new_window', 'height=300,width=600'] # link_to "Destroy account", { :action => "destroy" }, :confirm => "Are you sure?", :post => true def link_to(name, options = {}, html_options = nil, *parameters_for_method_reference) - html_options = (html_options || {}).stringify_keys - convert_options_to_javascript!(html_options) - if options.is_a?(String) - content_tag "a", name || options, (html_options || {}).merge("href" => options) + if html_options + html_options = html_options.stringify_keys + convert_options_to_javascript!(html_options) + tag_options = tag_options(html_options) else - content_tag( - "a", name || url_for(options, *parameters_for_method_reference), - (html_options || {}).merge("href" => url_for(options, *parameters_for_method_reference)) - ) + tag_options = nil end + url = options.is_a?(String) ? options : url_for(options, *parameters_for_method_reference) + "#{name||url}" end # Generates a form containing a sole button that submits to the @@ -236,7 +235,7 @@ module ActionView # Returns true if the current page uri is generated by the options passed (in url_for format). def current_page?(options) - url_for(options) == @request.request_uri + url_for(options) == @controller.request.request_uri end private diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 84ca1673e7..a0b6bc0c09 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -63,8 +63,8 @@ class ControllerInstanceTests < Test::Unit::TestCase @non_empty_controllers = [Controllers::NonEmptyController.new, Controllers::Submodule::ContainedNonEmptyController.new] - end + def test_action_methods @empty_controllers.each {|c| assert_equal({}, c.send(:action_methods), "#{c.class.controller_path} should be empty!")} @non_empty_controllers.each {|c| assert_equal({"public_action"=>true}, c.send(:action_methods), "#{c.class.controller_path} should not be empty!")} diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb index 6d416fedfb..acff1b5e40 100644 --- a/actionpack/test/template/active_record_helper_test.rb +++ b/actionpack/test/template/active_record_helper_test.rb @@ -60,27 +60,27 @@ class ActiveRecordHelperTest < Test::Unit::TestCase end def test_generic_input_tag - assert_equal( + assert_dom_equal( %(), input("post", "title") ) end def test_text_area_with_errors - assert_equal( + assert_dom_equal( %(
), text_area("post", "body") ) end def test_text_field_with_errors - assert_equal( + assert_dom_equal( %(
), text_field("post", "author_name") ) end def test_form_with_string - assert_equal( + assert_dom_equal( %(


\n


), form("post") ) @@ -90,7 +90,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase def to_param() id end def id() 1 end end - assert_equal( + assert_dom_equal( %(


\n


), form("post") ) @@ -99,7 +99,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase def test_form_with_date def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end - assert_equal( + assert_dom_equal( %(


\n\n\n

), form("post") ) @@ -109,19 +109,19 @@ class ActiveRecordHelperTest < Test::Unit::TestCase def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ] end @post.written_on = Time.gm(2004, 6, 15, 16, 30) - assert_equal( + assert_dom_equal( %(


\n\n\n — \n : \n

), form("post") ) end def test_error_for_block - assert_equal %(

1 error prohibited this post from being saved

There were problems with the following fields:

  • Author name can't be empty
), error_messages_for("post") + assert_dom_equal %(

1 error prohibited this post from being saved

There were problems with the following fields:

  • Author name can't be empty
), error_messages_for("post") assert_equal %(

1 error prohibited this post from being saved

There were problems with the following fields:

  • Author name can't be empty
), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1") end def test_form_with_string_multipart - assert_equal( + assert_dom_equal( %(


\n


), form("post", :multipart => true) ) diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 84c273a72f..35cc6dd9cc 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -8,6 +8,8 @@ class AssetTagHelperTest < Test::Unit::TestCase def setup @controller = Class.new do + + attr_accessor :request def url_for(options, *parameters_for_method_reference) "http://www.example.com" @@ -20,6 +22,8 @@ class AssetTagHelperTest < Test::Unit::TestCase "" end end.new + + @controller.request = @request end @@ -67,31 +71,31 @@ class AssetTagHelperTest < Test::Unit::TestCase } def test_auto_discovery - AutoDiscoveryToTag.each { |method, tag| assert_equal(tag, eval(method)) } + AutoDiscoveryToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end def test_javascript_path - JavascriptPathToTag.each { |method, tag| assert_equal(tag, eval(method)) } + JavascriptPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end def test_javascript_include - JavascriptIncludeToTag.each { |method, tag| assert_equal(tag, eval(method)) } + JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end def test_style_path - StylePathToTag.each { |method, tag| assert_equal(tag, eval(method)) } + StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end def test_style_link - StyleLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) } + StyleLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end def test_image_path - ImagePathToTag.each { |method, tag| assert_equal(tag, eval(method)) } + ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end def test_image_tag - ImageLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) } + ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end end @@ -104,6 +108,8 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase def setup @controller = Class.new do + attr_accessor :request + def url_for(options, *parameters_for_method_reference) "http://www.example.com/calloboration/hieraki" end @@ -116,6 +122,8 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase end end.new + @controller.request = @request + end AutoDiscoveryToTag = { @@ -154,31 +162,31 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase } def test_auto_discovery - AutoDiscoveryToTag.each { |method, tag| assert_equal(tag, eval(method)) } + AutoDiscoveryToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end def test_javascript_path - JavascriptPathToTag.each { |method, tag| assert_equal(tag, eval(method)) } + JavascriptPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end def test_javascript_include - JavascriptIncludeToTag.each { |method, tag| assert_equal(tag, eval(method)) } + JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end def test_style_path - StylePathToTag.each { |method, tag| assert_equal(tag, eval(method)) } + StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end def test_style_link - StyleLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) } + StyleLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end def test_image_path - ImagePathToTag.each { |method, tag| assert_equal(tag, eval(method)) } + ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end def test_image_tag - ImageLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) } + ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } # Assigning a default alt tag should not cause an exception to be raised assert_nothing_raised { image_tag('') } end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 9cc89a5860..51141770bd 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -30,52 +30,52 @@ class FormHelperTest < Test::Unit::TestCase end def test_text_field - assert_equal( + assert_dom_equal( '', text_field("post", "title") ) - assert_equal( + assert_dom_equal( '', password_field("post", "title") ) - assert_equal( + assert_dom_equal( '', password_field("person", "name") ) end def test_text_field_with_escapes @post.title = "Hello World" - assert_equal( + assert_dom_equal( '', text_field("post", "title") ) end def test_text_field_with_options expected = '' - assert_equal expected, text_field("post", "title", "size" => 35) - assert_equal expected, text_field("post", "title", :size => 35) + assert_dom_equal expected, text_field("post", "title", "size" => 35) + assert_dom_equal expected, text_field("post", "title", :size => 35) end def test_text_field_assuming_size expected = '' - assert_equal expected, text_field("post", "title", "maxlength" => 35) - assert_equal expected, text_field("post", "title", :maxlength => 35) + assert_dom_equal expected, text_field("post", "title", "maxlength" => 35) + assert_dom_equal expected, text_field("post", "title", :maxlength => 35) end def test_check_box - assert_equal( + assert_dom_equal( '', check_box("post", "secret") ) @post.secret = 0 - assert_equal( + assert_dom_equal( '', check_box("post", "secret") ) - assert_equal( + assert_dom_equal( '', check_box("post", "secret" ,{"checked"=>"checked"}) ) @post.secret = true - assert_equal( + assert_dom_equal( '', check_box("post", "secret") ) @@ -83,23 +83,23 @@ class FormHelperTest < Test::Unit::TestCase def test_check_box_with_explicit_checked_and_unchecked_values @post.secret = "on" - assert_equal( + assert_dom_equal( '', check_box("post", "secret", {}, "on", "off") ) end def test_radio_button - assert_equal('', + assert_dom_equal('', radio_button("post", "title", "Hello World") ) - assert_equal('', + assert_dom_equal('', radio_button("post", "title", "Goodbye World") ) end def test_text_area - assert_equal( + assert_dom_equal( '', text_area("post", "body") ) @@ -107,77 +107,77 @@ class FormHelperTest < Test::Unit::TestCase def test_text_area_with_escapes @post.body = "Back to the hill and over it again!" - assert_equal( + assert_dom_equal( '', text_area("post", "body") ) end def test_date_selects - assert_equal( + assert_dom_equal( '', text_area("post", "body") ) end def test_explicit_name - assert_equal( + assert_dom_equal( '', text_field("post", "title", "name" => "dont guess") ) - assert_equal( + assert_dom_equal( '', text_area("post", "body", "name" => "really!") ) - assert_equal( + assert_dom_equal( '', check_box("post", "secret", "name" => "i mean it") ) - assert_equal text_field("post", "title", "name" => "dont guess"), + assert_dom_equal text_field("post", "title", "name" => "dont guess"), text_field("post", "title", :name => "dont guess") - assert_equal text_area("post", "body", "name" => "really!"), + assert_dom_equal text_area("post", "body", "name" => "really!"), text_area("post", "body", :name => "really!") - assert_equal check_box("post", "secret", "name" => "i mean it"), + assert_dom_equal check_box("post", "secret", "name" => "i mean it"), check_box("post", "secret", :name => "i mean it") end def test_explicit_id - assert_equal( + assert_dom_equal( '', text_field("post", "title", "id" => "dont guess") ) - assert_equal( + assert_dom_equal( '', text_area("post", "body", "id" => "really!") ) - assert_equal( + assert_dom_equal( '', check_box("post", "secret", "id" => "i mean it") ) - assert_equal text_field("post", "title", "id" => "dont guess"), + assert_dom_equal text_field("post", "title", "id" => "dont guess"), text_field("post", "title", :id => "dont guess") - assert_equal text_area("post", "body", "id" => "really!"), + assert_dom_equal text_area("post", "body", "id" => "really!"), text_area("post", "body", :id => "really!") - assert_equal check_box("post", "secret", "id" => "i mean it"), + assert_dom_equal check_box("post", "secret", "id" => "i mean it"), check_box("post", "secret", :id => "i mean it") end def test_auto_index pid = @post.id - assert_equal( + assert_dom_equal( "", text_field("post[]","title") ) - assert_equal( + assert_dom_equal( "", text_area("post[]", "body") ) - assert_equal( + assert_dom_equal( "", check_box("post[]", "secret") ) - assert_equal( + assert_dom_equal( "", radio_button("post[]", "title", "Hello World") ) - assert_equal("", + assert_dom_equal("", radio_button("post[]", "title", "Goodbye World") ) end diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index d92a01a4e3..cc68312fb8 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -39,7 +39,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase Post.new("Cabe went home", "Cabe", "To a little house", "shh!") ] - assert_equal( + assert_dom_equal( "\n\n", options_from_collection_for_select(@posts, "author_name", "title") ) @@ -53,7 +53,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase Post.new("Cabe went home", "Cabe", "To a little house", "shh!") ] - assert_equal( + assert_dom_equal( "\n\n", options_from_collection_for_select(@posts, "author_name", "title", "Babe") ) @@ -66,60 +66,60 @@ class FormOptionsHelperTest < Test::Unit::TestCase Post.new("Cabe went home", "Cabe", "To a little house", "shh!") ] - assert_equal( + assert_dom_equal( "\n\n", options_from_collection_for_select(@posts, "author_name", "title", [ "Babe", "Cabe" ]) ) end def test_array_options_for_select - assert_equal( + assert_dom_equal( "\n\n", options_for_select([ "", "USA", "Sweden" ]) ) end def test_array_options_for_select_with_selection - assert_equal( + assert_dom_equal( "\n\n", options_for_select([ "Denmark", "", "Sweden" ], "") ) end def test_array_options_for_select_with_selection_array - assert_equal( + assert_dom_equal( "\n\n", options_for_select([ "Denmark", "", "Sweden" ], [ "", "Sweden" ]) ) end def test_array_options_for_string_include_in_other_string_bug_fix - assert_equal( + assert_dom_equal( "\n", options_for_select([ "ruby", "rubyonrails" ], "rubyonrails") ) - assert_equal( + assert_dom_equal( "\n", options_for_select([ "ruby", "rubyonrails" ], "ruby") ) end def test_hash_options_for_select - assert_equal( + assert_dom_equal( "\n", options_for_select({ "$" => "Dollar", "" => "" }) ) end def test_hash_options_for_select_with_selection - assert_equal( + assert_dom_equal( "\n", options_for_select({ "$" => "Dollar", "" => "" }, "Dollar") ) end def test_hash_options_for_select_with_selection - assert_equal( + assert_dom_equal( "\n", options_for_select({ "$" => "Dollar", "" => "" }, [ "Dollar", "" ]) ) @@ -131,7 +131,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] ) ] - assert_equal( + assert_dom_equal( "\n\n", option_groups_from_collection_for_select(@continents, "countries", "continent_name", "country_id", "country_name", "dk") ) @@ -139,7 +139,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_time_zone_options_no_parms opts = time_zone_options_for_select - assert_equal "\n" + + assert_dom_equal "\n" + "\n" + "\n" + "\n" + @@ -149,7 +149,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_time_zone_options_with_selected opts = time_zone_options_for_select( "D" ) - assert_equal "\n" + + assert_dom_equal "\n" + "\n" + "\n" + "\n" + @@ -159,7 +159,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_time_zone_options_with_unknown_selected opts = time_zone_options_for_select( "K" ) - assert_equal "\n" + + assert_dom_equal "\n" + "\n" + "\n" + "\n" + @@ -170,7 +170,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_time_zone_options_with_priority_zones zones = [ TimeZone.new( "B" ), TimeZone.new( "E" ) ] opts = time_zone_options_for_select( nil, zones ) - assert_equal "\n" + + assert_dom_equal "\n" + "" + "\n" + "\n" + @@ -182,7 +182,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_time_zone_options_with_selected_priority_zones zones = [ TimeZone.new( "B" ), TimeZone.new( "E" ) ] opts = time_zone_options_for_select( "E", zones ) - assert_equal "\n" + + assert_dom_equal "\n" + "" + "\n" + "\n" + @@ -194,7 +194,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_time_zone_options_with_unselected_priority_zones zones = [ TimeZone.new( "B" ), TimeZone.new( "E" ) ] opts = time_zone_options_for_select( "C", zones ) - assert_equal "\n" + + assert_dom_equal "\n" + "" + "\n" + "\n" + @@ -206,7 +206,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_select @post = Post.new @post.category = "" - assert_equal( + assert_dom_equal( "", select("post", "category", %w( abe hest)) ) @@ -215,7 +215,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_select_with_blank @post = Post.new @post.category = "" - assert_equal( + assert_dom_equal( "", select("post", "category", %w( abe hest), :include_blank => true) ) @@ -224,7 +224,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_select_with_default_prompt @post = Post.new @post.category = "" - assert_equal( + assert_dom_equal( "", select("post", "category", %w( abe hest), :prompt => true) ) @@ -233,7 +233,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_select_no_prompt_when_select_has_value @post = Post.new @post.category = "" - assert_equal( + assert_dom_equal( "", select("post", "category", %w( abe hest), :prompt => true) ) @@ -242,7 +242,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_select_with_given_prompt @post = Post.new @post.category = "" - assert_equal( + assert_dom_equal( "", select("post", "category", %w( abe hest), :prompt => 'The prompt') ) @@ -251,7 +251,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_select_with_prompt_and_blank @post = Post.new @post.category = "" - assert_equal( + assert_dom_equal( "", select("post", "category", %w( abe hest), :prompt => true, :include_blank => true) ) @@ -267,7 +267,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase @post = Post.new @post.author_name = "Babe" - assert_equal( + assert_dom_equal( "", collection_select("post", "author_name", @posts, "author_name", "author_name") ) @@ -283,7 +283,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase @post = Post.new @post.author_name = "Babe" - assert_equal( + assert_dom_equal( "", collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px") ) @@ -292,7 +292,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase def test_country_select @post = Post.new @post.origin = "Denmark" - assert_equal( + assert_dom_equal( "" + + assert_dom_equal "" + + assert_dom_equal "" + + assert_dom_equal "", html - assert_equal html, time_zone_select("firm", "time_zone", nil, {}, + assert_dom_equal html, time_zone_select("firm", "time_zone", nil, {}, :style => "color: red") end @@ -348,7 +348,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase @firm = Firm.new("D") html = time_zone_select("firm", "time_zone", nil, { :include_blank => true }, "style" => "color: red") - assert_equal "" + "\n" + "\n" + "\n" + @@ -357,7 +357,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase "" + "", html - assert_equal html, time_zone_select("firm", "time_zone", nil, + assert_dom_equal html, time_zone_select("firm", "time_zone", nil, { :include_blank => true }, :style => "color: red") end @@ -365,7 +365,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase @firm = Firm.new("D") zones = [ TimeZone.new("A"), TimeZone.new("D") ] html = time_zone_select("firm", "time_zone", zones ) - assert_equal "" + "\n" + "" + "\n" + diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 6295aa91b6..1fc84744e8 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -18,74 +18,74 @@ class FormTagHelperTest < Test::Unit::TestCase def test_check_box_tag actual = check_box_tag "admin" expected = %() - assert_equal expected, actual + assert_dom_equal expected, actual end def test_form_tag actual = form_tag expected = %(
) - assert_equal expected, actual + assert_dom_equal expected, actual end def test_form_tag_multipart actual = form_tag({}, { 'multipart' => true }) expected = %() - assert_equal expected, actual + assert_dom_equal expected, actual end def test_hidden_field_tag actual = hidden_field_tag "id", 3 expected = %() - assert_equal expected, actual + assert_dom_equal expected, actual end def test_password_field_tag actual = password_field_tag expected = %() - assert_equal expected, actual + assert_dom_equal expected, actual end def test_radio_button_tag actual = radio_button_tag "people", "david" expected = %() - assert_equal expected, actual + assert_dom_equal expected, actual end def test_select_tag actual = select_tag "people", "" expected = %() - assert_equal expected, actual + assert_dom_equal expected, actual end def test_text_area_tag_size_string actual = text_area_tag "body", "hello world", "size" => "20x40" expected = %() - assert_equal expected, actual + assert_dom_equal expected, actual end def test_text_area_tag_size_symbol actual = text_area_tag "body", "hello world", :size => "20x40" expected = %() - assert_equal expected, actual + assert_dom_equal expected, actual end def test_text_field_tag actual = text_field_tag "title", "Hello!" expected = %() - assert_equal expected, actual + assert_dom_equal expected, actual end def test_text_field_tag_class_string actual = text_field_tag "title", "Hello!", "class" => "admin" expected = %() - assert_equal expected, actual + assert_dom_equal expected, actual end def test_boolean_optios - assert_equal %(), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes") - assert_equal %(), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil) - assert_equal %(), select_tag("people", "", :multiple => true) - assert_equal %(), select_tag("people", "", :multiple => nil) + assert_dom_equal %(), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes") + assert_dom_equal %(), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil) + assert_dom_equal %(), select_tag("people", "", :multiple => true) + assert_dom_equal %(), select_tag("people", "", :multiple => nil) end end diff --git a/actionpack/test/template/java_script_macros_helper_test.rb b/actionpack/test/template/java_script_macros_helper_test.rb index 763eb3d5e9..5b305eb5ee 100644 --- a/actionpack/test/template/java_script_macros_helper_test.rb +++ b/actionpack/test/template/java_script_macros_helper_test.rb @@ -23,11 +23,11 @@ class JavaScriptMacrosHelperTest < Test::Unit::TestCase def test_auto_complete_field - assert_equal %(), + assert_dom_equal %(), auto_complete_field("some_input", :url => { :action => "autocomplete" }); - assert_equal %(), + assert_dom_equal %(), auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => ','); - assert_equal %(), + assert_dom_equal %(), auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => [',']); end @@ -46,7 +46,7 @@ class JavaScriptMacrosHelperTest < Test::Unit::TestCase def test_text_field_with_auto_complete assert_match "