PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/rails/actionpack/test/template/form_tag_helper_test.rb

http://github.com/benburkert/cruisecontrolrb
Ruby | 172 lines | 142 code | 30 blank | 0 comment | 0 complexity | 57e642b6dcbf760dd2598f5a403c20f2 MD5 | raw file
Possible License(s): Apache-2.0
  1. require File.dirname(__FILE__) + '/../abstract_unit'
  2. class FormTagHelperTest < Test::Unit::TestCase
  3. include ActionView::Helpers::UrlHelper
  4. include ActionView::Helpers::TagHelper
  5. include ActionView::Helpers::FormTagHelper
  6. include ActionView::Helpers::TextHelper
  7. include ActionView::Helpers::CaptureHelper
  8. def setup
  9. @controller = Class.new do
  10. def url_for(options, *parameters_for_method_reference)
  11. "http://www.example.com"
  12. end
  13. end
  14. @controller = @controller.new
  15. end
  16. def test_check_box_tag
  17. actual = check_box_tag "admin"
  18. expected = %(<input id="admin" name="admin" type="checkbox" value="1" />)
  19. assert_dom_equal expected, actual
  20. end
  21. def test_form_tag
  22. actual = form_tag
  23. expected = %(<form action="http://www.example.com" method="post">)
  24. assert_dom_equal expected, actual
  25. end
  26. def test_form_tag_multipart
  27. actual = form_tag({}, { 'multipart' => true })
  28. expected = %(<form action="http://www.example.com" enctype="multipart/form-data" method="post">)
  29. assert_dom_equal expected, actual
  30. end
  31. def test_form_tag_with_method
  32. actual = form_tag({}, { :method => :put })
  33. expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>)
  34. assert_dom_equal expected, actual
  35. end
  36. def test_form_tag_with_block
  37. _erbout = ''
  38. form_tag("http://example.com") { _erbout.concat "Hello world!" }
  39. expected = %(<form action="http://www.example.com" method="post">Hello world!</form>)
  40. assert_dom_equal expected, _erbout
  41. end
  42. def test_form_tag_with_block_and_method
  43. _erbout = ''
  44. form_tag("http://example.com", :method => :put) { _erbout.concat "Hello world!" }
  45. expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>Hello world!</form>)
  46. assert_dom_equal expected, _erbout
  47. end
  48. def test_hidden_field_tag
  49. actual = hidden_field_tag "id", 3
  50. expected = %(<input id="id" name="id" type="hidden" value="3" />)
  51. assert_dom_equal expected, actual
  52. end
  53. def test_password_field_tag
  54. actual = password_field_tag
  55. expected = %(<input id="password" name="password" type="password" />)
  56. assert_dom_equal expected, actual
  57. end
  58. def test_radio_button_tag
  59. actual = radio_button_tag "people", "david"
  60. expected = %(<input id="people_david" name="people" type="radio" value="david" />)
  61. assert_dom_equal expected, actual
  62. actual = radio_button_tag("num_people", 5)
  63. expected = %(<input id="num_people_5" name="num_people" type="radio" value="5" />)
  64. assert_dom_equal expected, actual
  65. actual = radio_button_tag("gender", "m") + radio_button_tag("gender", "f")
  66. expected = %(<input id="gender_m" name="gender" type="radio" value="m" /><input id="gender_f" name="gender" type="radio" value="f" />)
  67. assert_dom_equal expected, actual
  68. actual = radio_button_tag("opinion", "-1") + radio_button_tag("opinion", "1")
  69. expected = %(<input id="opinion_-1" name="opinion" type="radio" value="-1" /><input id="opinion_1" name="opinion" type="radio" value="1" />)
  70. assert_dom_equal expected, actual
  71. end
  72. def test_select_tag
  73. actual = select_tag "people", "<option>david</option>"
  74. expected = %(<select id="people" name="people"><option>david</option></select>)
  75. assert_dom_equal expected, actual
  76. end
  77. def test_text_area_tag_size_string
  78. actual = text_area_tag "body", "hello world", "size" => "20x40"
  79. expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
  80. assert_dom_equal expected, actual
  81. end
  82. def test_text_area_tag_size_symbol
  83. actual = text_area_tag "body", "hello world", :size => "20x40"
  84. expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
  85. assert_dom_equal expected, actual
  86. end
  87. def test_text_field_tag
  88. actual = text_field_tag "title", "Hello!"
  89. expected = %(<input id="title" name="title" type="text" value="Hello!" />)
  90. assert_dom_equal expected, actual
  91. end
  92. def test_text_field_tag_class_string
  93. actual = text_field_tag "title", "Hello!", "class" => "admin"
  94. expected = %(<input class="admin" id="title" name="title" type="text" value="Hello!" />)
  95. assert_dom_equal expected, actual
  96. end
  97. def test_boolean_optios
  98. assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")
  99. assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil)
  100. assert_dom_equal %(<select id="people" multiple="multiple" name="people"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => true)
  101. assert_dom_equal %(<select id="people" name="people"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => nil)
  102. end
  103. def test_stringify_symbol_keys
  104. actual = text_field_tag "title", "Hello!", :id => "admin"
  105. expected = %(<input id="admin" name="title" type="text" value="Hello!" />)
  106. assert_dom_equal expected, actual
  107. end
  108. def test_submit_tag
  109. assert_dom_equal(
  110. %(<input name='commit' type='submit' value='Save' onclick="this.disabled=true;this.value='Saving...';this.form.submit();alert('hello!')" />),
  111. submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')")
  112. )
  113. end
  114. def test_pass
  115. assert_equal 1, 1
  116. end
  117. end
  118. class DeprecatedFormTagHelperTest < Test::Unit::TestCase
  119. include ActionView::Helpers::UrlHelper
  120. include ActionView::Helpers::TagHelper
  121. include ActionView::Helpers::FormTagHelper
  122. include ActionView::Helpers::TextHelper
  123. include ActionView::Helpers::CaptureHelper
  124. def setup
  125. @controller = Class.new do
  126. def url_for(options, *parameters_for_method_reference)
  127. "http://www.example.com"
  128. end
  129. end
  130. @controller = @controller.new
  131. end
  132. def test_start_form_tag_deprecation
  133. assert_deprecated /start_form_tag/ do
  134. start_form_tag
  135. end
  136. end
  137. def test_end_form_tag_deprecation
  138. assert_deprecated /end_form_tag/ do
  139. end_form_tag
  140. end
  141. end
  142. end