actionpack 2.2.3 → 2.3.2

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 (264) hide show
  1. data/CHANGELOG +433 -375
  2. data/MIT-LICENSE +1 -1
  3. data/README +21 -75
  4. data/Rakefile +1 -1
  5. data/lib/action_controller.rb +80 -43
  6. data/lib/action_controller/assertions/model_assertions.rb +1 -0
  7. data/lib/action_controller/assertions/response_assertions.rb +43 -16
  8. data/lib/action_controller/assertions/routing_assertions.rb +1 -1
  9. data/lib/action_controller/assertions/selector_assertions.rb +17 -12
  10. data/lib/action_controller/assertions/tag_assertions.rb +1 -4
  11. data/lib/action_controller/base.rb +153 -82
  12. data/lib/action_controller/benchmarking.rb +9 -9
  13. data/lib/action_controller/caching.rb +9 -11
  14. data/lib/action_controller/caching/actions.rb +11 -18
  15. data/lib/action_controller/caching/fragments.rb +28 -20
  16. data/lib/action_controller/caching/pages.rb +13 -15
  17. data/lib/action_controller/caching/sweeping.rb +2 -2
  18. data/lib/action_controller/cgi_ext.rb +0 -1
  19. data/lib/action_controller/cgi_ext/cookie.rb +2 -0
  20. data/lib/action_controller/cgi_process.rb +54 -162
  21. data/lib/action_controller/cookies.rb +13 -25
  22. data/lib/action_controller/dispatcher.rb +43 -122
  23. data/lib/action_controller/failsafe.rb +52 -0
  24. data/lib/action_controller/flash.rb +38 -47
  25. data/lib/action_controller/helpers.rb +13 -9
  26. data/lib/action_controller/http_authentication.rb +203 -23
  27. data/lib/action_controller/integration.rb +126 -70
  28. data/lib/action_controller/layout.rb +36 -39
  29. data/lib/action_controller/middleware_stack.rb +119 -0
  30. data/lib/action_controller/middlewares.rb +13 -0
  31. data/lib/action_controller/mime_responds.rb +19 -4
  32. data/lib/action_controller/mime_type.rb +8 -0
  33. data/lib/action_controller/params_parser.rb +71 -0
  34. data/lib/action_controller/performance_test.rb +0 -1
  35. data/lib/action_controller/polymorphic_routes.rb +36 -30
  36. data/lib/action_controller/reloader.rb +14 -0
  37. data/lib/action_controller/request.rb +107 -499
  38. data/lib/action_controller/request_forgery_protection.rb +7 -39
  39. data/lib/action_controller/rescue.rb +55 -35
  40. data/lib/action_controller/resources.rb +34 -31
  41. data/lib/action_controller/response.rb +99 -57
  42. data/lib/action_controller/rewindable_input.rb +28 -0
  43. data/lib/action_controller/routing.rb +7 -7
  44. data/lib/action_controller/routing/builder.rb +4 -1
  45. data/lib/action_controller/routing/optimisations.rb +1 -1
  46. data/lib/action_controller/routing/recognition_optimisation.rb +1 -2
  47. data/lib/action_controller/routing/route.rb +15 -5
  48. data/lib/action_controller/routing/route_set.rb +82 -35
  49. data/lib/action_controller/routing/segments.rb +35 -0
  50. data/lib/action_controller/session/abstract_store.rb +181 -0
  51. data/lib/action_controller/session/cookie_store.rb +197 -175
  52. data/lib/action_controller/session/mem_cache_store.rb +36 -83
  53. data/lib/action_controller/session_management.rb +26 -134
  54. data/lib/action_controller/streaming.rb +24 -7
  55. data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
  56. data/lib/action_controller/templates/rescues/template_error.erb +2 -2
  57. data/lib/action_controller/test_case.rb +87 -30
  58. data/lib/action_controller/test_process.rb +145 -104
  59. data/lib/action_controller/uploaded_file.rb +44 -0
  60. data/lib/action_controller/url_rewriter.rb +3 -6
  61. data/lib/action_controller/vendor/html-scanner.rb +16 -0
  62. data/lib/action_controller/vendor/html-scanner/html/selector.rb +1 -1
  63. data/lib/action_controller/vendor/rack-1.0/rack.rb +89 -0
  64. data/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +22 -0
  65. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +37 -0
  66. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +37 -0
  67. data/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +58 -0
  68. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +124 -0
  69. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +51 -0
  70. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +55 -0
  71. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +40 -0
  72. data/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +480 -0
  73. data/lib/action_controller/vendor/rack-1.0/rack/builder.rb +63 -0
  74. data/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +36 -0
  75. data/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +49 -0
  76. data/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +61 -0
  77. data/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +45 -0
  78. data/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +29 -0
  79. data/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +23 -0
  80. data/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +85 -0
  81. data/lib/action_controller/vendor/rack-1.0/rack/directory.rb +153 -0
  82. data/lib/action_controller/vendor/rack-1.0/rack/file.rb +88 -0
  83. data/lib/action_controller/vendor/rack-1.0/rack/handler.rb +48 -0
  84. data/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +61 -0
  85. data/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +8 -0
  86. data/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +89 -0
  87. data/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +55 -0
  88. data/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +84 -0
  89. data/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +59 -0
  90. data/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +8 -0
  91. data/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +18 -0
  92. data/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +67 -0
  93. data/lib/action_controller/vendor/rack-1.0/rack/head.rb +19 -0
  94. data/lib/action_controller/vendor/rack-1.0/rack/lint.rb +462 -0
  95. data/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +65 -0
  96. data/lib/action_controller/vendor/rack-1.0/rack/lock.rb +16 -0
  97. data/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +27 -0
  98. data/lib/action_controller/vendor/rack-1.0/rack/mime.rb +204 -0
  99. data/lib/action_controller/vendor/rack-1.0/rack/mock.rb +160 -0
  100. data/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +57 -0
  101. data/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +64 -0
  102. data/lib/action_controller/vendor/rack-1.0/rack/request.rb +241 -0
  103. data/lib/action_controller/vendor/rack-1.0/rack/response.rb +179 -0
  104. data/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +142 -0
  105. data/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +91 -0
  106. data/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +109 -0
  107. data/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +100 -0
  108. data/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +349 -0
  109. data/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +106 -0
  110. data/lib/action_controller/vendor/rack-1.0/rack/static.rb +38 -0
  111. data/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +55 -0
  112. data/lib/action_controller/vendor/rack-1.0/rack/utils.rb +392 -0
  113. data/lib/action_controller/verification.rb +1 -1
  114. data/lib/action_pack.rb +1 -1
  115. data/lib/action_pack/version.rb +2 -2
  116. data/lib/action_view.rb +22 -17
  117. data/lib/action_view/base.rb +53 -79
  118. data/lib/action_view/erb/util.rb +38 -0
  119. data/lib/action_view/helpers.rb +24 -5
  120. data/lib/action_view/helpers/active_record_helper.rb +2 -2
  121. data/lib/action_view/helpers/asset_tag_helper.rb +81 -50
  122. data/lib/action_view/helpers/atom_feed_helper.rb +1 -1
  123. data/lib/action_view/helpers/benchmark_helper.rb +26 -5
  124. data/lib/action_view/helpers/date_helper.rb +82 -7
  125. data/lib/action_view/helpers/form_helper.rb +295 -64
  126. data/lib/action_view/helpers/form_options_helper.rb +160 -18
  127. data/lib/action_view/helpers/form_tag_helper.rb +2 -2
  128. data/lib/action_view/helpers/number_helper.rb +31 -18
  129. data/lib/action_view/helpers/prototype_helper.rb +2 -12
  130. data/lib/action_view/helpers/sanitize_helper.rb +0 -10
  131. data/lib/action_view/helpers/scriptaculous_helper.rb +1 -0
  132. data/lib/action_view/helpers/tag_helper.rb +3 -4
  133. data/lib/action_view/helpers/text_helper.rb +99 -122
  134. data/lib/action_view/helpers/translation_helper.rb +19 -1
  135. data/lib/action_view/helpers/url_helper.rb +25 -2
  136. data/lib/action_view/inline_template.rb +1 -1
  137. data/lib/action_view/locale/en.yml +19 -1
  138. data/lib/action_view/partials.rb +46 -9
  139. data/lib/action_view/paths.rb +28 -84
  140. data/lib/action_view/reloadable_template.rb +117 -0
  141. data/lib/action_view/renderable.rb +28 -35
  142. data/lib/action_view/renderable_partial.rb +3 -4
  143. data/lib/action_view/template.rb +172 -31
  144. data/lib/action_view/template_error.rb +8 -9
  145. data/lib/action_view/template_handler.rb +1 -1
  146. data/lib/action_view/template_handlers.rb +9 -6
  147. data/lib/action_view/template_handlers/erb.rb +2 -39
  148. data/lib/action_view/template_handlers/rjs.rb +1 -0
  149. data/lib/action_view/test_case.rb +27 -1
  150. data/test/abstract_unit.rb +23 -17
  151. data/test/active_record_unit.rb +5 -4
  152. data/test/activerecord/active_record_store_test.rb +139 -106
  153. data/test/activerecord/render_partial_with_record_identification_test.rb +5 -21
  154. data/test/controller/action_pack_assertions_test.rb +25 -23
  155. data/test/controller/addresses_render_test.rb +3 -6
  156. data/test/controller/assert_select_test.rb +83 -70
  157. data/test/controller/base_test.rb +11 -13
  158. data/test/controller/benchmark_test.rb +3 -3
  159. data/test/controller/caching_test.rb +34 -24
  160. data/test/controller/capture_test.rb +3 -6
  161. data/test/controller/content_type_test.rb +3 -6
  162. data/test/controller/cookie_test.rb +31 -66
  163. data/test/controller/deprecation/deprecated_base_methods_test.rb +9 -11
  164. data/test/controller/dispatcher_test.rb +23 -28
  165. data/test/controller/fake_models.rb +8 -0
  166. data/test/controller/filters_test.rb +6 -2
  167. data/test/controller/flash_test.rb +2 -6
  168. data/test/controller/helper_test.rb +15 -1
  169. data/test/controller/html-scanner/document_test.rb +1 -1
  170. data/test/controller/html-scanner/sanitizer_test.rb +1 -1
  171. data/test/controller/http_basic_authentication_test.rb +88 -0
  172. data/test/controller/http_digest_authentication_test.rb +178 -0
  173. data/test/controller/integration_test.rb +56 -52
  174. data/test/controller/layout_test.rb +46 -44
  175. data/test/controller/middleware_stack_test.rb +90 -0
  176. data/test/controller/mime_responds_test.rb +7 -11
  177. data/test/controller/mime_type_test.rb +9 -0
  178. data/test/controller/polymorphic_routes_test.rb +235 -151
  179. data/test/controller/rack_test.rb +52 -81
  180. data/test/controller/redirect_test.rb +6 -14
  181. data/test/controller/render_test.rb +273 -60
  182. data/test/controller/request/json_params_parsing_test.rb +45 -0
  183. data/test/controller/request/multipart_params_parsing_test.rb +223 -0
  184. data/test/controller/request/query_string_parsing_test.rb +120 -0
  185. data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
  186. data/test/controller/request/xml_params_parsing_test.rb +88 -0
  187. data/test/controller/request_forgery_protection_test.rb +17 -98
  188. data/test/controller/request_test.rb +45 -530
  189. data/test/controller/rescue_test.rb +45 -22
  190. data/test/controller/resources_test.rb +112 -37
  191. data/test/controller/routing_test.rb +1442 -1384
  192. data/test/controller/selector_test.rb +3 -3
  193. data/test/controller/send_file_test.rb +30 -3
  194. data/test/controller/session/cookie_store_test.rb +169 -240
  195. data/test/controller/session/mem_cache_store_test.rb +94 -148
  196. data/test/controller/session/test_session_test.rb +58 -0
  197. data/test/controller/test_test.rb +32 -13
  198. data/test/controller/url_rewriter_test.rb +54 -4
  199. data/test/controller/verification_test.rb +1 -1
  200. data/test/controller/view_paths_test.rb +15 -15
  201. data/test/controller/webservice_test.rb +178 -147
  202. data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
  203. data/test/fixtures/layout_tests/alt/layouts/alt.rhtml +0 -0
  204. data/test/fixtures/layouts/default_html.html.erb +1 -0
  205. data/test/fixtures/layouts/xhr.html.erb +2 -0
  206. data/test/fixtures/multipart/empty +10 -0
  207. data/test/fixtures/multipart/hello.txt +1 -0
  208. data/test/fixtures/multipart/none +9 -0
  209. data/test/fixtures/public/500.da.html +1 -0
  210. data/test/fixtures/quiz/questions/_question.html.erb +1 -0
  211. data/test/fixtures/replies.yml +1 -1
  212. data/test/fixtures/test/_one.html.erb +1 -0
  213. data/test/fixtures/test/_two.html.erb +1 -0
  214. data/test/fixtures/test/dont_pick_me +1 -0
  215. data/test/fixtures/test/hello.builder +1 -1
  216. data/test/fixtures/test/hello_world.da.html.erb +1 -0
  217. data/test/fixtures/test/hello_world.erb~ +1 -0
  218. data/test/fixtures/test/hello_world.pt-BR.html.erb +1 -0
  219. data/test/fixtures/test/malformed/malformed.en.html.erb~ +1 -0
  220. data/test/fixtures/test/malformed/malformed.erb~ +1 -0
  221. data/test/fixtures/test/malformed/malformed.html.erb~ +1 -0
  222. data/test/fixtures/test/render_explicit_html_template.js.rjs +1 -0
  223. data/test/fixtures/test/render_implicit_html_template.js.rjs +1 -0
  224. data/test/fixtures/test/render_implicit_html_template_from_xhr_request.da.html.erb +1 -0
  225. data/test/fixtures/test/render_implicit_html_template_from_xhr_request.html.erb +1 -0
  226. data/test/fixtures/test/render_implicit_js_template_without_layout.js.erb +1 -0
  227. data/test/fixtures/test/utf8.html.erb +2 -0
  228. data/test/template/active_record_helper_i18n_test.rb +31 -33
  229. data/test/template/active_record_helper_test.rb +34 -0
  230. data/test/template/asset_tag_helper_test.rb +52 -14
  231. data/test/template/atom_feed_helper_test.rb +3 -5
  232. data/test/template/benchmark_helper_test.rb +50 -24
  233. data/test/template/compiled_templates_test.rb +177 -33
  234. data/test/template/date_helper_i18n_test.rb +88 -81
  235. data/test/template/date_helper_test.rb +427 -43
  236. data/test/template/form_helper_test.rb +243 -44
  237. data/test/template/form_options_helper_test.rb +631 -565
  238. data/test/template/form_tag_helper_test.rb +9 -2
  239. data/test/template/javascript_helper_test.rb +0 -5
  240. data/test/template/number_helper_i18n_test.rb +60 -48
  241. data/test/template/number_helper_test.rb +1 -0
  242. data/test/template/render_test.rb +117 -35
  243. data/test/template/test_test.rb +4 -6
  244. data/test/template/text_helper_test.rb +129 -50
  245. data/test/template/translation_helper_test.rb +23 -19
  246. data/test/template/url_helper_test.rb +35 -2
  247. data/test/view/test_case_test.rb +8 -0
  248. metadata +197 -23
  249. data/lib/action_controller/assertions.rb +0 -69
  250. data/lib/action_controller/caching/sql_cache.rb +0 -18
  251. data/lib/action_controller/cgi_ext/session.rb +0 -53
  252. data/lib/action_controller/components.rb +0 -169
  253. data/lib/action_controller/rack_process.rb +0 -297
  254. data/lib/action_controller/request_profiler.rb +0 -169
  255. data/lib/action_controller/session/active_record_store.rb +0 -340
  256. data/lib/action_controller/session/drb_server.rb +0 -32
  257. data/lib/action_controller/session/drb_store.rb +0 -35
  258. data/test/controller/cgi_test.rb +0 -269
  259. data/test/controller/components_test.rb +0 -156
  260. data/test/controller/http_authentication_test.rb +0 -54
  261. data/test/controller/integration_upload_test.rb +0 -43
  262. data/test/controller/session_fixation_test.rb +0 -89
  263. data/test/controller/session_management_test.rb +0 -178
  264. data/test/fixtures/test/hello_world.js +0 -1
@@ -1,11 +1,10 @@
1
1
  require 'abstract_unit'
2
- require 'action_controller/rack_process'
3
2
 
4
3
  class BaseRackTest < Test::Unit::TestCase
5
4
  def setup
6
5
  @env = {
7
6
  "HTTP_MAX_FORWARDS" => "10",
8
- "SERVER_NAME" => "glu.ttono.us:8007",
7
+ "SERVER_NAME" => "glu.ttono.us",
9
8
  "FCGI_ROLE" => "RESPONDER",
10
9
  "AUTH_TYPE" => "Basic",
11
10
  "HTTP_X_FORWARDED_HOST" => "glu.ttono.us",
@@ -44,10 +43,10 @@ class BaseRackTest < Test::Unit::TestCase
44
43
  "REDIRECT_STATUS" => "200",
45
44
  "REQUEST_METHOD" => "GET"
46
45
  }
47
- @request = ActionController::RackRequest.new(@env)
46
+ @request = ActionController::Request.new(@env)
48
47
  # some Nokia phone browsers omit the space after the semicolon separator.
49
48
  # some developers have grown accustomed to using comma in cookie values.
50
- @alt_cookie_fmt_request = ActionController::RackRequest.new(@env.merge({"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"}))
49
+ @alt_cookie_fmt_request = ActionController::Request.new(@env.merge({"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"}))
51
50
  end
52
51
 
53
52
  def default_test; end
@@ -58,67 +57,67 @@ class BaseRackTest < Test::Unit::TestCase
58
57
  @request.env['REQUEST_METHOD'] = 'POST'
59
58
  @request.env['CONTENT_LENGTH'] = data.length
60
59
  @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
61
- @request.env['RAW_POST_DATA'] = data
60
+ @request.env['rack.input'] = StringIO.new(data)
62
61
  end
63
62
  end
64
63
 
65
64
  class RackRequestTest < BaseRackTest
66
65
  def test_proxy_request
67
- assert_equal 'glu.ttono.us', @request.host_with_port(true)
66
+ assert_equal 'glu.ttono.us', @request.host_with_port
68
67
  end
69
68
 
70
69
  def test_http_host
71
70
  @env.delete "HTTP_X_FORWARDED_HOST"
72
71
  @env['HTTP_HOST'] = "rubyonrails.org:8080"
73
- assert_equal "rubyonrails.org", @request.host(true)
74
- assert_equal "rubyonrails.org:8080", @request.host_with_port(true)
72
+ assert_equal "rubyonrails.org", @request.host
73
+ assert_equal "rubyonrails.org:8080", @request.host_with_port
75
74
 
76
75
  @env['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org"
77
- assert_equal "www.secondhost.org", @request.host(true)
76
+ assert_equal "www.secondhost.org", @request.host
78
77
  end
79
78
 
80
79
  def test_http_host_with_default_port_overrides_server_port
81
80
  @env.delete "HTTP_X_FORWARDED_HOST"
82
81
  @env['HTTP_HOST'] = "rubyonrails.org"
83
- assert_equal "rubyonrails.org", @request.host_with_port(true)
82
+ assert_equal "rubyonrails.org", @request.host_with_port
84
83
  end
85
84
 
86
85
  def test_host_with_port_defaults_to_server_name_if_no_host_headers
87
86
  @env.delete "HTTP_X_FORWARDED_HOST"
88
87
  @env.delete "HTTP_HOST"
89
- assert_equal "glu.ttono.us:8007", @request.host_with_port(true)
88
+ assert_equal "glu.ttono.us:8007", @request.host_with_port
90
89
  end
91
90
 
92
91
  def test_host_with_port_falls_back_to_server_addr_if_necessary
93
92
  @env.delete "HTTP_X_FORWARDED_HOST"
94
93
  @env.delete "HTTP_HOST"
95
94
  @env.delete "SERVER_NAME"
96
- assert_equal "207.7.108.53", @request.host(true)
97
- assert_equal 8007, @request.port(true)
98
- assert_equal "207.7.108.53:8007", @request.host_with_port(true)
95
+ assert_equal "207.7.108.53", @request.host
96
+ assert_equal 8007, @request.port
97
+ assert_equal "207.7.108.53:8007", @request.host_with_port
99
98
  end
100
99
 
101
100
  def test_host_with_port_if_http_standard_port_is_specified
102
101
  @env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:80"
103
- assert_equal "glu.ttono.us", @request.host_with_port(true)
102
+ assert_equal "glu.ttono.us", @request.host_with_port
104
103
  end
105
104
 
106
105
  def test_host_with_port_if_https_standard_port_is_specified
107
106
  @env['HTTP_X_FORWARDED_PROTO'] = "https"
108
107
  @env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:443"
109
- assert_equal "glu.ttono.us", @request.host_with_port(true)
108
+ assert_equal "glu.ttono.us", @request.host_with_port
110
109
  end
111
110
 
112
111
  def test_host_if_ipv6_reference
113
112
  @env.delete "HTTP_X_FORWARDED_HOST"
114
113
  @env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]"
115
- assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host(true)
114
+ assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host
116
115
  end
117
116
 
118
117
  def test_host_if_ipv6_reference_with_port
119
118
  @env.delete "HTTP_X_FORWARDED_HOST"
120
119
  @env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]:8008"
121
- assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host(true)
120
+ assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host
122
121
  end
123
122
 
124
123
  def test_cgi_environment_variables
@@ -146,7 +145,7 @@ class RackRequestTest < BaseRackTest
146
145
  assert_equal "kevin", @request.remote_user
147
146
  assert_equal :get, @request.request_method
148
147
  assert_equal "/dispatch.fcgi", @request.script_name
149
- assert_equal "glu.ttono.us:8007", @request.server_name
148
+ assert_equal "glu.ttono.us", @request.server_name
150
149
  assert_equal 8007, @request.server_port
151
150
  assert_equal "HTTP/1.1", @request.server_protocol
152
151
  assert_equal "lighttpd", @request.server_software
@@ -154,12 +153,12 @@ class RackRequestTest < BaseRackTest
154
153
 
155
154
  def test_cookie_syntax_resilience
156
155
  cookies = @request.cookies
157
- assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], cookies["_session_id"], cookies.inspect
158
- assert_equal ["yes"], cookies["is_admin"], cookies.inspect
156
+ assert_equal "c84ace84796670c052c6ceb2451fb0f2", cookies["_session_id"], cookies.inspect
157
+ assert_equal "yes", cookies["is_admin"], cookies.inspect
159
158
 
160
159
  alt_cookies = @alt_cookie_fmt_request.cookies
161
- assert_equal ["c84ace847,96670c052c6ceb2451fb0f2"], alt_cookies["_session_id"], alt_cookies.inspect
162
- assert_equal ["yes"], alt_cookies["is_admin"], alt_cookies.inspect
160
+ #assert_equal "c84ace847,96670c052c6ceb2451fb0f2", alt_cookies["_session_id"], alt_cookies.inspect
161
+ assert_equal "yes", alt_cookies["is_admin"], alt_cookies.inspect
163
162
  end
164
163
  end
165
164
 
@@ -188,29 +187,6 @@ class RackRequestContentTypeTest < BaseRackTest
188
187
  end
189
188
  end
190
189
 
191
- class RackRequestMethodTest < BaseRackTest
192
- def test_get
193
- assert_equal :get, @request.request_method
194
- end
195
-
196
- def test_post
197
- @request.env['REQUEST_METHOD'] = 'POST'
198
- assert_equal :post, @request.request_method
199
- end
200
-
201
- def test_put
202
- set_content_data '_method=put'
203
-
204
- assert_equal :put, @request.request_method
205
- end
206
-
207
- def test_delete
208
- set_content_data '_method=delete'
209
-
210
- assert_equal :delete, @request.request_method
211
- end
212
- end
213
-
214
190
  class RackRequestNeedsRewoundTest < BaseRackTest
215
191
  def test_body_should_be_rewound
216
192
  data = 'foo'
@@ -219,7 +195,7 @@ class RackRequestNeedsRewoundTest < BaseRackTest
219
195
  @env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
220
196
 
221
197
  # Read the request body by parsing params.
222
- request = ActionController::RackRequest.new(@env)
198
+ request = ActionController::Request.new(@env)
223
199
  request.request_parameters
224
200
 
225
201
  # Should have rewound the body.
@@ -230,21 +206,20 @@ end
230
206
  class RackResponseTest < BaseRackTest
231
207
  def setup
232
208
  super
233
- @response = ActionController::RackResponse.new(@request)
234
- @output = StringIO.new('')
209
+ @response = ActionController::Response.new
235
210
  end
236
211
 
237
212
  def test_simple_output
238
213
  @response.body = "Hello, World!"
239
214
  @response.prepare!
240
215
 
241
- status, headers, body = @response.out(@output)
242
- assert_equal "200 OK", status
216
+ status, headers, body = @response.to_a
217
+ assert_equal 200, status
243
218
  assert_equal({
244
219
  "Content-Type" => "text/html; charset=utf-8",
245
220
  "Cache-Control" => "private, max-age=0, must-revalidate",
246
221
  "ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"',
247
- "Set-Cookie" => [],
222
+ "Set-Cookie" => "",
248
223
  "Content-Length" => "13"
249
224
  }, headers)
250
225
 
@@ -253,60 +228,56 @@ class RackResponseTest < BaseRackTest
253
228
  assert_equal ["Hello, World!"], parts
254
229
  end
255
230
 
256
- def test_streaming_block
257
- @response.body = Proc.new do |response, output|
258
- 5.times { |n| output.write(n) }
259
- end
231
+ def test_utf8_output
232
+ @response.body = [1090, 1077, 1089, 1090].pack("U*")
260
233
  @response.prepare!
261
234
 
262
- status, headers, body = @response.out(@output)
263
- assert_equal "200 OK", status
264
- assert_equal({"Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers)
265
-
266
- parts = []
267
- body.each { |part| parts << part }
268
- assert_equal ["0", "1", "2", "3", "4"], parts
235
+ status, headers, body = @response.to_a
236
+ assert_equal 200, status
237
+ assert_equal({
238
+ "Content-Type" => "text/html; charset=utf-8",
239
+ "Cache-Control" => "private, max-age=0, must-revalidate",
240
+ "ETag" => '"ebb5e89e8a94e9dd22abf5d915d112b2"',
241
+ "Set-Cookie" => "",
242
+ "Content-Length" => "8"
243
+ }, headers)
269
244
  end
270
245
 
271
- def test_set_session_cookie
272
- cookie = CGI::Cookie.new({"name" => "name", "value" => "Josh"})
273
- @request.cgi.send :instance_variable_set, '@output_cookies', [cookie]
274
-
275
- @response.body = "Hello, World!"
246
+ def test_streaming_block
247
+ @response.body = Proc.new do |response, output|
248
+ 5.times { |n| output.write(n) }
249
+ end
276
250
  @response.prepare!
277
251
 
278
- status, headers, body = @response.out(@output)
279
- assert_equal "200 OK", status
252
+ status, headers, body = @response.to_a
253
+ assert_equal 200, status
280
254
  assert_equal({
281
255
  "Content-Type" => "text/html; charset=utf-8",
282
- "Cache-Control" => "private, max-age=0, must-revalidate",
283
- "ETag" => '"65a8e27d8879283831b664bd8b7f0ad4"',
284
- "Set-Cookie" => ["name=Josh; path="],
285
- "Content-Length" => "13"
256
+ "Cache-Control" => "no-cache",
257
+ "Set-Cookie" => ""
286
258
  }, headers)
287
259
 
288
260
  parts = []
289
261
  body.each { |part| parts << part }
290
- assert_equal ["Hello, World!"], parts
262
+ assert_equal ["0", "1", "2", "3", "4"], parts
291
263
  end
292
264
  end
293
265
 
294
266
  class RackResponseHeadersTest < BaseRackTest
295
267
  def setup
296
268
  super
297
- @response = ActionController::RackResponse.new(@request)
298
- @output = StringIO.new('')
299
- @response.headers['Status'] = "200 OK"
269
+ @response = ActionController::Response.new
270
+ @response.status = "200 OK"
300
271
  end
301
272
 
302
273
  def test_content_type
303
274
  [204, 304].each do |c|
304
- @response.headers['Status'] = c.to_s
275
+ @response.status = c.to_s
305
276
  assert !response_headers.has_key?("Content-Type"), "#{c} should not have Content-Type header"
306
277
  end
307
278
 
308
279
  [200, 302, 404, 500].each do |c|
309
- @response.headers['Status'] = c.to_s
280
+ @response.status = c.to_s
310
281
  assert response_headers.has_key?("Content-Type"), "#{c} did not have Content-Type header"
311
282
  end
312
283
  end
@@ -318,6 +289,6 @@ class RackResponseHeadersTest < BaseRackTest
318
289
  private
319
290
  def response_headers
320
291
  @response.prepare!
321
- @response.out(@output)[1]
292
+ @response.to_a[1]
322
293
  end
323
294
  end
@@ -103,12 +103,8 @@ class RedirectController < ActionController::Base
103
103
  end
104
104
  end
105
105
 
106
- class RedirectTest < Test::Unit::TestCase
107
- def setup
108
- @controller = RedirectController.new
109
- @request = ActionController::TestRequest.new
110
- @response = ActionController::TestResponse.new
111
- end
106
+ class RedirectTest < ActionController::TestCase
107
+ tests RedirectController
112
108
 
113
109
  def test_simple_redirect
114
110
  get :simple_redirect
@@ -216,7 +212,7 @@ class RedirectTest < Test::Unit::TestCase
216
212
  end
217
213
 
218
214
  def test_redirect_to_back_with_no_referer
219
- assert_raises(ActionController::RedirectBackError) {
215
+ assert_raise(ActionController::RedirectBackError) {
220
216
  @request.env["HTTP_REFERER"] = nil
221
217
  get :redirect_to_back
222
218
  }
@@ -243,7 +239,7 @@ class RedirectTest < Test::Unit::TestCase
243
239
  end
244
240
 
245
241
  def test_redirect_to_nil
246
- assert_raises(ActionController::ActionControllerError) do
242
+ assert_raise(ActionController::ActionControllerError) do
247
243
  get :redirect_to_nil
248
244
  end
249
245
  end
@@ -256,12 +252,8 @@ module ModuleTest
256
252
  end
257
253
  end
258
254
 
259
- class ModuleRedirectTest < Test::Unit::TestCase
260
- def setup
261
- @controller = ModuleRedirectController.new
262
- @request = ActionController::TestRequest.new
263
- @response = ActionController::TestResponse.new
264
- end
255
+ class ModuleRedirectTest < ActionController::TestCase
256
+ tests ModuleRedirectController
265
257
 
266
258
  def test_simple_redirect
267
259
  get :simple_redirect
@@ -21,6 +21,8 @@ class MockLogger
21
21
  end
22
22
 
23
23
  class TestController < ActionController::Base
24
+ protect_from_forgery
25
+
24
26
  class LabellingFormBuilder < ActionView::Helpers::FormBuilder
25
27
  end
26
28
 
@@ -34,6 +36,39 @@ class TestController < ActionController::Base
34
36
  render :action => 'hello_world'
35
37
  end
36
38
  end
39
+
40
+ def conditional_hello_with_public_header
41
+ if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123], :public => true)
42
+ render :action => 'hello_world'
43
+ end
44
+ end
45
+
46
+ def conditional_hello_with_public_header_and_expires_at
47
+ expires_in 1.minute
48
+ if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123], :public => true)
49
+ render :action => 'hello_world'
50
+ end
51
+ end
52
+
53
+ def conditional_hello_with_expires_in
54
+ expires_in 1.minute
55
+ render :action => 'hello_world'
56
+ end
57
+
58
+ def conditional_hello_with_expires_in_with_public
59
+ expires_in 1.minute, :public => true
60
+ render :action => 'hello_world'
61
+ end
62
+
63
+ def conditional_hello_with_expires_in_with_public_with_more_keys
64
+ expires_in 1.minute, :public => true, 'max-stale' => 5.hours
65
+ render :action => 'hello_world'
66
+ end
67
+
68
+ def conditional_hello_with_expires_in_with_public_with_more_keys_old_syntax
69
+ expires_in 1.minute, :public => true, :private => nil, 'max-stale' => 5.hours
70
+ render :action => 'hello_world'
71
+ end
37
72
 
38
73
  def conditional_hello_with_bangs
39
74
  render :action => 'hello_world'
@@ -79,6 +114,10 @@ class TestController < ActionController::Base
79
114
  render :action => "hello_world"
80
115
  end
81
116
 
117
+ def render_action_hello_world_as_string
118
+ render "hello_world"
119
+ end
120
+
82
121
  def render_action_hello_world_with_symbol
83
122
  render :action => :hello_world
84
123
  end
@@ -102,6 +141,12 @@ class TestController < ActionController::Base
102
141
  render :file => path
103
142
  end
104
143
 
144
+ def render_file_as_string_with_instance_variables
145
+ @secret = 'in the sauce'
146
+ path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb'))
147
+ render path
148
+ end
149
+
105
150
  def render_file_not_using_full_path
106
151
  @secret = 'in the sauce'
107
152
  render :file => 'test/render_file_with_ivar'
@@ -112,6 +157,11 @@ class TestController < ActionController::Base
112
157
  render :file => 'test/dot.directory/render_file_with_ivar'
113
158
  end
114
159
 
160
+ def render_file_using_pathname
161
+ @secret = 'in the sauce'
162
+ render :file => Pathname.new(File.dirname(__FILE__)).join('..', 'fixtures', 'test', 'dot.directory', 'render_file_with_ivar.erb')
163
+ end
164
+
115
165
  def render_file_from_template
116
166
  @secret = 'in the sauce'
117
167
  @path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb'))
@@ -122,6 +172,11 @@ class TestController < ActionController::Base
122
172
  render :file => path, :locals => {:secret => 'in the sauce'}
123
173
  end
124
174
 
175
+ def render_file_as_string_with_locals
176
+ path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.erb'))
177
+ render path, :locals => {:secret => 'in the sauce'}
178
+ end
179
+
125
180
  def accessing_request_in_template
126
181
  render :inline => "Hello: <%= request.host %>"
127
182
  end
@@ -180,10 +235,6 @@ class TestController < ActionController::Base
180
235
  render :text => "appended"
181
236
  end
182
237
 
183
- def render_invalid_args
184
- render("test/hello")
185
- end
186
-
187
238
  def render_vanilla_js_hello
188
239
  render :js => "alert('hello')"
189
240
  end
@@ -193,6 +244,11 @@ class TestController < ActionController::Base
193
244
  render :template => "test/hello"
194
245
  end
195
246
 
247
+ def render_xml_hello_as_string_template
248
+ @name = "David"
249
+ render "test/hello"
250
+ end
251
+
196
252
  def render_xml_with_custom_content_type
197
253
  render :xml => "<blah/>", :content_type => "application/atomsvc+xml"
198
254
  end
@@ -209,6 +265,10 @@ class TestController < ActionController::Base
209
265
  # let's just rely on the template
210
266
  end
211
267
 
268
+ def blank_response
269
+ render :text => ' '
270
+ end
271
+
212
272
  def layout_test
213
273
  render :action => "hello_world"
214
274
  end
@@ -246,13 +306,20 @@ class TestController < ActionController::Base
246
306
  :locals => { :local_name => name }
247
307
  end
248
308
 
249
- def helper_method_to_render_to_string(*args)
250
- render_to_string(*args)
309
+ def render_implicit_html_template
251
310
  end
252
- helper_method :helper_method_to_render_to_string
253
311
 
254
- def render_html_only_partial_within_inline
255
- render :inline => "Hello world <%= helper_method_to_render_to_string :partial => 'test/partial_with_only_html_version' %>"
312
+ def render_explicit_html_template
313
+ end
314
+
315
+ def render_implicit_html_template_from_xhr_request
316
+ end
317
+
318
+ def render_implicit_js_template_without_layout
319
+ end
320
+
321
+ def render_html_explicit_template_and_layout
322
+ render :template => 'test/render_implicit_html_template_from_xhr_request', :layout => 'layouts/default_html'
256
323
  end
257
324
 
258
325
  def formatted_html_erb
@@ -281,6 +348,14 @@ class TestController < ActionController::Base
281
348
  render :action => "hello_world", :layout => "standard"
282
349
  end
283
350
 
351
+ def layout_test_with_different_layout_and_string_action
352
+ render "hello_world", :layout => "standard"
353
+ end
354
+
355
+ def layout_test_with_different_layout_and_symbol_action
356
+ render :hello_world, :layout => "standard"
357
+ end
358
+
284
359
  def rendering_without_layout
285
360
  render :action => "hello_world", :layout => false
286
361
  end
@@ -322,6 +397,10 @@ class TestController < ActionController::Base
322
397
  render :template => "test/hello_world"
323
398
  end
324
399
 
400
+ def render_with_explicit_string_template
401
+ render "test/hello_world"
402
+ end
403
+
325
404
  def render_with_explicit_template_with_locals
326
405
  render :template => "test/render_file_with_locals", :locals => { :secret => 'area51' }
327
406
  end
@@ -608,6 +687,14 @@ class TestController < ActionController::Base
608
687
  render :partial => "hash_object", :object => {:first_name => "Sam"}
609
688
  end
610
689
 
690
+ def partial_with_nested_object
691
+ render :partial => "quiz/questions/question", :object => Quiz::Question.new("first")
692
+ end
693
+
694
+ def partial_with_nested_object_shorthand
695
+ render Quiz::Question.new("first")
696
+ end
697
+
611
698
  def partial_hash_collection
612
699
  render :partial => "hash_object", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ]
613
700
  end
@@ -644,23 +731,26 @@ class TestController < ActionController::Base
644
731
  "accessing_params_in_template",
645
732
  "accessing_params_in_template_with_layout",
646
733
  "render_with_explicit_template",
734
+ "render_with_explicit_string_template",
647
735
  "render_js_with_explicit_template",
648
736
  "render_js_with_explicit_action_template",
649
737
  "delete_with_js", "update_page", "update_page_with_instance_variables"
650
738
 
651
739
  "layouts/standard"
740
+ when "render_implicit_js_template_without_layout"
741
+ "layouts/default_html"
652
742
  when "action_talk_to_layout", "layout_overriding_layout"
653
743
  "layouts/talk_from_action"
744
+ when "render_implicit_html_template_from_xhr_request"
745
+ (request.xhr? ? 'layouts/xhr' : 'layouts/standard')
654
746
  end
655
747
  end
656
748
  end
657
749
 
658
- class RenderTest < Test::Unit::TestCase
659
- def setup
660
- @request = ActionController::TestRequest.new
661
- @response = ActionController::TestResponse.new
662
- @controller = TestController.new
750
+ class RenderTest < ActionController::TestCase
751
+ tests TestController
663
752
 
753
+ def setup
664
754
  # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
665
755
  # a more accurate simulation of what happens in "real life".
666
756
  @controller.logger = Logger.new(nil)
@@ -725,6 +815,12 @@ class RenderTest < Test::Unit::TestCase
725
815
  assert_template "test/hello_world"
726
816
  end
727
817
 
818
+ def test_render_action_hello_world_as_string
819
+ get :render_action_hello_world_as_string
820
+ assert_equal "Hello world!", @response.body
821
+ assert_template "test/hello_world"
822
+ end
823
+
728
824
  def test_render_action_with_symbol
729
825
  get :render_action_hello_world_with_symbol
730
826
  assert_template "test/hello_world"
@@ -740,6 +836,11 @@ class RenderTest < Test::Unit::TestCase
740
836
  assert_equal "<html>hello world, I'm here!</html>", @response.body
741
837
  end
742
838
 
839
+ def test_xhr_with_render_text_and_layout
840
+ xhr :get, :render_text_hello_world_with_layout
841
+ assert_equal "<html>hello world, I'm here!</html>", @response.body
842
+ end
843
+
743
844
  def test_do_with_render_action_and_layout_false
744
845
  get :hello_world_with_layout_false
745
846
  assert_equal 'Hello world!', @response.body
@@ -750,6 +851,11 @@ class RenderTest < Test::Unit::TestCase
750
851
  assert_equal "The secret is in the sauce\n", @response.body
751
852
  end
752
853
 
854
+ def test_render_file_as_string_with_instance_variables
855
+ get :render_file_as_string_with_instance_variables
856
+ assert_equal "The secret is in the sauce\n", @response.body
857
+ end
858
+
753
859
  def test_render_file_not_using_full_path
754
860
  get :render_file_not_using_full_path
755
861
  assert_equal "The secret is in the sauce\n", @response.body
@@ -760,11 +866,21 @@ class RenderTest < Test::Unit::TestCase
760
866
  assert_equal "The secret is in the sauce\n", @response.body
761
867
  end
762
868
 
869
+ def test_render_file_using_pathname
870
+ get :render_file_using_pathname
871
+ assert_equal "The secret is in the sauce\n", @response.body
872
+ end
873
+
763
874
  def test_render_file_with_locals
764
875
  get :render_file_with_locals
765
876
  assert_equal "The secret is in the sauce\n", @response.body
766
877
  end
767
878
 
879
+ def test_render_file_as_string_with_locals
880
+ get :render_file_as_string_with_locals
881
+ assert_equal "The secret is in the sauce\n", @response.body
882
+ end
883
+
768
884
  def test_render_file_from_template
769
885
  get :render_file_from_template
770
886
  assert_equal "The secret is in the sauce\n", @response.body
@@ -830,16 +946,12 @@ class RenderTest < Test::Unit::TestCase
830
946
  assert_equal 'appended', @response.body
831
947
  end
832
948
 
833
- def test_attempt_to_render_with_invalid_arguments
834
- assert_raises(ActionController::RenderError) { get :render_invalid_args }
835
- end
836
-
837
949
  def test_attempt_to_access_object_method
838
- assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
950
+ assert_raise(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
839
951
  end
840
952
 
841
953
  def test_private_methods
842
- assert_raises(ActionController::UnknownAction, "No action responded to [determine_layout]") { get :determine_layout }
954
+ assert_raise(ActionController::UnknownAction, "No action responded to [determine_layout]") { get :determine_layout }
843
955
  end
844
956
 
845
957
  def test_access_to_request_in_view
@@ -869,10 +981,13 @@ class RenderTest < Test::Unit::TestCase
869
981
  end
870
982
 
871
983
  def test_render_xml
872
- assert_deprecated do
873
- get :render_xml_hello
874
- end
984
+ get :render_xml_hello
985
+ assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
986
+ assert_equal "application/xml", @response.content_type
987
+ end
875
988
 
989
+ def test_render_xml_as_string_template
990
+ get :render_xml_hello_as_string_template
876
991
  assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
877
992
  assert_equal "application/xml", @response.content_type
878
993
  end
@@ -888,12 +1003,13 @@ class RenderTest < Test::Unit::TestCase
888
1003
  end
889
1004
 
890
1005
  def test_enum_rjs_test
1006
+ ActiveSupport::SecureRandom.stubs(:base64).returns("asdf")
891
1007
  get :enum_rjs_test
892
1008
  body = %{
893
1009
  $$(".product").each(function(value, index) {
894
1010
  new Effect.Highlight(element,{});
895
1011
  new Effect.Highlight(value,{});
896
- Sortable.create(value, {onUpdate:function(){new Ajax.Request('/test/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(value)})}});
1012
+ Sortable.create(value, {onUpdate:function(){new Ajax.Request('/test/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(value) + '&authenticity_token=' + encodeURIComponent('asdf')})}});
897
1013
  new Draggable(value, {});
898
1014
  });
899
1015
  }.gsub(/^ /, '').strip
@@ -906,10 +1022,7 @@ class RenderTest < Test::Unit::TestCase
906
1022
  end
907
1023
 
908
1024
  def test_render_xml_with_layouts
909
- assert_deprecated do
910
- get :builder_layout_test
911
- end
912
-
1025
+ get :builder_layout_test
913
1026
  assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body
914
1027
  end
915
1028
 
@@ -949,9 +1062,37 @@ class RenderTest < Test::Unit::TestCase
949
1062
  assert_equal "Goodbye, Local David", @response.body
950
1063
  end
951
1064
 
952
- def test_rendering_html_only_partial_within_inline_with_js
953
- get :render_html_only_partial_within_inline, :format => :js
954
- assert_equal "Hello world partial with only html version", @response.body
1065
+ def test_render_in_an_rjs_template_should_pick_html_templates_when_available
1066
+ [:js, "js"].each do |format|
1067
+ assert_nothing_raised do
1068
+ get :render_implicit_html_template, :format => format
1069
+ assert_equal %(document.write("Hello world\\n");), @response.body
1070
+ end
1071
+ end
1072
+ end
1073
+
1074
+ def test_explicitly_rendering_an_html_template_with_implicit_html_template_renders_should_be_possible_from_an_rjs_template
1075
+ [:js, "js"].each do |format|
1076
+ assert_nothing_raised do
1077
+ get :render_explicit_html_template, :format => format
1078
+ assert_equal %(document.write("Hello world\\n");), @response.body
1079
+ end
1080
+ end
1081
+ end
1082
+
1083
+ def test_should_implicitly_render_html_template_from_xhr_request
1084
+ xhr :get, :render_implicit_html_template_from_xhr_request
1085
+ assert_equal "XHR!\nHello HTML!", @response.body
1086
+ end
1087
+
1088
+ def test_should_render_explicit_html_template_with_html_layout
1089
+ xhr :get, :render_html_explicit_template_and_layout
1090
+ assert_equal "<html>Hello HTML!</html>\n", @response.body
1091
+ end
1092
+
1093
+ def test_should_implicitly_render_js_template_without_layout
1094
+ get :render_implicit_js_template_without_layout, :format => :js
1095
+ assert_no_match /<html>/, @response.body
955
1096
  end
956
1097
 
957
1098
  def test_should_render_formatted_template
@@ -1005,6 +1146,16 @@ class RenderTest < Test::Unit::TestCase
1005
1146
  assert_equal "<html>Hello world!</html>", @response.body
1006
1147
  end
1007
1148
 
1149
+ def test_layout_test_with_different_layout_and_string_action
1150
+ get :layout_test_with_different_layout_and_string_action
1151
+ assert_equal "<html>Hello world!</html>", @response.body
1152
+ end
1153
+
1154
+ def test_layout_test_with_different_layout_and_symbol_action
1155
+ get :layout_test_with_different_layout_and_symbol_action
1156
+ assert_equal "<html>Hello world!</html>", @response.body
1157
+ end
1158
+
1008
1159
  def test_rendering_without_layout
1009
1160
  get :rendering_without_layout
1010
1161
  assert_equal "Hello world!", @response.body
@@ -1032,7 +1183,7 @@ class RenderTest < Test::Unit::TestCase
1032
1183
  end
1033
1184
 
1034
1185
  def test_bad_render_to_string_still_throws_exception
1035
- assert_raises(ActionView::MissingTemplate) { get :render_to_string_with_exception }
1186
+ assert_raise(ActionView::MissingTemplate) { get :render_to_string_with_exception }
1036
1187
  end
1037
1188
 
1038
1189
  def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns
@@ -1051,16 +1202,21 @@ class RenderTest < Test::Unit::TestCase
1051
1202
  assert_response :success
1052
1203
  end
1053
1204
 
1205
+ def test_render_with_explicit_string_template
1206
+ get :render_with_explicit_string_template
1207
+ assert_equal "<html>Hello world!</html>", @response.body
1208
+ end
1209
+
1054
1210
  def test_double_render
1055
- assert_raises(ActionController::DoubleRenderError) { get :double_render }
1211
+ assert_raise(ActionController::DoubleRenderError) { get :double_render }
1056
1212
  end
1057
1213
 
1058
1214
  def test_double_redirect
1059
- assert_raises(ActionController::DoubleRenderError) { get :double_redirect }
1215
+ assert_raise(ActionController::DoubleRenderError) { get :double_redirect }
1060
1216
  end
1061
1217
 
1062
1218
  def test_render_and_redirect
1063
- assert_raises(ActionController::DoubleRenderError) { get :render_and_redirect }
1219
+ assert_raise(ActionController::DoubleRenderError) { get :render_and_redirect }
1064
1220
  end
1065
1221
 
1066
1222
  # specify the one exception to double render rule - render_to_string followed by render
@@ -1092,14 +1248,14 @@ class RenderTest < Test::Unit::TestCase
1092
1248
  def test_update_page
1093
1249
  get :update_page
1094
1250
  assert_template nil
1095
- assert_equal 'text/javascript; charset=utf-8', @response.headers['type']
1251
+ assert_equal 'text/javascript; charset=utf-8', @response.headers['Content-Type']
1096
1252
  assert_equal 2, @response.body.split($/).length
1097
1253
  end
1098
1254
 
1099
1255
  def test_update_page_with_instance_variables
1100
1256
  get :update_page_with_instance_variables
1101
1257
  assert_template nil
1102
- assert_equal 'text/javascript; charset=utf-8', @response.headers['type']
1258
+ assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"]
1103
1259
  assert_match /balance/, @response.body
1104
1260
  assert_match /\$37/, @response.body
1105
1261
  end
@@ -1107,7 +1263,7 @@ class RenderTest < Test::Unit::TestCase
1107
1263
  def test_update_page_with_view_method
1108
1264
  get :update_page_with_view_method
1109
1265
  assert_template nil
1110
- assert_equal 'text/javascript; charset=utf-8', @response.headers['type']
1266
+ assert_equal 'text/javascript; charset=utf-8', @response.headers["Content-Type"]
1111
1267
  assert_match /2 people/, @response.body
1112
1268
  end
1113
1269
 
@@ -1140,13 +1296,18 @@ class RenderTest < Test::Unit::TestCase
1140
1296
 
1141
1297
  def test_head_with_symbolic_status
1142
1298
  get :head_with_symbolic_status, :status => "ok"
1143
- assert_equal "200 OK", @response.headers["Status"]
1299
+ assert_equal "200 OK", @response.status
1144
1300
  assert_response :ok
1145
1301
 
1146
1302
  get :head_with_symbolic_status, :status => "not_found"
1147
- assert_equal "404 Not Found", @response.headers["Status"]
1303
+ assert_equal "404 Not Found", @response.status
1148
1304
  assert_response :not_found
1149
1305
 
1306
+ get :head_with_symbolic_status, :status => "no_content"
1307
+ assert_equal "204 No Content", @response.status
1308
+ assert !@response.headers.include?('Content-Length')
1309
+ assert_response :no_content
1310
+
1150
1311
  ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code|
1151
1312
  get :head_with_symbolic_status, :status => status.to_s
1152
1313
  assert_equal code, @response.response_code
@@ -1307,21 +1468,28 @@ class RenderTest < Test::Unit::TestCase
1307
1468
  def test_partial_collection_with_spacer
1308
1469
  get :partial_collection_with_spacer
1309
1470
  assert_equal "Hello: davidonly partialHello: mary", @response.body
1471
+ assert_template :partial => 'test/_partial_only'
1472
+ assert_template :partial => '_customer'
1310
1473
  end
1311
1474
 
1312
1475
  def test_partial_collection_shorthand_with_locals
1313
1476
  get :partial_collection_shorthand_with_locals
1314
1477
  assert_equal "Bonjour: davidBonjour: mary", @response.body
1478
+ assert_template :partial => 'customers/_customer', :count => 2
1479
+ assert_template :partial => '_completely_fake_and_made_up_template_that_cannot_possibly_be_rendered', :count => 0
1315
1480
  end
1316
1481
 
1317
1482
  def test_partial_collection_shorthand_with_different_types_of_records
1318
1483
  get :partial_collection_shorthand_with_different_types_of_records
1319
1484
  assert_equal "Bonjour bad customer: mark0Bonjour good customer: craig1Bonjour bad customer: john2Bonjour good customer: zach3Bonjour good customer: brandon4Bonjour bad customer: dan5", @response.body
1485
+ assert_template :partial => 'good_customers/_good_customer', :count => 3
1486
+ assert_template :partial => 'bad_customers/_bad_customer', :count => 3
1320
1487
  end
1321
1488
 
1322
1489
  def test_empty_partial_collection
1323
1490
  get :empty_partial_collection
1324
1491
  assert_equal " ", @response.body
1492
+ assert_template :partial => false
1325
1493
  end
1326
1494
 
1327
1495
  def test_partial_with_hash_object
@@ -1329,6 +1497,16 @@ class RenderTest < Test::Unit::TestCase
1329
1497
  assert_equal "Sam\nmaS\n", @response.body
1330
1498
  end
1331
1499
 
1500
+ def test_partial_with_nested_object
1501
+ get :partial_with_nested_object
1502
+ assert_equal "first", @response.body
1503
+ end
1504
+
1505
+ def test_partial_with_nested_object_shorthand
1506
+ get :partial_with_nested_object_shorthand
1507
+ assert_equal "first", @response.body
1508
+ end
1509
+
1332
1510
  def test_hash_partial_collection
1333
1511
  get :partial_hash_collection
1334
1512
  assert_equal "Pratik\nkitarP\nAmy\nymA\n", @response.body
@@ -1347,7 +1525,7 @@ class RenderTest < Test::Unit::TestCase
1347
1525
  end
1348
1526
 
1349
1527
  def test_render_missing_partial_template
1350
- assert_raises(ActionView::MissingTemplate) do
1528
+ assert_raise(ActionView::MissingTemplate) do
1351
1529
  get :missing_partial
1352
1530
  end
1353
1531
  end
@@ -1363,16 +1541,48 @@ class RenderTest < Test::Unit::TestCase
1363
1541
  end
1364
1542
  end
1365
1543
 
1366
- class EtagRenderTest < Test::Unit::TestCase
1544
+ class ExpiresInRenderTest < ActionController::TestCase
1545
+ tests TestController
1546
+
1367
1547
  def setup
1368
- @request = ActionController::TestRequest.new
1369
- @response = ActionController::TestResponse.new
1370
- @controller = TestController.new
1548
+ @request.host = "www.nextangle.com"
1549
+ end
1550
+
1551
+ def test_expires_in_header
1552
+ get :conditional_hello_with_expires_in
1553
+ assert_equal "max-age=60, private", @response.headers["Cache-Control"]
1554
+ end
1555
+
1556
+ def test_expires_in_header_with_public
1557
+ get :conditional_hello_with_expires_in_with_public
1558
+ assert_equal "max-age=60, public", @response.headers["Cache-Control"]
1559
+ end
1560
+
1561
+ def test_expires_in_header_with_additional_headers
1562
+ get :conditional_hello_with_expires_in_with_public_with_more_keys
1563
+ assert_equal "max-age=60, public, max-stale=18000", @response.headers["Cache-Control"]
1564
+ end
1565
+
1566
+ def test_expires_in_old_syntax
1567
+ get :conditional_hello_with_expires_in_with_public_with_more_keys_old_syntax
1568
+ assert_equal "max-age=60, public, max-stale=18000", @response.headers["Cache-Control"]
1569
+ end
1570
+ end
1571
+
1371
1572
 
1573
+ class EtagRenderTest < ActionController::TestCase
1574
+ tests TestController
1575
+
1576
+ def setup
1372
1577
  @request.host = "www.nextangle.com"
1373
1578
  @expected_bang_etag = etag_for(expand_key([:foo, 123]))
1374
1579
  end
1375
1580
 
1581
+ def test_render_blank_body_shouldnt_set_etag
1582
+ get :blank_response
1583
+ assert !@response.etag?
1584
+ end
1585
+
1376
1586
  def test_render_200_should_set_etag
1377
1587
  get :render_hello_world_from_variable
1378
1588
  assert_equal etag_for("hello david"), @response.headers['ETag']
@@ -1389,7 +1599,7 @@ class EtagRenderTest < Test::Unit::TestCase
1389
1599
  def test_render_against_etag_request_should_have_no_content_length_when_match
1390
1600
  @request.if_none_match = etag_for("hello david")
1391
1601
  get :render_hello_world_from_variable
1392
- assert !@response.headers.has_key?("Content-Length")
1602
+ assert !@response.headers.has_key?("Content-Length"), @response.headers['Content-Length']
1393
1603
  end
1394
1604
 
1395
1605
  def test_render_against_etag_request_should_200_when_no_match
@@ -1433,10 +1643,7 @@ class EtagRenderTest < Test::Unit::TestCase
1433
1643
  end
1434
1644
 
1435
1645
  def test_etag_should_govern_renders_with_layouts_too
1436
- assert_deprecated do
1437
- get :builder_layout_test
1438
- end
1439
-
1646
+ get :builder_layout_test
1440
1647
  assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body
1441
1648
  assert_equal etag_for("<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n"), @response.headers['ETag']
1442
1649
  end
@@ -1452,6 +1659,16 @@ class EtagRenderTest < Test::Unit::TestCase
1452
1659
  get :conditional_hello_with_bangs
1453
1660
  assert_response :not_modified
1454
1661
  end
1662
+
1663
+ def test_etag_with_public_true_should_set_header
1664
+ get :conditional_hello_with_public_header
1665
+ assert_equal "public", @response.headers['Cache-Control']
1666
+ end
1667
+
1668
+ def test_etag_with_public_true_should_set_header_and_retain_other_headers
1669
+ get :conditional_hello_with_public_header_and_expires_at
1670
+ assert_equal "max-age=60, public", @response.headers['Cache-Control']
1671
+ end
1455
1672
 
1456
1673
  protected
1457
1674
  def etag_for(text)
@@ -1463,12 +1680,10 @@ class EtagRenderTest < Test::Unit::TestCase
1463
1680
  end
1464
1681
  end
1465
1682
 
1466
- class LastModifiedRenderTest < Test::Unit::TestCase
1467
- def setup
1468
- @request = ActionController::TestRequest.new
1469
- @response = ActionController::TestResponse.new
1470
- @controller = TestController.new
1683
+ class LastModifiedRenderTest < ActionController::TestCase
1684
+ tests TestController
1471
1685
 
1686
+ def setup
1472
1687
  @request.host = "www.nextangle.com"
1473
1688
  @last_modified = Time.now.utc.beginning_of_day.httpdate
1474
1689
  end
@@ -1520,12 +1735,10 @@ class LastModifiedRenderTest < Test::Unit::TestCase
1520
1735
  end
1521
1736
  end
1522
1737
 
1523
- class RenderingLoggingTest < Test::Unit::TestCase
1524
- def setup
1525
- @request = ActionController::TestRequest.new
1526
- @response = ActionController::TestResponse.new
1527
- @controller = TestController.new
1738
+ class RenderingLoggingTest < ActionController::TestCase
1739
+ tests TestController
1528
1740
 
1741
+ def setup
1529
1742
  @request.host = "www.nextangle.com"
1530
1743
  end
1531
1744