Permalink
Browse files

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
  • Loading branch information...
1 parent c0c0018 commit 71b77a3d6aa527b3486f89556ca3752e06985146 @jeremy jeremy committed Jun 13, 2007
View
@@ -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]
@@ -224,6 +224,14 @@ def test_select_month_with_zero_indexed_custom_names
assert_equal expected, select_month(8, :use_month_names => month_names)
end
+ def test_select_month_with_hidden
+ assert_dom_equal "<input type=\"hidden\" id=\"date_month\" name=\"date[month]\" value=\"8\" />\n", select_month(8, :use_hidden => true)
+ end
+
+ def test_select_month_with_hidden_and_field_name
+ assert_dom_equal "<input type=\"hidden\" id=\"date_mois\" name=\"date[mois]\" value=\"8\" />\n", select_month(8, :use_hidden => true, :field_name => 'mois')
+ end
+
def test_select_year
expected = %(<select id="date_year" name="date[year]">\n)
expected << %(<option value="2003" selected="selected">2003</option>\n<option value="2004">2004</option>\n<option value="2005">2005</option>\n)
@@ -271,6 +279,14 @@ def test_select_year_descending
assert_equal expected, select_year(2005, :start_year => 2005, :end_year => 2003)
end
+ def test_select_year_with_hidden
+ assert_dom_equal "<input type=\"hidden\" id=\"date_year\" name=\"date[year]\" value=\"2007\" />\n", select_year(2007, :use_hidden => true)
+ end
+
+ def test_select_year_with_hidden_and_field_name
+ assert_dom_equal "<input type=\"hidden\" id=\"date_anno\" name=\"date[anno]\" value=\"2007\" />\n", select_year(2007, :use_hidden => true, :field_name => 'anno')
+ end
+
def test_select_hour
expected = %(<select id="date_hour" name="date[hour]">\n)
expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08" selected="selected">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n)
@@ -367,6 +383,14 @@ def test_select_minute_nil_with_blank_and_step
assert_equal expected, select_minute(nil, { :include_blank => true , :minute_step => 15 })
end
+ def test_select_minute_with_hidden
+ assert_dom_equal "<input type=\"hidden\" id=\"date_minute\" name=\"date[minute]\" value=\"8\" />\n", select_minute(8, :use_hidden => true)
+ end
+
+ def test_select_minute_with_hidden_and_field_name
+ assert_dom_equal "<input type=\"hidden\" id=\"date_minuto\" name=\"date[minuto]\" value=\"8\" />\n", select_minute(8, :use_hidden => true, :field_name => 'minuto')
+ end
+
def test_select_second
expected = %(<select id="date_second" name="date[second]">\n)
expected << %(<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18" selected="selected">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n)
@@ -114,6 +114,22 @@ def test_text_field_doesnt_change_param_values
assert_equal object_name, "post[]"
end
+ def test_hidden_field
+ assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="Hello World" />',
+ hidden_field("post", "title")
+ end
+
+ def test_hidden_field_with_escapes
+ @post.title = "<b>Hello World</b>"
+ assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="&lt;b&gt;Hello World&lt;/b&gt;" />',
+ hidden_field("post", "title")
+ end
+
+ def test_text_field_with_options
+ assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="Something Else" />',
+ hidden_field("post", "title", :value => "Something Else")
+ end
+
def test_check_box
assert_dom_equal(
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
@@ -157,7 +173,7 @@ def test_radio_button_is_checked_with_integers
radio_button("post", "secret", "1")
)
end
-
+
def test_radio_button_respects_passed_in_id
assert_dom_equal('<input checked="checked" id="foo" name="post[secret]" type="radio" value="1" />',
radio_button("post", "secret", "1", :id=>"foo")
@@ -178,21 +194,21 @@ def test_text_area_with_escapes
text_area("post", "body")
)
end
-
+
def test_text_area_with_alternate_value
assert_dom_equal(
'<textarea cols="40" id="post_body" name="post[body]" rows="20">Testing alternate values.</textarea>',
text_area("post", "body", :value => 'Testing alternate values.')
)
end
-
+
def test_text_area_with_size_option
assert_dom_equal(
'<textarea cols="183" id="post_body" name="post[body]" rows="820">Back to the hill and over it again!</textarea>',
text_area("post", "body", :size => "183x820")
)
end
-
+
def test_explicit_name
assert_dom_equal(
'<input id="post_title" name="dont guess" size="30" type="text" value="Hello World" />', text_field("post", "title", "name" => "dont guess")
@@ -317,7 +333,7 @@ def test_form_for_without_object
assert_dom_equal expected, _erbout
end
-
+
def test_form_for_with_index
_erbout = ''
@@ -401,7 +417,7 @@ def test_fields_for_object_with_bracketed_name
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 @@ def test_form_for_and_fields_for
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 @@ def #{selector}(field, *args, &proc)
class_eval src, __FILE__, __LINE__
end
end
-
+
def test_form_for_with_labelled_builder
_erbout = ''
@@ -479,7 +495,7 @@ def test_default_form_builder
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 @@ def test_fields_for_with_labelled_builder
assert_dom_equal expected, _erbout
end
-
+
def test_form_for_with_html_options_adds_options_to_form_tag
_erbout = ''
@@ -545,7 +561,7 @@ def test_form_for_with_html_options_adds_options_to_form_tag
assert_dom_equal expected, _erbout
end
-
+
def test_form_for_with_string_url_option
_erbout = ''
@@ -562,7 +578,7 @@ def test_form_for_with_hash_url_option
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 @@ def test_form_for_with_existing_object_and_custom_url
expected = "<form action=\"/super_posts\" class=\"edit_post\" id=\"edit_post_123\" method=\"post\"><div style=\"margin:0;padding:0\"><input name=\"_method\" type=\"hidden\" value=\"put\" /></div></form>"
assert_equal expected, _erbout
end
-
+
def test_remote_form_for_with_html_options_adds_options_to_form_tag
self.extend ActionView::Helpers::PrototypeHelper
_erbout = ''
Oops, something went wrong.

0 comments on commit 71b77a3

Please sign in to comment.