actionpack 1.11.2 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (149) hide show
  1. data/CHANGELOG +392 -5
  2. data/lib/action_controller.rb +8 -4
  3. data/lib/action_controller/assertions.rb +9 -10
  4. data/lib/action_controller/base.rb +177 -88
  5. data/lib/action_controller/benchmarking.rb +5 -5
  6. data/lib/action_controller/caching.rb +44 -36
  7. data/lib/action_controller/cgi_ext/cgi_methods.rb +71 -6
  8. data/lib/action_controller/cgi_ext/cookie_performance_fix.rb +1 -1
  9. data/lib/action_controller/cgi_process.rb +36 -24
  10. data/lib/action_controller/components.rb +152 -52
  11. data/lib/action_controller/dependencies.rb +1 -1
  12. data/lib/action_controller/deprecated_redirects.rb +2 -2
  13. data/lib/action_controller/deprecated_request_methods.rb +34 -0
  14. data/lib/action_controller/filters.rb +59 -19
  15. data/lib/action_controller/flash.rb +53 -47
  16. data/lib/action_controller/helpers.rb +2 -2
  17. data/lib/action_controller/integration.rb +524 -0
  18. data/lib/action_controller/layout.rb +58 -23
  19. data/lib/action_controller/mime_responds.rb +163 -0
  20. data/lib/action_controller/mime_type.rb +142 -0
  21. data/lib/action_controller/pagination.rb +13 -7
  22. data/lib/action_controller/request.rb +59 -56
  23. data/lib/action_controller/rescue.rb +1 -1
  24. data/lib/action_controller/routing.rb +29 -10
  25. data/lib/action_controller/scaffolding.rb +8 -0
  26. data/lib/action_controller/session/active_record_store.rb +21 -10
  27. data/lib/action_controller/session/mem_cache_store.rb +18 -12
  28. data/lib/action_controller/session_management.rb +30 -11
  29. data/lib/action_controller/templates/rescues/_trace.rhtml +1 -1
  30. data/lib/action_controller/templates/scaffolds/layout.rhtml +4 -4
  31. data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
  32. data/lib/action_controller/test_process.rb +189 -118
  33. data/lib/action_controller/vendor/html-scanner/html/node.rb +20 -1
  34. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +3 -0
  35. data/lib/action_controller/vendor/html-scanner/html/version.rb +1 -1
  36. data/lib/action_controller/vendor/xml_node.rb +97 -0
  37. data/lib/action_controller/verification.rb +2 -0
  38. data/lib/action_pack/version.rb +3 -3
  39. data/lib/action_view.rb +0 -2
  40. data/lib/action_view/base.rb +109 -36
  41. data/lib/action_view/compiled_templates.rb +1 -1
  42. data/lib/action_view/helpers/active_record_helper.rb +4 -2
  43. data/lib/action_view/helpers/asset_tag_helper.rb +6 -7
  44. data/lib/action_view/helpers/capture_helper.rb +49 -12
  45. data/lib/action_view/helpers/date_helper.rb +14 -4
  46. data/lib/action_view/helpers/form_helper.rb +136 -20
  47. data/lib/action_view/helpers/form_options_helper.rb +29 -7
  48. data/lib/action_view/helpers/form_tag_helper.rb +22 -20
  49. data/lib/action_view/helpers/java_script_macros_helper.rb +29 -9
  50. data/lib/action_view/helpers/javascript_helper.rb +50 -446
  51. data/lib/action_view/helpers/javascripts/controls.js +95 -30
  52. data/lib/action_view/helpers/javascripts/dragdrop.js +161 -21
  53. data/lib/action_view/helpers/javascripts/effects.js +310 -211
  54. data/lib/action_view/helpers/javascripts/prototype.js +228 -28
  55. data/lib/action_view/helpers/number_helper.rb +9 -9
  56. data/lib/action_view/helpers/pagination_helper.rb +1 -1
  57. data/lib/action_view/helpers/prototype_helper.rb +900 -0
  58. data/lib/action_view/helpers/scriptaculous_helper.rb +135 -0
  59. data/lib/action_view/helpers/text_helper.rb +7 -6
  60. data/lib/action_view/helpers/url_helper.rb +23 -14
  61. data/lib/action_view/partials.rb +12 -4
  62. data/rakefile +13 -5
  63. data/test/abstract_unit.rb +4 -3
  64. data/test/active_record_unit.rb +88 -0
  65. data/test/{controller → activerecord}/active_record_assertions_test.rb +7 -50
  66. data/test/{controller → activerecord}/active_record_store_test.rb +27 -4
  67. data/test/activerecord/pagination_test.rb +161 -0
  68. data/test/controller/action_pack_assertions_test.rb +18 -15
  69. data/test/controller/base_test.rb +31 -42
  70. data/test/controller/benchmark_test.rb +8 -11
  71. data/test/controller/capture_test.rb +33 -1
  72. data/test/controller/cgi_test.rb +33 -0
  73. data/test/controller/custom_handler_test.rb +8 -0
  74. data/test/controller/fake_controllers.rb +9 -17
  75. data/test/controller/filters_test.rb +32 -3
  76. data/test/controller/flash_test.rb +26 -41
  77. data/test/controller/fragment_store_setting_test.rb +1 -1
  78. data/test/controller/layout_test.rb +73 -0
  79. data/test/controller/mime_responds_test.rb +257 -0
  80. data/test/controller/mime_type_test.rb +24 -0
  81. data/test/controller/new_render_test.rb +157 -1
  82. data/test/controller/redirect_test.rb +23 -0
  83. data/test/controller/render_test.rb +54 -56
  84. data/test/controller/request_test.rb +25 -0
  85. data/test/controller/routing_test.rb +74 -66
  86. data/test/controller/test_test.rb +66 -1
  87. data/test/controller/verification_test.rb +3 -1
  88. data/test/controller/webservice_test.rb +255 -0
  89. data/test/fixtures/companies.yml +24 -0
  90. data/test/fixtures/company.rb +9 -0
  91. data/test/fixtures/db_definitions/sqlite.sql +42 -0
  92. data/test/fixtures/developer.rb +7 -0
  93. data/test/fixtures/developers.yml +21 -0
  94. data/test/fixtures/developers_projects.yml +13 -0
  95. data/test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml +1 -0
  96. data/test/fixtures/layout_tests/layouts/item.rhtml +1 -0
  97. data/test/fixtures/layout_tests/layouts/layout_test.rhtml +1 -0
  98. data/test/fixtures/layout_tests/layouts/third_party_template_library.mab +1 -0
  99. data/test/fixtures/layout_tests/views/hello.rhtml +1 -0
  100. data/test/fixtures/multipart/mona_lisa.jpg +0 -0
  101. data/test/fixtures/project.rb +3 -0
  102. data/test/fixtures/projects.yml +7 -0
  103. data/test/fixtures/replies.yml +13 -0
  104. data/test/fixtures/reply.rb +5 -0
  105. data/test/fixtures/respond_to/all_types_with_layout.rhtml +1 -0
  106. data/test/fixtures/respond_to/all_types_with_layout.rjs +1 -0
  107. data/test/fixtures/respond_to/layouts/standard.rhtml +1 -0
  108. data/test/fixtures/respond_to/using_defaults.rhtml +1 -0
  109. data/test/fixtures/respond_to/using_defaults.rjs +1 -0
  110. data/test/fixtures/respond_to/using_defaults.rxml +1 -0
  111. data/test/fixtures/respond_to/using_defaults_with_type_list.rhtml +1 -0
  112. data/test/fixtures/respond_to/using_defaults_with_type_list.rjs +1 -0
  113. data/test/fixtures/respond_to/using_defaults_with_type_list.rxml +1 -0
  114. data/test/fixtures/test/block_content_for.rhtml +2 -0
  115. data/test/fixtures/test/delete_with_js.rjs +2 -0
  116. data/test/fixtures/test/dot.directory/render_file_with_ivar.rhtml +1 -0
  117. data/test/fixtures/test/enum_rjs_test.rjs +6 -0
  118. data/test/fixtures/test/erb_content_for.rhtml +2 -0
  119. data/test/fixtures/test/hello_world.rxml +3 -0
  120. data/test/fixtures/test/hello_world_with_layout_false.rhtml +1 -0
  121. data/test/fixtures/test/non_erb_block_content_for.rxml +4 -0
  122. data/test/fixtures/topic.rb +3 -0
  123. data/test/fixtures/topics.yml +22 -0
  124. data/test/template/active_record_helper_test.rb +4 -0
  125. data/test/template/asset_tag_helper_test.rb +7 -2
  126. data/test/template/date_helper_test.rb +39 -2
  127. data/test/template/form_helper_test.rb +238 -5
  128. data/test/template/form_options_helper_test.rb +78 -0
  129. data/test/template/form_tag_helper_test.rb +11 -0
  130. data/test/template/java_script_macros_helper_test.rb +51 -6
  131. data/test/template/javascript_helper_test.rb +7 -153
  132. data/test/template/number_helper_test.rb +14 -13
  133. data/test/template/prototype_helper_test.rb +423 -0
  134. data/test/template/scriptaculous_helper_test.rb +90 -0
  135. data/test/template/text_helper_test.rb +12 -9
  136. data/test/template/url_helper_test.rb +31 -15
  137. metadata +291 -246
  138. data/lib/action_controller/cgi_ext/multipart_progress.rb +0 -169
  139. data/lib/action_controller/upload_progress.rb +0 -473
  140. data/lib/action_controller/vendor/html-scanner/html/node.rb.rej +0 -17
  141. data/lib/action_view/helpers/upload_progress_helper.rb +0 -433
  142. data/lib/action_view/vendor/builder.rb +0 -13
  143. data/lib/action_view/vendor/builder/blankslate.rb +0 -53
  144. data/lib/action_view/vendor/builder/xmlbase.rb +0 -143
  145. data/lib/action_view/vendor/builder/xmlevents.rb +0 -63
  146. data/lib/action_view/vendor/builder/xmlmarkup.rb +0 -308
  147. data/test/controller/multipart_progress_testx.rb +0 -365
  148. data/test/controller/upload_progress_testx.rb +0 -89
  149. data/test/template/upload_progress_helper_testx.rb +0 -136
@@ -0,0 +1 @@
1
+ HTML for all_types_with_layout
@@ -0,0 +1 @@
1
+ page << "RJS for all_types_with_layout"
@@ -0,0 +1 @@
1
+ <html><%= @content_for_layout %></html>
@@ -0,0 +1 @@
1
+ Hello world!
@@ -0,0 +1 @@
1
+ page[:body].visual_effect :highlight
@@ -0,0 +1 @@
1
+ xml.p "Hello world!"
@@ -0,0 +1 @@
1
+ page[:body].visual_effect :highlight
@@ -0,0 +1,2 @@
1
+ <% block_content_for :title do 'Putting stuff in the title!' end %>
2
+ Great stuff!
@@ -0,0 +1,2 @@
1
+ page.remove 'person'
2
+ page.visual_effect :highlight, "project-#{@project_id}"
@@ -0,0 +1 @@
1
+ The secret is <%= @secret %>
@@ -0,0 +1,6 @@
1
+ page.select('.product').each do |value|
2
+ page.visual_effect :highlight
3
+ page.visual_effect :highlight, value
4
+ page.sortable(value, :url => { :action => "order" })
5
+ page.draggable(value)
6
+ end
@@ -0,0 +1,2 @@
1
+ <% erb_content_for :title do %>Putting stuff in the title!<% end %>
2
+ Great stuff!
@@ -0,0 +1,3 @@
1
+ xml.html do
2
+ xml.p "Hello"
3
+ end
@@ -0,0 +1,4 @@
1
+ content_for :title do
2
+ 'Putting stuff in the title!'
3
+ end
4
+ xml << "\nGreat stuff!"
@@ -0,0 +1,3 @@
1
+ class Topic < ActiveRecord::Base
2
+ has_many :replies, :include => [:user], :dependent => true
3
+ end
@@ -0,0 +1,22 @@
1
+ futurama:
2
+ id: 1
3
+ title: Isnt futurama awesome?
4
+ subtitle: It really is, isnt it.
5
+ content: I like futurama
6
+ created_at: <%= 1.day.ago.to_s(:db) %>
7
+ updated_at:
8
+
9
+ harvey_birdman:
10
+ id: 2
11
+ title: Harvey Birdman is the king of all men
12
+ subtitle: yup
13
+ content: It really is
14
+ created_at: <%= 2.hours.ago.to_s(:db) %>
15
+ updated_at:
16
+
17
+ rails:
18
+ id: 3
19
+ title: Rails is nice
20
+ subtitle: It makes me happy
21
+ content: except when I have to hack internals to fix pagination. even then really.
22
+ created_at: <%= 20.minutes.ago.to_s(:db) %>
@@ -119,6 +119,10 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
119
119
  assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post")
120
120
  assert_equal %(<div class="errorDeathByClass" id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
121
121
  end
122
+
123
+ def test_error_messages_for_handles_nil
124
+ assert_equal "", error_messages_for("notthere")
125
+ end
122
126
 
123
127
  def test_form_with_string_multipart
124
128
  assert_dom_equal(
@@ -49,7 +49,9 @@ class AssetTagHelperTest < Test::Unit::TestCase
49
49
  %(javascript_include_tag("xmlhr")) => %(<script src="/javascripts/xmlhr.js" type="text/javascript"></script>),
50
50
  %(javascript_include_tag("xmlhr", :lang => "vbscript")) => %(<script lang="vbscript" src="/javascripts/xmlhr.js" type="text/javascript"></script>),
51
51
  %(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(<script src="/javascripts/common.javascript" type="text/javascript"></script>\n<script src="/elsewhere/cools.js" type="text/javascript"></script>),
52
- %(javascript_include_tag(:defaults)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>)
52
+ %(javascript_include_tag(:defaults)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>),
53
+ %(javascript_include_tag(:defaults, "test")) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/test.js" type="text/javascript"></script>),
54
+ %(javascript_include_tag("test", :defaults)) => %(<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>)
53
55
  }
54
56
 
55
57
  StylePathToTag = {
@@ -74,6 +76,8 @@ class AssetTagHelperTest < Test::Unit::TestCase
74
76
  %(image_tag("xml")) => %(<img alt="Xml" src="/images/xml.png" />),
75
77
  %(image_tag("rss", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/images/rss.png" />),
76
78
  %(image_tag("gold", :size => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />),
79
+ %(image_tag("symbolize", "size" => "45x70")) => %(<img alt="Symbolize" height="70" src="/images/symbolize.png" width="45" />),
80
+ %(image_tag("http://www.rubyonrails.com/images/rails")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />)
77
81
  }
78
82
 
79
83
  def test_auto_discovery
@@ -94,7 +98,7 @@ class AssetTagHelperTest < Test::Unit::TestCase
94
98
  ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'lib1', '/elsewhere/blub/lib2'
95
99
  assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>\n<script src="/javascripts/lib1.js" type="text/javascript"></script>\n<script src="/elsewhere/blub/lib2.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
96
100
  end
97
-
101
+
98
102
  def test_style_path
99
103
  StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
100
104
  end
@@ -174,6 +178,7 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
174
178
  %(image_tag("rss", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/calloboration/hieraki/images/rss.png" />),
175
179
  %(image_tag("gold", :size => "45x70")) => %(<img alt="Gold" height="70" src="/calloboration/hieraki/images/gold.png" width="45" />),
176
180
  %(image_tag("http://www.example.com/images/icon.gif")) => %(<img alt="Icon" src="http://www.example.com/images/icon.gif" />),
181
+ %(image_tag("symbolize", "size" => "45x70")) => %(<img alt="Symbolize" height="70" src="/calloboration/hieraki/images/symbolize.png" width="45" />)
177
182
  }
178
183
 
179
184
  def test_auto_discovery
@@ -1,9 +1,13 @@
1
1
  require 'test/unit'
2
- require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
3
2
  require File.dirname(__FILE__) + "/../abstract_unit"
4
3
 
5
4
  class DateHelperTest < Test::Unit::TestCase
6
5
  include ActionView::Helpers::DateHelper
6
+ include ActionView::Helpers::FormHelper
7
+
8
+ silence_warnings do
9
+ Post = Struct.new("Post", :written_on, :updated_at)
10
+ end
7
11
 
8
12
  def test_distance_in_words
9
13
  from = Time.mktime(2004, 3, 6, 21, 41, 18)
@@ -497,6 +501,38 @@ class DateHelperTest < Test::Unit::TestCase
497
501
  assert_equal expected, select_date(0, :start_year => 2003, :end_year => 2005, :prefix => "date[first]")
498
502
  end
499
503
 
504
+ def test_date_select_within_fields_for
505
+ @post = Post.new
506
+ @post.written_on = Date.new(2004, 6, 15)
507
+
508
+ _erbout = ''
509
+
510
+ fields_for :post, @post do |f|
511
+ _erbout.concat f.date_select(:written_on)
512
+ end
513
+
514
+ expected = "<select name='post[written_on(1i)]'>\n<option value='1999'>1999</option>\n<option value='2000'>2000</option>\n<option value='2001'>2001</option>\n<option value='2002'>2002</option>\n<option value='2003'>2003</option>\n<option selected='selected' value='2004'>2004</option>\n<option value='2005'>2005</option>\n<option value='2006'>2006</option>\n<option value='2007'>2007</option>\n<option value='2008'>2008</option>\n<option value='2009'>2009</option>\n</select>\n" +
515
+ "<select name='post[written_on(2i)]'>\n<option value='1'>January</option>\n<option value='2'>February</option>\n<option value='3'>March</option>\n<option value='4'>April</option>\n<option value='5'>May</option>\n<option selected='selected' value='6'>June</option>\n<option value='7'>July</option>\n<option value='8'>August</option>\n<option value='9'>September</option>\n<option value='10'>October</option>\n<option value='11'>November</option>\n<option value='12'>December</option>\n</select>\n" +
516
+ "<select name='post[written_on(3i)]'>\n<option value='1'>1</option>\n<option value='2'>2</option>\n<option value='3'>3</option>\n<option value='4'>4</option>\n<option value='5'>5</option>\n<option value='6'>6</option>\n<option value='7'>7</option>\n<option value='8'>8</option>\n<option value='9'>9</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 selected='selected' 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<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</select>\n"
517
+
518
+ assert_dom_equal(expected, _erbout)
519
+ end
520
+
521
+ def test_datetime_select_within_fields_for
522
+ @post = Post.new
523
+ @post.updated_at = Time.local(2004, 6, 15, 16, 35)
524
+
525
+ _erbout = ''
526
+
527
+ fields_for :post, @post do |f|
528
+ _erbout.concat f.datetime_select(:updated_at)
529
+ end
530
+
531
+ expected = "<select name='post[updated_at(1i)]'>\n<option value='1999'>1999</option>\n<option value='2000'>2000</option>\n<option value='2001'>2001</option>\n<option value='2002'>2002</option>\n<option value='2003'>2003</option>\n<option selected='selected' value='2004'>2004</option>\n<option value='2005'>2005</option>\n<option value='2006'>2006</option>\n<option value='2007'>2007</option>\n<option value='2008'>2008</option>\n<option value='2009'>2009</option>\n</select>\n<select name='post[updated_at(2i)]'>\n<option value='1'>January</option>\n<option value='2'>February</option>\n<option value='3'>March</option>\n<option value='4'>April</option>\n<option value='5'>May</option>\n<option selected='selected' value='6'>June</option>\n<option value='7'>July</option>\n<option value='8'>August</option>\n<option value='9'>September</option>\n<option value='10'>October</option>\n<option value='11'>November</option>\n<option value='12'>December</option>\n</select>\n<select name='post[updated_at(3i)]'>\n<option value='1'>1</option>\n<option value='2'>2</option>\n<option value='3'>3</option>\n<option value='4'>4</option>\n<option value='5'>5</option>\n<option value='6'>6</option>\n<option value='7'>7</option>\n<option value='8'>8</option>\n<option value='9'>9</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 selected='selected' 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<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</select>\n &mdash; <select name='post[updated_at(4i)]'>\n<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 selected='selected' 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</select>\n : <select name='post[updated_at(5i)]'>\n<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'>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 selected='selected' 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</select>\n"
532
+
533
+ assert_dom_equal(expected, _erbout)
534
+ end
535
+
500
536
  def test_date_select_with_zero_value_and_no_start_year
501
537
  expected = %(<select name="date[first][year]">\n)
502
538
  (Date.today.year-5).upto(Date.today.year+1) { |y| expected << %(<option value="#{y}">#{y}</option>\n) }
@@ -516,7 +552,8 @@ class DateHelperTest < Test::Unit::TestCase
516
552
 
517
553
  def test_date_select_with_zero_value_and_no_end_year
518
554
  expected = %(<select name="date[first][year]">\n)
519
- 2003.upto(2010) { |y| expected << %(<option value="#{y}">#{y}</option>\n) }
555
+ last_year = Time.now.year + 5
556
+ 2003.upto(last_year) { |y| expected << %(<option value="#{y}">#{y}</option>\n) }
520
557
  expected << "</select>\n"
521
558
 
522
559
  expected << %(<select name="date[first][month]">\n)
@@ -1,10 +1,11 @@
1
- require 'test/unit'
2
- require 'erb'
3
- require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_helper'
4
- require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/hash' #for stringify keys
1
+ require File.dirname(__FILE__) + '/../abstract_unit'
5
2
 
6
3
  class FormHelperTest < Test::Unit::TestCase
7
4
  include ActionView::Helpers::FormHelper
5
+ include ActionView::Helpers::FormTagHelper
6
+ include ActionView::Helpers::UrlHelper
7
+ include ActionView::Helpers::TagHelper
8
+ include ActionView::Helpers::TextHelper
8
9
 
9
10
  silence_warnings do
10
11
  Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on, :cost)
@@ -27,6 +28,15 @@ class FormHelperTest < Test::Unit::TestCase
27
28
  @post.body = "Back to the hill and over it again!"
28
29
  @post.secret = 1
29
30
  @post.written_on = Date.new(2004, 6, 15)
31
+
32
+ @controller = Class.new do
33
+ attr_reader :url_for_options
34
+ def url_for(options, *parameters_for_method_reference)
35
+ @url_for_options = options
36
+ "http://www.example.com"
37
+ end
38
+ end
39
+ @controller = @controller.new
30
40
  end
31
41
 
32
42
  def test_text_field
@@ -60,6 +70,13 @@ class FormHelperTest < Test::Unit::TestCase
60
70
  assert_dom_equal expected, text_field("post", "title", :maxlength => 35)
61
71
  end
62
72
 
73
+ def test_text_field_doesnt_change_param_values
74
+ object_name = 'post[]'
75
+ expected = '<input id="post_123_title" name="post[123][title]" size="30" type="text" value="Hello World" />'
76
+ assert_equal expected, text_field(object_name, "title")
77
+ assert_equal object_name, "post[]"
78
+ end
79
+
63
80
  def test_check_box
64
81
  assert_dom_equal(
65
82
  '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
@@ -118,7 +135,14 @@ class FormHelperTest < Test::Unit::TestCase
118
135
  text_area("post", "body")
119
136
  )
120
137
  end
121
-
138
+
139
+ def test_text_area_with_alternate_value
140
+ assert_dom_equal(
141
+ '<textarea cols="40" id="post_body" name="post[body]" rows="20">Testing alternate values.</textarea>',
142
+ text_area("post", "body", :value => 'Testing alternate values.')
143
+ )
144
+ end
145
+
122
146
  def test_date_selects
123
147
  assert_dom_equal(
124
148
  '<textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea>',
@@ -187,4 +211,213 @@ class FormHelperTest < Test::Unit::TestCase
187
211
  radio_button("post[]", "title", "Goodbye World")
188
212
  )
189
213
  end
214
+
215
+ def test_form_for
216
+ _erbout = ''
217
+
218
+ form_for(:post, @post, :html => { :id => 'create-post' }) do |f|
219
+ _erbout.concat f.text_field(:title)
220
+ _erbout.concat f.text_area(:body)
221
+ _erbout.concat f.check_box(:secret)
222
+ end
223
+
224
+ expected =
225
+ "<form action='http://www.example.com' id='create-post' method='post'>" +
226
+ "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
227
+ "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
228
+ "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
229
+ "<input name='post[secret]' type='hidden' value='0' />" +
230
+ "</form>"
231
+
232
+ assert_dom_equal expected, _erbout
233
+ end
234
+
235
+ def test_form_for_without_object
236
+ _erbout = ''
237
+
238
+ form_for(:post, :html => { :id => 'create-post' }) do |f|
239
+ _erbout.concat f.text_field(:title)
240
+ _erbout.concat f.text_area(:body)
241
+ _erbout.concat f.check_box(:secret)
242
+ end
243
+
244
+ expected =
245
+ "<form action='http://www.example.com' id='create-post' method='post'>" +
246
+ "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
247
+ "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
248
+ "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
249
+ "<input name='post[secret]' type='hidden' value='0' />" +
250
+ "</form>"
251
+
252
+ assert_dom_equal expected, _erbout
253
+ end
254
+
255
+ def test_fields_for
256
+ _erbout = ''
257
+
258
+ fields_for(:post, @post) do |f|
259
+ _erbout.concat f.text_field(:title)
260
+ _erbout.concat f.text_area(:body)
261
+ _erbout.concat f.check_box(:secret)
262
+ end
263
+
264
+ expected =
265
+ "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
266
+ "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
267
+ "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
268
+ "<input name='post[secret]' type='hidden' value='0' />"
269
+
270
+ assert_dom_equal expected, _erbout
271
+ end
272
+
273
+ def test_fields_for_without_object
274
+ _erbout = ''
275
+ fields_for(:post) do |f|
276
+ _erbout.concat f.text_field(:title)
277
+ _erbout.concat f.text_area(:body)
278
+ _erbout.concat f.check_box(:secret)
279
+ end
280
+
281
+ expected =
282
+ "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
283
+ "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
284
+ "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
285
+ "<input name='post[secret]' type='hidden' value='0' />"
286
+
287
+ assert_dom_equal expected, _erbout
288
+ end
289
+
290
+ def test_form_builder_does_not_have_form_for_method
291
+ assert ! ActionView::Helpers::FormBuilder.instance_methods.include?('form_for')
292
+ end
293
+
294
+ def test_form_for_and_fields_for
295
+ _erbout = ''
296
+
297
+ form_for(:post, @post, :html => { :id => 'create-post' }) do |post_form|
298
+ _erbout.concat post_form.text_field(:title)
299
+ _erbout.concat post_form.text_area(:body)
300
+
301
+ fields_for(:parent_post, @post) do |parent_fields|
302
+ _erbout.concat parent_fields.check_box(:secret)
303
+ end
304
+ end
305
+
306
+ expected =
307
+ "<form action='http://www.example.com' id='create-post' method='post'>" +
308
+ "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
309
+ "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
310
+ "<input name='parent_post[secret]' checked='checked' type='checkbox' id='parent_post_secret' value='1' />" +
311
+ "<input name='parent_post[secret]' type='hidden' value='0' />" +
312
+ "</form>"
313
+
314
+ assert_dom_equal expected, _erbout
315
+ end
316
+
317
+ class LabelledFormBuilder < ActionView::Helpers::FormBuilder
318
+ (field_helpers - %w(hidden_field)).each do |selector|
319
+ src = <<-END_SRC
320
+ def #{selector}(field, *args, &proc)
321
+ "<label for='\#{field}'>\#{field.to_s.humanize}:</label> " + super + "<br/>"
322
+ end
323
+ END_SRC
324
+ class_eval src, __FILE__, __LINE__
325
+ end
326
+ end
327
+
328
+ def test_form_for_with_labelled_builder
329
+ _erbout = ''
330
+
331
+ form_for(:post, @post, :builder => LabelledFormBuilder) do |f|
332
+ _erbout.concat f.text_field(:title)
333
+ _erbout.concat f.text_area(:body)
334
+ _erbout.concat f.check_box(:secret)
335
+ end
336
+
337
+ expected =
338
+ "<form action='http://www.example.com' method='post'>" +
339
+ "<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
340
+ "<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
341
+ "<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
342
+ "<input name='post[secret]' type='hidden' value='0' /><br/>" +
343
+ "</form>"
344
+
345
+ assert_dom_equal expected, _erbout
346
+ end
347
+
348
+ # Perhaps this test should be moved to prototype helper tests.
349
+ def test_remote_form_for_with_labelled_builder
350
+ self.extend ActionView::Helpers::PrototypeHelper
351
+ _erbout = ''
352
+
353
+ remote_form_for(:post, @post, :builder => LabelledFormBuilder) do |f|
354
+ _erbout.concat f.text_field(:title)
355
+ _erbout.concat f.text_area(:body)
356
+ _erbout.concat f.check_box(:secret)
357
+ end
358
+
359
+ expected =
360
+ %(<form action="http://www.example.com" onsubmit="new Ajax.Request('http://www.example.com', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" method="post">) +
361
+ "<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
362
+ "<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
363
+ "<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
364
+ "<input name='post[secret]' type='hidden' value='0' /><br/>" +
365
+ "</form>"
366
+
367
+ assert_dom_equal expected, _erbout
368
+ end
369
+
370
+ def test_fields_for_with_labelled_builder
371
+ _erbout = ''
372
+
373
+ fields_for(:post, @post, :builder => LabelledFormBuilder) do |f|
374
+ _erbout.concat f.text_field(:title)
375
+ _erbout.concat f.text_area(:body)
376
+ _erbout.concat f.check_box(:secret)
377
+ end
378
+
379
+ expected =
380
+ "<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
381
+ "<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
382
+ "<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
383
+ "<input name='post[secret]' type='hidden' value='0' /><br/>"
384
+
385
+ assert_dom_equal expected, _erbout
386
+ end
387
+
388
+ def test_form_for_with_html_options_adds_options_to_form_tag
389
+ _erbout = ''
390
+
391
+ form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
392
+ expected = "<form action=\"http://www.example.com\" class=\"some_class\" id=\"some_form\" method=\"post\"></form>"
393
+
394
+ assert_dom_equal expected, _erbout
395
+ end
396
+
397
+ def test_form_for_with_string_url_option
398
+ _erbout = ''
399
+
400
+ form_for(:post, @post, :url => 'http://www.otherdomain.com') do |f| end
401
+
402
+ assert_equal 'http://www.otherdomain.com', @controller.url_for_options
403
+ end
404
+
405
+ def test_form_for_with_hash_url_option
406
+ _erbout = ''
407
+
408
+ form_for(:post, @post, :url => {:controller => 'controller', :action => 'action'}) do |f| end
409
+
410
+ assert_equal 'controller', @controller.url_for_options[:controller]
411
+ assert_equal 'action', @controller.url_for_options[:action]
412
+ end
413
+
414
+ def test_remote_form_for_with_html_options_adds_options_to_form_tag
415
+ self.extend ActionView::Helpers::PrototypeHelper
416
+ _erbout = ''
417
+
418
+ remote_form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
419
+ expected = "<form action=\"http://www.example.com\" class=\"some_class\" id=\"some_form\" method=\"post\" onsubmit=\"new Ajax.Request('http://www.example.com', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\"></form>"
420
+
421
+ assert_dom_equal expected, _erbout
422
+ end
190
423
  end