From 71b77a3d6aa527b3486f89556ca3752e06985146 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 13 Jun 2007 01:20:55 +0000 Subject: [PATCH] Improve helper test coverage. Closes #7215, #7233, #7234, #7235, #7236, #7237, #7238. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7011 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 +- actionpack/test/template/date_helper_test.rb | 24 +++++++++++ actionpack/test/template/form_helper_test.rb | 42 +++++++++++++------ .../test/template/form_options_helper_test.rb | 28 ++++++++++++- .../test/template/form_tag_helper_test.rb | 8 ++++ .../test/template/javascript_helper_test.rb | 33 +++++++++++---- 6 files changed, 112 insertions(+), 25 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 3ae169883d..5c75ccf203 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -8,7 +8,7 @@ * Improve Text Helper test coverage. #7274 [Rob Sanheim, Josh Peek] -* Improve Action View test coverage. #7241, #7243, #7244 [Rich Collins] +* Improve helper test coverage. #7215, #7233, #7234, #7235, #7236, #7237, #7238, #7241, #7243, #7244 [Rich Collins, Josh Peek] * Resources: url_for([parent, child]) generates /parents/1/children/2 for the nested resource. Likewise with the other simply helpful methods like form_for and link_to. #6432 [mhw, Jonathan Vaught, lotswholetime] diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index 8f92840c78..92a0a0a43e 100755 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -224,6 +224,14 @@ class DateHelperTest < Test::Unit::TestCase assert_equal expected, select_month(8, :use_month_names => month_names) end + def test_select_month_with_hidden + assert_dom_equal "\n", select_month(8, :use_hidden => true) + end + + def test_select_month_with_hidden_and_field_name + assert_dom_equal "\n", select_month(8, :use_hidden => true, :field_name => 'mois') + end + def test_select_year expected = %(\n", select_year(2007, :use_hidden => true) + end + + def test_select_year_with_hidden_and_field_name + assert_dom_equal "\n", select_year(2007, :use_hidden => true, :field_name => 'anno') + end + def test_select_hour expected = %(\n", select_minute(8, :use_hidden => true) + end + + def test_select_minute_with_hidden_and_field_name + assert_dom_equal "\n", select_minute(8, :use_hidden => true, :field_name => 'minuto') + end + def test_select_second expected = %(', + hidden_field("post", "title") + end + + def test_hidden_field_with_escapes + @post.title = "Hello World" + assert_dom_equal '', + hidden_field("post", "title") + end + + def test_text_field_with_options + assert_dom_equal '', + hidden_field("post", "title", :value => "Something Else") + end + def test_check_box assert_dom_equal( '', @@ -157,7 +173,7 @@ class FormHelperTest < Test::Unit::TestCase radio_button("post", "secret", "1") ) end - + def test_radio_button_respects_passed_in_id assert_dom_equal('', radio_button("post", "secret", "1", :id=>"foo") @@ -178,21 +194,21 @@ class FormHelperTest < Test::Unit::TestCase text_area("post", "body") ) end - + def test_text_area_with_alternate_value assert_dom_equal( '', text_area("post", "body", :value => 'Testing alternate values.') ) end - + def test_text_area_with_size_option assert_dom_equal( '', text_area("post", "body", :size => "183x820") ) end - + def test_explicit_name assert_dom_equal( '', text_field("post", "title", "name" => "dont guess") @@ -317,7 +333,7 @@ class FormHelperTest < Test::Unit::TestCase assert_dom_equal expected, _erbout end - + def test_form_for_with_index _erbout = '' @@ -401,7 +417,7 @@ class FormHelperTest < Test::Unit::TestCase def test_form_builder_does_not_have_form_for_method assert ! ActionView::Helpers::FormBuilder.instance_methods.include?('form_for') end - + def test_form_for_and_fields_for _erbout = '' @@ -424,7 +440,7 @@ class FormHelperTest < Test::Unit::TestCase assert_dom_equal expected, _erbout end - + class LabelledFormBuilder < ActionView::Helpers::FormBuilder (field_helpers - %w(hidden_field)).each do |selector| src = <<-END_SRC @@ -435,7 +451,7 @@ class FormHelperTest < Test::Unit::TestCase class_eval src, __FILE__, __LINE__ end end - + def test_form_for_with_labelled_builder _erbout = '' @@ -479,7 +495,7 @@ class FormHelperTest < Test::Unit::TestCase ensure ActionView::Base.default_form_builder = old_default_form_builder end - + def test_default_form_builder_with_active_record_helpers _erbout = '' @@ -536,7 +552,7 @@ class FormHelperTest < Test::Unit::TestCase assert_dom_equal expected, _erbout end - + def test_form_for_with_html_options_adds_options_to_form_tag _erbout = '' @@ -545,7 +561,7 @@ class FormHelperTest < Test::Unit::TestCase assert_dom_equal expected, _erbout end - + def test_form_for_with_string_url_option _erbout = '' @@ -562,7 +578,7 @@ class FormHelperTest < Test::Unit::TestCase assert_equal 'controller', @controller.url_for_options[:controller] assert_equal 'action', @controller.url_for_options[:action] end - + def test_form_for_with_record_url_option _erbout = '' @@ -621,7 +637,7 @@ class FormHelperTest < Test::Unit::TestCase expected = "
" assert_equal expected, _erbout end - + def test_remote_form_for_with_html_options_adds_options_to_form_tag self.extend ActionView::Helpers::PrototypeHelper _erbout = '' diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 3c0a96b0de..aa7869641d 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -296,7 +296,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase select("post", "category", %w( abe hest), :prompt => true, :include_blank => true) ) end - + def test_select_with_selected_value @post = Post.new @post.category = "" @@ -416,6 +416,30 @@ class FormOptionsHelperTest < Test::Unit::TestCase ) end + def test_country_select_with_priority_countries + @post = Post.new + @post.origin = "Denmark" + assert_dom_equal( + "", + country_select("post", "origin", ["New Zealand", "Nicaragua"]) + ) + end + + def test_country_select_with_selected_priority_country + @post = Post.new + @post.origin = "New Zealand" + assert_dom_equal( + "", + country_select("post", "origin", ["New Zealand", "Nicaragua"]) + ) + end + def test_time_zone_select @firm = Firm.new("D") html = time_zone_select( "firm", "time_zone" ) @@ -449,7 +473,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase _erbout ) end - + def test_time_zone_select_with_blank @firm = Firm.new("D") html = time_zone_select("firm", "time_zone", nil, :include_blank => true) diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 2390edff86..cb78a59516 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -62,6 +62,14 @@ class FormTagHelperTest < Test::Unit::TestCase assert_dom_equal expected, actual end + def test_file_field_tag + assert_dom_equal "", file_field_tag("picsplz") + end + + def test_file_field_tag_with_options + assert_dom_equal "", file_field_tag("picsplz", :class => "pix") + end + def test_password_field_tag actual = password_field_tag expected = %() diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index 08bbd5e95f..ce830494a7 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -2,33 +2,34 @@ require "#{File.dirname(__FILE__)}/../abstract_unit" class JavaScriptHelperTest < Test::Unit::TestCase include ActionView::Helpers::JavaScriptHelper - + include ActionView::Helpers::UrlHelper include ActionView::Helpers::TagHelper include ActionView::Helpers::TextHelper include ActionView::Helpers::FormHelper include ActionView::Helpers::CaptureHelper - + def test_define_javascript_functions # check if prototype.js is included first assert_not_nil define_javascript_functions.split("\n")[1].match(/Prototype JavaScript framework/) - + # check that scriptaculous.js is not in here, only needed if loaded remotely assert_nil define_javascript_functions.split("\n")[1].match(/var Scriptaculous = \{/) end def test_escape_javascript + assert_equal '', escape_javascript(nil) assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos')) assert_equal %(backslash\\\\test), escape_javascript( %(backslash\\test) ) end - + def test_link_to_function - assert_dom_equal %(Greeting), + assert_dom_equal %(Greeting), link_to_function("Greeting", "alert('Hello world!')") end - + def test_link_to_function_with_existing_onclick - assert_dom_equal %(Greeting), + assert_dom_equal %(Greeting), link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')") end @@ -47,12 +48,12 @@ class JavaScriptHelperTest < Test::Unit::TestCase end def test_link_to_function_with_href - assert_dom_equal %(Greeting), + assert_dom_equal %(Greeting), link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/') end def test_button_to_function - assert_dom_equal %(), + assert_dom_equal %(), button_to_function("Greeting", "alert('Hello world!')") end @@ -70,6 +71,16 @@ class JavaScriptHelperTest < Test::Unit::TestCase assert_dom_equal %(), html end + def test_button_to_function_with_onclick + assert_dom_equal "", + button_to_function("Greeting", "alert('Hello world!')", :onclick => "alert('Goodbye World :(')") + end + + def test_button_to_function_without_function + assert_dom_equal "", + button_to_function("Greeting") + end + def test_javascript_tag assert_dom_equal "", javascript_tag("alert('hello')") @@ -79,4 +90,8 @@ class JavaScriptHelperTest < Test::Unit::TestCase assert_dom_equal "", javascript_tag("alert('hello')", :id => "the_js_tag") end + + def test_javascript_cdata_section + assert_dom_equal "\n//\n", javascript_cdata_section("alert('hello')") + end end