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,32 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # This is a really simple session storage daemon, basically just a hash,
4
- # which is enabled for DRb access.
5
-
6
- require 'drb'
7
-
8
- session_hash = Hash.new
9
- session_hash.instance_eval { @mutex = Mutex.new }
10
-
11
- class <<session_hash
12
- def []=(key, value)
13
- @mutex.synchronize do
14
- super(key, value)
15
- end
16
- end
17
-
18
- def [](key)
19
- @mutex.synchronize do
20
- super(key)
21
- end
22
- end
23
-
24
- def delete(key)
25
- @mutex.synchronize do
26
- super(key)
27
- end
28
- end
29
- end
30
-
31
- DRb.start_service('druby://127.0.0.1:9192', session_hash)
32
- DRb.thread.join
@@ -1,35 +0,0 @@
1
- require 'cgi'
2
- require 'cgi/session'
3
- require 'drb'
4
-
5
- class CGI #:nodoc:all
6
- class Session
7
- class DRbStore
8
- @@session_data = DRbObject.new(nil, 'druby://localhost:9192')
9
-
10
- def initialize(session, option=nil)
11
- @session_id = session.session_id
12
- end
13
-
14
- def restore
15
- @h = @@session_data[@session_id] || {}
16
- end
17
-
18
- def update
19
- @@session_data[@session_id] = @h
20
- end
21
-
22
- def close
23
- update
24
- end
25
-
26
- def delete
27
- @@session_data.delete(@session_id)
28
- end
29
-
30
- def data
31
- @@session_data[@session_id]
32
- end
33
- end
34
- end
35
- end
@@ -1,269 +0,0 @@
1
- require 'abstract_unit'
2
- require 'action_controller/cgi_process'
3
-
4
- class BaseCgiTest < Test::Unit::TestCase
5
- def setup
6
- @request_hash = {
7
- "HTTP_MAX_FORWARDS" => "10",
8
- "SERVER_NAME" => "glu.ttono.us:8007",
9
- "FCGI_ROLE" => "RESPONDER",
10
- "AUTH_TYPE" => "Basic",
11
- "HTTP_X_FORWARDED_HOST" => "glu.ttono.us",
12
- "HTTP_ACCEPT_CHARSET" => "UTF-8",
13
- "HTTP_ACCEPT_ENCODING" => "gzip, deflate",
14
- "HTTP_CACHE_CONTROL" => "no-cache, max-age=0",
15
- "HTTP_PRAGMA" => "no-cache",
16
- "HTTP_USER_AGENT" => "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)",
17
- "PATH_INFO" => "/homepage/",
18
- "HTTP_ACCEPT_LANGUAGE" => "en",
19
- "HTTP_NEGOTIATE" => "trans",
20
- "HTTP_HOST" => "glu.ttono.us:8007",
21
- "HTTP_REFERER" => "http://www.google.com/search?q=glu.ttono.us",
22
- "HTTP_FROM" => "googlebot",
23
- "SERVER_PROTOCOL" => "HTTP/1.1",
24
- "REDIRECT_URI" => "/dispatch.fcgi",
25
- "SCRIPT_NAME" => "/dispatch.fcgi",
26
- "SERVER_ADDR" => "207.7.108.53",
27
- "REMOTE_ADDR" => "207.7.108.53",
28
- "REMOTE_HOST" => "google.com",
29
- "REMOTE_IDENT" => "kevin",
30
- "REMOTE_USER" => "kevin",
31
- "SERVER_SOFTWARE" => "lighttpd/1.4.5",
32
- "HTTP_COOKIE" => "_session_id=c84ace84796670c052c6ceb2451fb0f2; is_admin=yes",
33
- "HTTP_X_FORWARDED_SERVER" => "glu.ttono.us",
34
- "REQUEST_URI" => "/admin",
35
- "DOCUMENT_ROOT" => "/home/kevinc/sites/typo/public",
36
- "PATH_TRANSLATED" => "/home/kevinc/sites/typo/public/homepage/",
37
- "SERVER_PORT" => "8007",
38
- "QUERY_STRING" => "",
39
- "REMOTE_PORT" => "63137",
40
- "GATEWAY_INTERFACE" => "CGI/1.1",
41
- "HTTP_X_FORWARDED_FOR" => "65.88.180.234",
42
- "HTTP_ACCEPT" => "*/*",
43
- "SCRIPT_FILENAME" => "/home/kevinc/sites/typo/public/dispatch.fcgi",
44
- "REDIRECT_STATUS" => "200",
45
- "REQUEST_METHOD" => "GET"
46
- }
47
- # some Nokia phone browsers omit the space after the semicolon separator.
48
- # some developers have grown accustomed to using comma in cookie values.
49
- @alt_cookie_fmt_request_hash = {"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"}
50
- @cgi = CGI.new
51
- class << @cgi; attr_accessor :env_table end
52
- @cgi.env_table = @request_hash
53
- @request = ActionController::CgiRequest.new(@cgi)
54
- end
55
-
56
- def default_test; end
57
-
58
- private
59
-
60
- def set_content_data(data)
61
- @request.env['REQUEST_METHOD'] = 'POST'
62
- @request.env['CONTENT_LENGTH'] = data.length
63
- @request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
64
- @request.env['RAW_POST_DATA'] = data
65
- end
66
- end
67
-
68
- class CgiRequestTest < BaseCgiTest
69
- def test_proxy_request
70
- assert_equal 'glu.ttono.us', @request.host_with_port
71
- end
72
-
73
- def test_http_host
74
- @request_hash.delete "HTTP_X_FORWARDED_HOST"
75
- @request_hash['HTTP_HOST'] = "rubyonrails.org:8080"
76
- assert_equal "rubyonrails.org:8080", @request.host_with_port
77
-
78
- @request_hash['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org"
79
- assert_equal "www.secondhost.org", @request.host(true)
80
- end
81
-
82
- def test_http_host_with_default_port_overrides_server_port
83
- @request_hash.delete "HTTP_X_FORWARDED_HOST"
84
- @request_hash['HTTP_HOST'] = "rubyonrails.org"
85
- assert_equal "rubyonrails.org", @request.host_with_port
86
- end
87
-
88
- def test_host_with_port_defaults_to_server_name_if_no_host_headers
89
- @request_hash.delete "HTTP_X_FORWARDED_HOST"
90
- @request_hash.delete "HTTP_HOST"
91
- assert_equal "glu.ttono.us:8007", @request.host_with_port
92
- end
93
-
94
- def test_host_with_port_falls_back_to_server_addr_if_necessary
95
- @request_hash.delete "HTTP_X_FORWARDED_HOST"
96
- @request_hash.delete "HTTP_HOST"
97
- @request_hash.delete "SERVER_NAME"
98
- assert_equal "207.7.108.53:8007", @request.host_with_port
99
- end
100
-
101
- def test_host_with_port_if_http_standard_port_is_specified
102
- @request_hash['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:80"
103
- assert_equal "glu.ttono.us", @request.host_with_port
104
- end
105
-
106
- def test_host_with_port_if_https_standard_port_is_specified
107
- @request_hash['HTTP_X_FORWARDED_PROTO'] = "https"
108
- @request_hash['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:443"
109
- assert_equal "glu.ttono.us", @request.host_with_port
110
- end
111
-
112
- def test_host_if_ipv6_reference
113
- @request_hash.delete "HTTP_X_FORWARDED_HOST"
114
- @request_hash['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]"
115
- assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host
116
- end
117
-
118
- def test_host_if_ipv6_reference_with_port
119
- @request_hash.delete "HTTP_X_FORWARDED_HOST"
120
- @request_hash['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]:8008"
121
- assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host
122
- end
123
-
124
- def test_cgi_environment_variables
125
- assert_equal "Basic", @request.auth_type
126
- assert_equal 0, @request.content_length
127
- assert_equal nil, @request.content_type
128
- assert_equal "CGI/1.1", @request.gateway_interface
129
- assert_equal "*/*", @request.accept
130
- assert_equal "UTF-8", @request.accept_charset
131
- assert_equal "gzip, deflate", @request.accept_encoding
132
- assert_equal "en", @request.accept_language
133
- assert_equal "no-cache, max-age=0", @request.cache_control
134
- assert_equal "googlebot", @request.from
135
- assert_equal "glu.ttono.us", @request.host
136
- assert_equal "trans", @request.negotiate
137
- assert_equal "no-cache", @request.pragma
138
- assert_equal "http://www.google.com/search?q=glu.ttono.us", @request.referer
139
- assert_equal "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)", @request.user_agent
140
- assert_equal "/homepage/", @request.path_info
141
- assert_equal "/home/kevinc/sites/typo/public/homepage/", @request.path_translated
142
- assert_equal "", @request.query_string
143
- assert_equal "207.7.108.53", @request.remote_addr
144
- assert_equal "google.com", @request.remote_host
145
- assert_equal "kevin", @request.remote_ident
146
- assert_equal "kevin", @request.remote_user
147
- assert_equal :get, @request.request_method
148
- assert_equal "/dispatch.fcgi", @request.script_name
149
- assert_equal "glu.ttono.us:8007", @request.server_name
150
- assert_equal 8007, @request.server_port
151
- assert_equal "HTTP/1.1", @request.server_protocol
152
- assert_equal "lighttpd", @request.server_software
153
- end
154
-
155
- def test_cookie_syntax_resilience
156
- cookies = CGI::Cookie::parse(@request_hash["HTTP_COOKIE"]);
157
- assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], cookies["_session_id"], cookies.inspect
158
- assert_equal ["yes"], cookies["is_admin"], cookies.inspect
159
-
160
- alt_cookies = CGI::Cookie::parse(@alt_cookie_fmt_request_hash["HTTP_COOKIE"]);
161
- assert_equal ["c84ace847,96670c052c6ceb2451fb0f2"], alt_cookies["_session_id"], alt_cookies.inspect
162
- assert_equal ["yes"], alt_cookies["is_admin"], alt_cookies.inspect
163
- end
164
-
165
- def test_relative_url_root
166
- assert_deprecated("ActionController::Base.relative_url_root") do
167
- assert_equal ActionController::Base.relative_url_root, @request.relative_url_root
168
- end
169
- end
170
- end
171
-
172
- class CgiRequestParamsParsingTest < BaseCgiTest
173
- def test_doesnt_break_when_content_type_has_charset
174
- set_content_data 'flamenco=love'
175
-
176
- assert_equal({"flamenco"=> "love"}, @request.request_parameters)
177
- end
178
-
179
- def test_doesnt_interpret_request_uri_as_query_string_when_missing
180
- @request.env['REQUEST_URI'] = 'foo'
181
- assert_equal({}, @request.query_parameters)
182
- end
183
- end
184
-
185
- class CgiRequestContentTypeTest < BaseCgiTest
186
- def test_html_content_type_verification
187
- @request.env['CONTENT_TYPE'] = Mime::HTML.to_s
188
- assert @request.content_type.verify_request?
189
- end
190
-
191
- def test_xml_content_type_verification
192
- @request.env['CONTENT_TYPE'] = Mime::XML.to_s
193
- assert !@request.content_type.verify_request?
194
- end
195
- end
196
-
197
- class CgiRequestMethodTest < BaseCgiTest
198
- def test_get
199
- assert_equal :get, @request.request_method
200
- end
201
-
202
- def test_post
203
- @request.env['REQUEST_METHOD'] = 'POST'
204
- assert_equal :post, @request.request_method
205
- end
206
-
207
- def test_put
208
- set_content_data '_method=put'
209
-
210
- assert_equal :put, @request.request_method
211
- end
212
-
213
- def test_delete
214
- set_content_data '_method=delete'
215
-
216
- assert_equal :delete, @request.request_method
217
- end
218
- end
219
-
220
- class CgiRequestNeedsRewoundTest < BaseCgiTest
221
- def test_body_should_be_rewound
222
- data = 'foo'
223
- fake_cgi = Struct.new(:env_table, :query_string, :stdinput).new(@request_hash, '', StringIO.new(data))
224
- fake_cgi.env_table['CONTENT_LENGTH'] = data.length
225
- fake_cgi.env_table['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
226
-
227
- # Read the request body by parsing params.
228
- request = ActionController::CgiRequest.new(fake_cgi)
229
- request.request_parameters
230
-
231
- # Should have rewound the body.
232
- assert_equal 0, request.body.pos
233
- end
234
- end
235
-
236
- uses_mocha 'CGI Response' do
237
- class CgiResponseTest < BaseCgiTest
238
- def setup
239
- super
240
- @cgi.expects(:header).returns("HTTP/1.0 200 OK\nContent-Type: text/html\n")
241
- @response = ActionController::CgiResponse.new(@cgi)
242
- @output = StringIO.new('')
243
- end
244
-
245
- def test_simple_output
246
- @response.body = "Hello, World!"
247
-
248
- @response.out(@output)
249
- assert_equal "HTTP/1.0 200 OK\nContent-Type: text/html\nHello, World!", @output.string
250
- end
251
-
252
- def test_head_request
253
- @cgi.env_table['REQUEST_METHOD'] = 'HEAD'
254
- @response.body = "Hello, World!"
255
-
256
- @response.out(@output)
257
- assert_equal "HTTP/1.0 200 OK\nContent-Type: text/html\n", @output.string
258
- end
259
-
260
- def test_streaming_block
261
- @response.body = Proc.new do |response, output|
262
- 5.times { |n| output.write(n) }
263
- end
264
-
265
- @response.out(@output)
266
- assert_equal "HTTP/1.0 200 OK\nContent-Type: text/html\n01234", @output.string
267
- end
268
- end
269
- end
@@ -1,156 +0,0 @@
1
- require 'abstract_unit'
2
-
3
- class CallerController < ActionController::Base
4
- def calling_from_controller
5
- render_component(:controller => "callee", :action => "being_called")
6
- end
7
-
8
- def calling_from_controller_with_params
9
- render_component(:controller => "callee", :action => "being_called", :params => { "name" => "David" })
10
- end
11
-
12
- def calling_from_controller_with_different_status_code
13
- render_component(:controller => "callee", :action => "blowing_up")
14
- end
15
-
16
- def calling_from_template
17
- render :inline => "Ring, ring: <%= render_component(:controller => 'callee', :action => 'being_called') %>"
18
- end
19
-
20
- def internal_caller
21
- render :inline => "Are you there? <%= render_component(:action => 'internal_callee') %>"
22
- end
23
-
24
- def internal_callee
25
- render :text => "Yes, ma'am"
26
- end
27
-
28
- def set_flash
29
- render_component(:controller => "callee", :action => "set_flash")
30
- end
31
-
32
- def use_flash
33
- render_component(:controller => "callee", :action => "use_flash")
34
- end
35
-
36
- def calling_redirected
37
- render_component(:controller => "callee", :action => "redirected")
38
- end
39
-
40
- def calling_redirected_as_string
41
- render :inline => "<%= render_component(:controller => 'callee', :action => 'redirected') %>"
42
- end
43
-
44
- def rescue_action(e) raise end
45
- end
46
-
47
- class CalleeController < ActionController::Base
48
- def being_called
49
- render :text => "#{params[:name] || "Lady"} of the House, speaking"
50
- end
51
-
52
- def blowing_up
53
- render :text => "It's game over, man, just game over, man!", :status => 500
54
- end
55
-
56
- def set_flash
57
- flash[:notice] = 'My stoney baby'
58
- render :text => 'flash is set'
59
- end
60
-
61
- def use_flash
62
- render :text => flash[:notice] || 'no flash'
63
- end
64
-
65
- def redirected
66
- redirect_to :controller => "callee", :action => "being_called"
67
- end
68
-
69
- def rescue_action(e) raise end
70
- end
71
-
72
- class ComponentsTest < Test::Unit::TestCase
73
- def setup
74
- @controller = CallerController.new
75
- @request = ActionController::TestRequest.new
76
- @response = ActionController::TestResponse.new
77
- end
78
-
79
- def test_calling_from_controller
80
- assert_deprecated do
81
- get :calling_from_controller
82
- assert_equal "Lady of the House, speaking", @response.body
83
- end
84
- end
85
-
86
- def test_calling_from_controller_with_params
87
- assert_deprecated do
88
- get :calling_from_controller_with_params
89
- assert_equal "David of the House, speaking", @response.body
90
- end
91
- end
92
-
93
- def test_calling_from_controller_with_different_status_code
94
- assert_deprecated do
95
- get :calling_from_controller_with_different_status_code
96
- assert_equal 500, @response.response_code
97
- end
98
- end
99
-
100
- def test_calling_from_template
101
- assert_deprecated do
102
- get :calling_from_template
103
- assert_equal "Ring, ring: Lady of the House, speaking", @response.body
104
- end
105
- end
106
-
107
- def test_etag_is_set_for_parent_template_when_calling_from_template
108
- assert_deprecated do
109
- get :calling_from_template
110
- expected_etag = etag_for("Ring, ring: Lady of the House, speaking")
111
- assert_equal expected_etag, @response.headers['ETag']
112
- end
113
- end
114
-
115
- def test_internal_calling
116
- assert_deprecated do
117
- get :internal_caller
118
- assert_equal "Are you there? Yes, ma'am", @response.body
119
- end
120
- end
121
-
122
- def test_flash
123
- assert_deprecated do
124
- get :set_flash
125
- assert_equal 'My stoney baby', flash[:notice]
126
- get :use_flash
127
- assert_equal 'My stoney baby', @response.body
128
- get :use_flash
129
- assert_equal 'no flash', @response.body
130
- end
131
- end
132
-
133
- def test_component_redirect_redirects
134
- assert_deprecated do
135
- get :calling_redirected
136
- assert_redirected_to :controller=>"callee", :action => "being_called"
137
- end
138
- end
139
-
140
- def test_component_multiple_redirect_redirects
141
- test_component_redirect_redirects
142
- test_internal_calling
143
- end
144
-
145
- def test_component_as_string_redirect_renders_redirected_action
146
- assert_deprecated do
147
- get :calling_redirected_as_string
148
- assert_equal "Lady of the House, speaking", @response.body
149
- end
150
- end
151
-
152
- protected
153
- def etag_for(text)
154
- %("#{Digest::MD5.hexdigest(text)}")
155
- end
156
- end