eactionpack 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (338) hide show
  1. data/CHANGELOG +7 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +469 -0
  4. data/RUNNING_UNIT_TESTS +24 -0
  5. data/Rakefile +146 -0
  6. data/install.rb +30 -0
  7. data/lib/action_controller.rb +79 -0
  8. data/lib/action_controller/assertions.rb +69 -0
  9. data/lib/action_controller/assertions/dom_assertions.rb +39 -0
  10. data/lib/action_controller/assertions/model_assertions.rb +20 -0
  11. data/lib/action_controller/assertions/response_assertions.rb +172 -0
  12. data/lib/action_controller/assertions/routing_assertions.rb +146 -0
  13. data/lib/action_controller/assertions/selector_assertions.rb +491 -0
  14. data/lib/action_controller/assertions/tag_assertions.rb +130 -0
  15. data/lib/action_controller/base.rb +1288 -0
  16. data/lib/action_controller/benchmarking.rb +94 -0
  17. data/lib/action_controller/caching.rb +72 -0
  18. data/lib/action_controller/caching/actions.rb +144 -0
  19. data/lib/action_controller/caching/fragments.rb +138 -0
  20. data/lib/action_controller/caching/pages.rb +154 -0
  21. data/lib/action_controller/caching/sql_cache.rb +18 -0
  22. data/lib/action_controller/caching/sweeping.rb +97 -0
  23. data/lib/action_controller/cgi_ext.rb +16 -0
  24. data/lib/action_controller/cgi_ext/cookie.rb +110 -0
  25. data/lib/action_controller/cgi_ext/query_extension.rb +22 -0
  26. data/lib/action_controller/cgi_ext/session.rb +73 -0
  27. data/lib/action_controller/cgi_ext/stdinput.rb +24 -0
  28. data/lib/action_controller/cgi_process.rb +223 -0
  29. data/lib/action_controller/components.rb +166 -0
  30. data/lib/action_controller/cookies.rb +96 -0
  31. data/lib/action_controller/dispatcher.rb +162 -0
  32. data/lib/action_controller/filters.rb +642 -0
  33. data/lib/action_controller/flash.rb +172 -0
  34. data/lib/action_controller/headers.rb +31 -0
  35. data/lib/action_controller/helpers.rb +221 -0
  36. data/lib/action_controller/http_authentication.rb +124 -0
  37. data/lib/action_controller/integration.rb +634 -0
  38. data/lib/action_controller/layout.rb +309 -0
  39. data/lib/action_controller/mime_responds.rb +173 -0
  40. data/lib/action_controller/mime_type.rb +186 -0
  41. data/lib/action_controller/mime_types.rb +20 -0
  42. data/lib/action_controller/polymorphic_routes.rb +191 -0
  43. data/lib/action_controller/record_identifier.rb +102 -0
  44. data/lib/action_controller/request.rb +764 -0
  45. data/lib/action_controller/request_forgery_protection.rb +140 -0
  46. data/lib/action_controller/request_profiler.rb +169 -0
  47. data/lib/action_controller/rescue.rb +258 -0
  48. data/lib/action_controller/resources.rb +572 -0
  49. data/lib/action_controller/response.rb +76 -0
  50. data/lib/action_controller/routing.rb +387 -0
  51. data/lib/action_controller/routing/builder.rb +203 -0
  52. data/lib/action_controller/routing/optimisations.rb +120 -0
  53. data/lib/action_controller/routing/recognition_optimisation.rb +162 -0
  54. data/lib/action_controller/routing/route.rb +240 -0
  55. data/lib/action_controller/routing/route_set.rb +436 -0
  56. data/lib/action_controller/routing/routing_ext.rb +46 -0
  57. data/lib/action_controller/routing/segments.rb +283 -0
  58. data/lib/action_controller/session/active_record_store.rb +340 -0
  59. data/lib/action_controller/session/cookie_store.rb +166 -0
  60. data/lib/action_controller/session/drb_server.rb +32 -0
  61. data/lib/action_controller/session/drb_store.rb +35 -0
  62. data/lib/action_controller/session/mem_cache_store.rb +98 -0
  63. data/lib/action_controller/session_management.rb +158 -0
  64. data/lib/action_controller/status_codes.rb +88 -0
  65. data/lib/action_controller/streaming.rb +155 -0
  66. data/lib/action_controller/templates/rescues/_request_and_response.erb +24 -0
  67. data/lib/action_controller/templates/rescues/_trace.erb +26 -0
  68. data/lib/action_controller/templates/rescues/diagnostics.erb +11 -0
  69. data/lib/action_controller/templates/rescues/layout.erb +29 -0
  70. data/lib/action_controller/templates/rescues/missing_template.erb +2 -0
  71. data/lib/action_controller/templates/rescues/routing_error.erb +10 -0
  72. data/lib/action_controller/templates/rescues/template_error.erb +21 -0
  73. data/lib/action_controller/templates/rescues/unknown_action.erb +2 -0
  74. data/lib/action_controller/test_case.rb +83 -0
  75. data/lib/action_controller/test_process.rb +526 -0
  76. data/lib/action_controller/url_rewriter.rb +142 -0
  77. data/lib/action_controller/vendor/html-scanner/html/document.rb +68 -0
  78. data/lib/action_controller/vendor/html-scanner/html/node.rb +537 -0
  79. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +173 -0
  80. data/lib/action_controller/vendor/html-scanner/html/selector.rb +828 -0
  81. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +105 -0
  82. data/lib/action_controller/vendor/html-scanner/html/version.rb +11 -0
  83. data/lib/action_controller/verification.rb +130 -0
  84. data/lib/action_pack.rb +24 -0
  85. data/lib/action_pack/version.rb +9 -0
  86. data/lib/action_view.rb +44 -0
  87. data/lib/action_view/base.rb +335 -0
  88. data/lib/action_view/helpers/active_record_helper.rb +276 -0
  89. data/lib/action_view/helpers/asset_tag_helper.rb +599 -0
  90. data/lib/action_view/helpers/atom_feed_helper.rb +143 -0
  91. data/lib/action_view/helpers/benchmark_helper.rb +33 -0
  92. data/lib/action_view/helpers/cache_helper.rb +40 -0
  93. data/lib/action_view/helpers/capture_helper.rb +161 -0
  94. data/lib/action_view/helpers/date_helper.rb +711 -0
  95. data/lib/action_view/helpers/debug_helper.rb +31 -0
  96. data/lib/action_view/helpers/form_helper.rb +767 -0
  97. data/lib/action_view/helpers/form_options_helper.rb +458 -0
  98. data/lib/action_view/helpers/form_tag_helper.rb +458 -0
  99. data/lib/action_view/helpers/javascript_helper.rb +148 -0
  100. data/lib/action_view/helpers/number_helper.rb +186 -0
  101. data/lib/action_view/helpers/record_identification_helper.rb +20 -0
  102. data/lib/action_view/helpers/record_tag_helper.rb +59 -0
  103. data/lib/action_view/helpers/sanitize_helper.rb +229 -0
  104. data/lib/action_view/helpers/tag_helper.rb +134 -0
  105. data/lib/action_view/helpers/text_helper.rb +507 -0
  106. data/lib/action_view/helpers/url_helper.rb +573 -0
  107. data/lib/action_view/inline_template.rb +20 -0
  108. data/lib/action_view/partial_template.rb +70 -0
  109. data/lib/action_view/partials.rb +158 -0
  110. data/lib/action_view/template.rb +125 -0
  111. data/lib/action_view/template_error.rb +110 -0
  112. data/lib/action_view/template_finder.rb +176 -0
  113. data/lib/action_view/template_handler.rb +34 -0
  114. data/lib/action_view/template_handlers/builder.rb +27 -0
  115. data/lib/action_view/template_handlers/compilable.rb +128 -0
  116. data/lib/action_view/template_handlers/erb.rb +56 -0
  117. data/lib/action_view/test_case.rb +58 -0
  118. data/lib/actionpack.rb +1 -0
  119. data/test/abstract_unit.rb +36 -0
  120. data/test/active_record_unit.rb +105 -0
  121. data/test/activerecord/active_record_store_test.rb +141 -0
  122. data/test/activerecord/render_partial_with_record_identification_test.rb +191 -0
  123. data/test/adv_attr_test.rb +20 -0
  124. data/test/controller/action_pack_assertions_test.rb +543 -0
  125. data/test/controller/addresses_render_test.rb +43 -0
  126. data/test/controller/assert_select_test.rb +331 -0
  127. data/test/controller/base_test.rb +219 -0
  128. data/test/controller/benchmark_test.rb +32 -0
  129. data/test/controller/caching_test.rb +581 -0
  130. data/test/controller/capture_test.rb +89 -0
  131. data/test/controller/cgi_test.rb +116 -0
  132. data/test/controller/components_test.rb +140 -0
  133. data/test/controller/content_type_test.rb +139 -0
  134. data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
  135. data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
  136. data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
  137. data/test/controller/cookie_test.rb +146 -0
  138. data/test/controller/custom_handler_test.rb +45 -0
  139. data/test/controller/deprecation/deprecated_base_methods_test.rb +37 -0
  140. data/test/controller/dispatcher_test.rb +105 -0
  141. data/test/controller/fake_controllers.rb +33 -0
  142. data/test/controller/fake_models.rb +11 -0
  143. data/test/controller/filter_params_test.rb +49 -0
  144. data/test/controller/filters_test.rb +881 -0
  145. data/test/controller/flash_test.rb +146 -0
  146. data/test/controller/header_test.rb +14 -0
  147. data/test/controller/helper_test.rb +210 -0
  148. data/test/controller/html-scanner/cdata_node_test.rb +15 -0
  149. data/test/controller/html-scanner/document_test.rb +148 -0
  150. data/test/controller/html-scanner/node_test.rb +89 -0
  151. data/test/controller/html-scanner/sanitizer_test.rb +269 -0
  152. data/test/controller/html-scanner/tag_node_test.rb +238 -0
  153. data/test/controller/html-scanner/text_node_test.rb +50 -0
  154. data/test/controller/html-scanner/tokenizer_test.rb +131 -0
  155. data/test/controller/http_authentication_test.rb +54 -0
  156. data/test/controller/integration_test.rb +252 -0
  157. data/test/controller/integration_upload_test.rb +43 -0
  158. data/test/controller/layout_test.rb +255 -0
  159. data/test/controller/mime_responds_test.rb +514 -0
  160. data/test/controller/mime_type_test.rb +84 -0
  161. data/test/controller/new_render_test.rb +843 -0
  162. data/test/controller/polymorphic_routes_test.rb +174 -0
  163. data/test/controller/record_identifier_test.rb +139 -0
  164. data/test/controller/redirect_test.rb +289 -0
  165. data/test/controller/render_test.rb +484 -0
  166. data/test/controller/request_forgery_protection_test.rb +305 -0
  167. data/test/controller/request_test.rb +928 -0
  168. data/test/controller/rescue_test.rb +517 -0
  169. data/test/controller/resources_test.rb +873 -0
  170. data/test/controller/routing_test.rb +2464 -0
  171. data/test/controller/selector_test.rb +628 -0
  172. data/test/controller/send_file_test.rb +138 -0
  173. data/test/controller/session/cookie_store_test.rb +258 -0
  174. data/test/controller/session/mem_cache_store_test.rb +181 -0
  175. data/test/controller/session_fixation_test.rb +89 -0
  176. data/test/controller/session_management_test.rb +178 -0
  177. data/test/controller/test_test.rb +695 -0
  178. data/test/controller/url_rewriter_test.rb +310 -0
  179. data/test/controller/verification_test.rb +270 -0
  180. data/test/controller/view_paths_test.rb +140 -0
  181. data/test/controller/webservice_test.rb +229 -0
  182. data/test/fixtures/addresses/list.erb +1 -0
  183. data/test/fixtures/bad_customers/_bad_customer.html.erb +1 -0
  184. data/test/fixtures/companies.yml +24 -0
  185. data/test/fixtures/company.rb +10 -0
  186. data/test/fixtures/content_type/render_default_content_types_for_respond_to.rhtml +1 -0
  187. data/test/fixtures/content_type/render_default_for_js.js.erb +1 -0
  188. data/test/fixtures/content_type/render_default_for_rhtml.rhtml +1 -0
  189. data/test/fixtures/content_type/render_default_for_rxml.rxml +1 -0
  190. data/test/fixtures/customers/_customer.html.erb +1 -0
  191. data/test/fixtures/db_definitions/sqlite.sql +49 -0
  192. data/test/fixtures/developer.rb +9 -0
  193. data/test/fixtures/developers.yml +21 -0
  194. data/test/fixtures/developers_projects.yml +13 -0
  195. data/test/fixtures/fun/games/hello_world.erb +1 -0
  196. data/test/fixtures/functional_caching/_partial.erb +3 -0
  197. data/test/fixtures/functional_caching/fragment_cached.html.erb +2 -0
  198. data/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb +1 -0
  199. data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +1 -0
  200. data/test/fixtures/good_customers/_good_customer.html.erb +1 -0
  201. data/test/fixtures/helpers/abc_helper.rb +5 -0
  202. data/test/fixtures/helpers/fun/games_helper.rb +3 -0
  203. data/test/fixtures/helpers/fun/pdf_helper.rb +3 -0
  204. data/test/fixtures/layout_tests/alt/hello.rhtml +1 -0
  205. data/test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml +1 -0
  206. data/test/fixtures/layout_tests/layouts/item.rhtml +1 -0
  207. data/test/fixtures/layout_tests/layouts/layout_test.rhtml +1 -0
  208. data/test/fixtures/layout_tests/layouts/multiple_extensions.html.erb +1 -0
  209. data/test/fixtures/layout_tests/layouts/third_party_template_library.mab +1 -0
  210. data/test/fixtures/layout_tests/views/hello.rhtml +1 -0
  211. data/test/fixtures/layouts/block_with_layout.erb +3 -0
  212. data/test/fixtures/layouts/builder.builder +3 -0
  213. data/test/fixtures/layouts/partial_with_layout.erb +3 -0
  214. data/test/fixtures/layouts/standard.erb +1 -0
  215. data/test/fixtures/layouts/talk_from_action.erb +2 -0
  216. data/test/fixtures/layouts/yield.erb +2 -0
  217. data/test/fixtures/mascot.rb +3 -0
  218. data/test/fixtures/mascots.yml +4 -0
  219. data/test/fixtures/mascots/_mascot.html.erb +1 -0
  220. data/test/fixtures/multipart/binary_file +0 -0
  221. data/test/fixtures/multipart/boundary_problem_file +10 -0
  222. data/test/fixtures/multipart/bracketed_param +5 -0
  223. data/test/fixtures/multipart/large_text_file +10 -0
  224. data/test/fixtures/multipart/mixed_files +0 -0
  225. data/test/fixtures/multipart/mona_lisa.jpg +0 -0
  226. data/test/fixtures/multipart/single_parameter +5 -0
  227. data/test/fixtures/multipart/text_file +10 -0
  228. data/test/fixtures/override/test/hello_world.erb +1 -0
  229. data/test/fixtures/override2/layouts/test/sub.erb +1 -0
  230. data/test/fixtures/post_test/layouts/post.html.erb +1 -0
  231. data/test/fixtures/post_test/layouts/super_post.iphone.erb +1 -0
  232. data/test/fixtures/post_test/post/index.html.erb +1 -0
  233. data/test/fixtures/post_test/post/index.iphone.erb +1 -0
  234. data/test/fixtures/post_test/super_post/index.html.erb +1 -0
  235. data/test/fixtures/post_test/super_post/index.iphone.erb +1 -0
  236. data/test/fixtures/project.rb +3 -0
  237. data/test/fixtures/projects.yml +7 -0
  238. data/test/fixtures/public/404.html +1 -0
  239. data/test/fixtures/public/500.html +1 -0
  240. data/test/fixtures/public/images/rails.png +0 -0
  241. data/test/fixtures/public/javascripts/application.js +1 -0
  242. data/test/fixtures/public/javascripts/bank.js +1 -0
  243. data/test/fixtures/public/javascripts/robber.js +1 -0
  244. data/test/fixtures/public/javascripts/version.1.0.js +1 -0
  245. data/test/fixtures/public/stylesheets/bank.css +1 -0
  246. data/test/fixtures/public/stylesheets/robber.css +1 -0
  247. data/test/fixtures/public/stylesheets/version.1.0.css +1 -0
  248. data/test/fixtures/replies.yml +15 -0
  249. data/test/fixtures/reply.rb +7 -0
  250. data/test/fixtures/respond_to/all_types_with_layout.html.erb +1 -0
  251. data/test/fixtures/respond_to/custom_constant_handling_without_block.mobile.erb +1 -0
  252. data/test/fixtures/respond_to/iphone_with_html_response_type.html.erb +1 -0
  253. data/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb +1 -0
  254. data/test/fixtures/respond_to/layouts/missing.html.erb +1 -0
  255. data/test/fixtures/respond_to/layouts/standard.html.erb +1 -0
  256. data/test/fixtures/respond_to/layouts/standard.iphone.erb +1 -0
  257. data/test/fixtures/respond_to/using_defaults.html.erb +1 -0
  258. data/test/fixtures/respond_to/using_defaults.js.rjs +1 -0
  259. data/test/fixtures/respond_to/using_defaults.xml.builder +1 -0
  260. data/test/fixtures/respond_to/using_defaults_with_type_list.html.erb +1 -0
  261. data/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs +1 -0
  262. data/test/fixtures/respond_to/using_defaults_with_type_list.xml.builder +1 -0
  263. data/test/fixtures/scope/test/modgreet.erb +1 -0
  264. data/test/fixtures/shared.html.erb +1 -0
  265. data/test/fixtures/symlink_parent/symlinked_layout.erb +5 -0
  266. data/test/fixtures/test/_customer.erb +1 -0
  267. data/test/fixtures/test/_customer_counter.erb +1 -0
  268. data/test/fixtures/test/_customer_greeting.erb +1 -0
  269. data/test/fixtures/test/_form.erb +1 -0
  270. data/test/fixtures/test/_hash_greeting.erb +1 -0
  271. data/test/fixtures/test/_hash_object.erb +2 -0
  272. data/test/fixtures/test/_hello.builder +1 -0
  273. data/test/fixtures/test/_labelling_form.erb +1 -0
  274. data/test/fixtures/test/_layout_for_partial.html.erb +3 -0
  275. data/test/fixtures/test/_partial.erb +1 -0
  276. data/test/fixtures/test/_partial.html.erb +1 -0
  277. data/test/fixtures/test/_partial.js.erb +1 -0
  278. data/test/fixtures/test/_partial_for_use_in_layout.html.erb +1 -0
  279. data/test/fixtures/test/_partial_only.erb +1 -0
  280. data/test/fixtures/test/_person.erb +2 -0
  281. data/test/fixtures/test/_raise.html.erb +1 -0
  282. data/test/fixtures/test/action_talk_to_layout.erb +2 -0
  283. data/test/fixtures/test/block_content_for.erb +2 -0
  284. data/test/fixtures/test/calling_partial_with_layout.html.erb +1 -0
  285. data/test/fixtures/test/capturing.erb +4 -0
  286. data/test/fixtures/test/content_for.erb +2 -0
  287. data/test/fixtures/test/content_for_concatenated.erb +3 -0
  288. data/test/fixtures/test/content_for_with_parameter.erb +2 -0
  289. data/test/fixtures/test/delete_with_js.rjs +2 -0
  290. data/test/fixtures/test/dot.directory/render_file_with_ivar.erb +1 -0
  291. data/test/fixtures/test/enum_rjs_test.rjs +6 -0
  292. data/test/fixtures/test/erb_content_for.erb +2 -0
  293. data/test/fixtures/test/formatted_html_erb.html.erb +1 -0
  294. data/test/fixtures/test/formatted_xml_erb.builder +1 -0
  295. data/test/fixtures/test/formatted_xml_erb.html.erb +1 -0
  296. data/test/fixtures/test/formatted_xml_erb.xml.erb +1 -0
  297. data/test/fixtures/test/greeting.erb +1 -0
  298. data/test/fixtures/test/greeting.js.rjs +1 -0
  299. data/test/fixtures/test/hello.builder +4 -0
  300. data/test/fixtures/test/hello_world.erb +1 -0
  301. data/test/fixtures/test/hello_world_container.builder +3 -0
  302. data/test/fixtures/test/hello_world_from_rxml.builder +4 -0
  303. data/test/fixtures/test/hello_world_with_layout_false.erb +1 -0
  304. data/test/fixtures/test/hello_xml_world.builder +11 -0
  305. data/test/fixtures/test/list.erb +1 -0
  306. data/test/fixtures/test/non_erb_block_content_for.builder +4 -0
  307. data/test/fixtures/test/potential_conflicts.erb +4 -0
  308. data/test/fixtures/test/render_file_from_template.html.erb +1 -0
  309. data/test/fixtures/test/render_file_with_ivar.erb +1 -0
  310. data/test/fixtures/test/render_file_with_locals.erb +1 -0
  311. data/test/fixtures/test/render_to_string_test.erb +1 -0
  312. data/test/fixtures/test/update_element_with_capture.erb +9 -0
  313. data/test/fixtures/test/using_layout_around_block.html.erb +1 -0
  314. data/test/fixtures/topic.rb +3 -0
  315. data/test/fixtures/topics.yml +22 -0
  316. data/test/fixtures/topics/_topic.html.erb +1 -0
  317. data/test/template/active_record_helper_test.rb +268 -0
  318. data/test/template/asset_tag_helper_test.rb +514 -0
  319. data/test/template/atom_feed_helper_test.rb +179 -0
  320. data/test/template/benchmark_helper_test.rb +60 -0
  321. data/test/template/date_helper_test.rb +1791 -0
  322. data/test/template/deprecated_erb_variable_test.rb +9 -0
  323. data/test/template/erb_util_test.rb +24 -0
  324. data/test/template/form_helper_test.rb +885 -0
  325. data/test/template/form_options_helper_test.rb +1333 -0
  326. data/test/template/form_tag_helper_test.rb +272 -0
  327. data/test/template/javascript_helper_test.rb +73 -0
  328. data/test/template/number_helper_test.rb +97 -0
  329. data/test/template/record_tag_helper_test.rb +54 -0
  330. data/test/template/sanitize_helper_test.rb +48 -0
  331. data/test/template/tag_helper_test.rb +77 -0
  332. data/test/template/template_finder_test.rb +73 -0
  333. data/test/template/template_object_test.rb +95 -0
  334. data/test/template/test_test.rb +56 -0
  335. data/test/template/text_helper_test.rb +367 -0
  336. data/test/template/url_helper_test.rb +544 -0
  337. data/test/testing_sandbox.rb +15 -0
  338. metadata +469 -0
@@ -0,0 +1,89 @@
1
+ require 'abstract_unit'
2
+
3
+
4
+ class SessionFixationTest < Test::Unit::TestCase
5
+ class MockCGI < CGI #:nodoc:
6
+ attr_accessor :stdoutput, :env_table
7
+
8
+ def initialize(env, data = '')
9
+ self.env_table = env
10
+ self.stdoutput = StringIO.new
11
+ super(nil, StringIO.new(data))
12
+ end
13
+ end
14
+
15
+ class TestController < ActionController::Base
16
+ session :session_key => '_myapp_session_id', :secret => CGI::Session.generate_unique_id, :except => :default_session_key
17
+ session :cookie_only => false, :only => :allow_session_fixation
18
+
19
+ def default_session_key
20
+ render :text => "default_session_key"
21
+ end
22
+
23
+ def custom_session_key
24
+ render :text => "custom_session_key: #{params[:id]}"
25
+ end
26
+
27
+ def allow_session_fixation
28
+ render :text => "allow_session_fixation"
29
+ end
30
+
31
+ def rescue_action(e) raise end
32
+ end
33
+
34
+ def setup
35
+ @controller = TestController.new
36
+ end
37
+
38
+ def test_should_be_able_to_make_a_successful_request
39
+ cgi = mock_cgi_for_request_to(:custom_session_key, :id => 1)
40
+
41
+ assert_nothing_raised do
42
+ @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi))
43
+ end
44
+ assert_equal 'custom_session_key: 1', @controller.response.body
45
+ assert_not_nil @controller.session
46
+ end
47
+
48
+ def test_should_catch_session_fixation_attempt
49
+ cgi = mock_cgi_for_request_to(:custom_session_key, :_myapp_session_id => 42)
50
+
51
+ assert_raises ActionController::CgiRequest::SessionFixationAttempt do
52
+ @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi))
53
+ end
54
+ assert_nil @controller.session
55
+ end
56
+
57
+ def test_should_not_catch_session_fixation_attempt_when_cookie_only_setting_is_disabled
58
+ cgi = mock_cgi_for_request_to(:allow_session_fixation, :_myapp_session_id => 42)
59
+
60
+ assert_nothing_raised do
61
+ @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi))
62
+ end
63
+ assert ! @controller.response.body.blank?
64
+ assert_not_nil @controller.session
65
+ end
66
+
67
+ def test_should_catch_session_fixation_attempt_with_default_session_key
68
+ ActionController::Base.session_store = :p_store # using the default session_key is not possible with cookie store
69
+ cgi = mock_cgi_for_request_to(:default_session_key, :_session_id => 42)
70
+
71
+ assert_raises ActionController::CgiRequest::SessionFixationAttempt do
72
+ @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi))
73
+ end
74
+ assert @controller.response.body.blank?
75
+ assert_nil @controller.session
76
+ end
77
+
78
+ private
79
+
80
+ def mock_cgi_for_request_to(action, params = {})
81
+ MockCGI.new({
82
+ "REQUEST_METHOD" => "GET",
83
+ "QUERY_STRING" => "action=#{action}&#{params.to_query}",
84
+ "REQUEST_URI" => "/",
85
+ "SERVER_PORT" => "80",
86
+ "HTTP_HOST" => "testdomain.com" }, '')
87
+ end
88
+
89
+ end
@@ -0,0 +1,178 @@
1
+ require 'abstract_unit'
2
+
3
+ class SessionManagementTest < Test::Unit::TestCase
4
+ class SessionOffController < ActionController::Base
5
+ session :off
6
+
7
+ def show
8
+ render :text => "done"
9
+ end
10
+
11
+ def tell
12
+ render :text => "done"
13
+ end
14
+ end
15
+
16
+ class SessionOffOnController < ActionController::Base
17
+ session :off
18
+ session :on, :only => :tell
19
+
20
+ def show
21
+ render :text => "done"
22
+ end
23
+
24
+ def tell
25
+ render :text => "done"
26
+ end
27
+ end
28
+
29
+ class TestController < ActionController::Base
30
+ session :off, :only => :show
31
+ session :session_secure => true, :except => :show
32
+ session :off, :only => :conditional,
33
+ :if => Proc.new { |r| r.parameters[:ws] }
34
+
35
+ def show
36
+ render :text => "done"
37
+ end
38
+
39
+ def tell
40
+ render :text => "done"
41
+ end
42
+
43
+ def conditional
44
+ render :text => ">>>#{params[:ws]}<<<"
45
+ end
46
+ end
47
+
48
+ class SpecializedController < SessionOffController
49
+ session :disabled => false, :only => :something
50
+
51
+ def something
52
+ render :text => "done"
53
+ end
54
+
55
+ def another
56
+ render :text => "done"
57
+ end
58
+ end
59
+
60
+ class AssociationCachingTestController < ActionController::Base
61
+ class ObjectWithAssociationCache
62
+ def initialize
63
+ @cached_associations = false
64
+ end
65
+
66
+ def fetch_associations
67
+ @cached_associations = true
68
+ end
69
+
70
+ def clear_association_cache
71
+ @cached_associations = false
72
+ end
73
+
74
+ def has_cached_associations?
75
+ @cached_associations
76
+ end
77
+ end
78
+
79
+ def show
80
+ session[:object] = ObjectWithAssociationCache.new
81
+ session[:object].fetch_associations
82
+ if session[:object].has_cached_associations?
83
+ render :text => "has cached associations"
84
+ else
85
+ render :text => "does not have cached associations"
86
+ end
87
+ end
88
+
89
+ def tell
90
+ if session[:object]
91
+ if session[:object].has_cached_associations?
92
+ render :text => "has cached associations"
93
+ else
94
+ render :text => "does not have cached associations"
95
+ end
96
+ else
97
+ render :text => "there is no object"
98
+ end
99
+ end
100
+ end
101
+
102
+
103
+ def setup
104
+ @request, @response = ActionController::TestRequest.new,
105
+ ActionController::TestResponse.new
106
+ end
107
+
108
+ def test_session_off_globally
109
+ @controller = SessionOffController.new
110
+ get :show
111
+ assert_equal false, @request.session_options
112
+ get :tell
113
+ assert_equal false, @request.session_options
114
+ end
115
+
116
+ def test_session_off_then_on_globally
117
+ @controller = SessionOffOnController.new
118
+ get :show
119
+ assert_equal false, @request.session_options
120
+ get :tell
121
+ assert_instance_of Hash, @request.session_options
122
+ assert_equal false, @request.session_options[:disabled]
123
+ end
124
+
125
+ def test_session_off_conditionally
126
+ @controller = TestController.new
127
+ get :show
128
+ assert_equal false, @request.session_options
129
+ get :tell
130
+ assert_instance_of Hash, @request.session_options
131
+ assert @request.session_options[:session_secure]
132
+ end
133
+
134
+ def test_controller_specialization_overrides_settings
135
+ @controller = SpecializedController.new
136
+ get :something
137
+ assert_instance_of Hash, @request.session_options
138
+ get :another
139
+ assert_equal false, @request.session_options
140
+ end
141
+
142
+ def test_session_off_with_if
143
+ @controller = TestController.new
144
+ get :conditional
145
+ assert_instance_of Hash, @request.session_options
146
+ get :conditional, :ws => "ws"
147
+ assert_equal false, @request.session_options
148
+ end
149
+
150
+ def test_session_store_setting
151
+ ActionController::Base.session_store = :drb_store
152
+ assert_equal CGI::Session::DRbStore, ActionController::Base.session_store
153
+
154
+ if Object.const_defined?(:ActiveRecord)
155
+ ActionController::Base.session_store = :active_record_store
156
+ assert_equal CGI::Session::ActiveRecordStore, ActionController::Base.session_store
157
+ end
158
+ end
159
+
160
+ def test_process_cleanup_with_session_management_support
161
+ @controller = AssociationCachingTestController.new
162
+ get :show
163
+ assert_equal "has cached associations", @response.body
164
+ get :tell
165
+ assert_equal "does not have cached associations", @response.body
166
+ end
167
+
168
+ def test_session_is_enabled
169
+ @controller = TestController.new
170
+ get :show
171
+ assert_nothing_raised do
172
+ assert_equal false, @controller.session_enabled?
173
+ end
174
+
175
+ get :tell
176
+ assert @controller.session_enabled?
177
+ end
178
+ end
@@ -0,0 +1,695 @@
1
+ require 'abstract_unit'
2
+ require 'controller/fake_controllers'
3
+
4
+ class TestTest < Test::Unit::TestCase
5
+ class TestController < ActionController::Base
6
+ def no_op
7
+ render :text => 'dummy'
8
+ end
9
+
10
+ def set_flash
11
+ flash["test"] = ">#{flash["test"]}<"
12
+ render :text => 'ignore me'
13
+ end
14
+
15
+ def set_flash_now
16
+ flash.now["test_now"] = ">#{flash["test_now"]}<"
17
+ render :text => 'ignore me'
18
+ end
19
+
20
+ def set_session
21
+ session['string'] = 'A wonder'
22
+ session[:symbol] = 'it works'
23
+ render :text => 'Success'
24
+ end
25
+
26
+ def render_raw_post
27
+ raise Test::Unit::AssertionFailedError, "#raw_post is blank" if request.raw_post.blank?
28
+ render :text => request.raw_post
29
+ end
30
+
31
+ def render_body
32
+ render :text => request.body.read
33
+ end
34
+
35
+ def test_params
36
+ render :text => params.inspect
37
+ end
38
+
39
+ def test_uri
40
+ render :text => request.request_uri
41
+ end
42
+
43
+ def test_query_string
44
+ render :text => request.query_string
45
+ end
46
+
47
+ def test_html_output
48
+ render :text => <<HTML
49
+ <html>
50
+ <body>
51
+ <a href="/"><img src="/images/button.png" /></a>
52
+ <div id="foo">
53
+ <ul>
54
+ <li class="item">hello</li>
55
+ <li class="item">goodbye</li>
56
+ </ul>
57
+ </div>
58
+ <div id="bar">
59
+ <form action="/somewhere">
60
+ Name: <input type="text" name="person[name]" id="person_name" />
61
+ </form>
62
+ </div>
63
+ </body>
64
+ </html>
65
+ HTML
66
+ end
67
+
68
+ def test_xml_output
69
+ response.content_type = "application/xml"
70
+ render :text => <<XML
71
+ <?xml version="1.0" encoding="UTF-8"?>
72
+ <root>
73
+ <area>area is an empty tag in HTML, raising an error if not in xml mode</area>
74
+ </root>
75
+ XML
76
+ end
77
+
78
+ def test_only_one_param
79
+ render :text => (params[:left] && params[:right]) ? "EEP, Both here!" : "OK"
80
+ end
81
+
82
+ def test_remote_addr
83
+ render :text => (request.remote_addr || "not specified")
84
+ end
85
+
86
+ def test_file_upload
87
+ render :text => params[:file].size
88
+ end
89
+
90
+ def test_send_file
91
+ send_file(File.expand_path(__FILE__))
92
+ end
93
+
94
+ def redirect_to_same_controller
95
+ redirect_to :controller => 'test', :action => 'test_uri', :id => 5
96
+ end
97
+
98
+ def redirect_to_different_controller
99
+ redirect_to :controller => 'fail', :id => 5
100
+ end
101
+
102
+ def create
103
+ head :created, :location => 'created resource'
104
+ end
105
+
106
+ private
107
+ def rescue_action(e)
108
+ raise e
109
+ end
110
+
111
+ def generate_url(opts)
112
+ url_for(opts.merge(:action => "test_uri"))
113
+ end
114
+ end
115
+
116
+ def setup
117
+ @controller = TestController.new
118
+ @request = ActionController::TestRequest.new
119
+ @response = ActionController::TestResponse.new
120
+ ActionController::Routing::Routes.reload
121
+ ActionController::Routing.use_controllers! %w(content admin/user test_test/test)
122
+ end
123
+
124
+ def teardown
125
+ ActionController::Routing::Routes.reload
126
+ end
127
+
128
+ def test_raw_post_handling
129
+ params = {:page => {:name => 'page name'}, 'some key' => 123}
130
+ post :render_raw_post, params.dup
131
+
132
+ assert_equal params.to_query, @response.body
133
+ end
134
+
135
+ def test_body_stream
136
+ params = { :page => { :name => 'page name' }, 'some key' => 123 }
137
+
138
+ post :render_body, params.dup
139
+
140
+ assert_equal params.to_query, @response.body
141
+ end
142
+
143
+ def test_process_without_flash
144
+ process :set_flash
145
+ assert_equal '><', flash['test']
146
+ end
147
+
148
+ def test_process_with_flash
149
+ process :set_flash, nil, nil, { "test" => "value" }
150
+ assert_equal '>value<', flash['test']
151
+ end
152
+
153
+ def test_process_with_flash_now
154
+ process :set_flash_now, nil, nil, { "test_now" => "value_now" }
155
+ assert_equal '>value_now<', flash['test_now']
156
+ end
157
+
158
+ def test_process_with_session
159
+ process :set_session
160
+ assert_equal 'A wonder', session['string'], "A value stored in the session should be available by string key"
161
+ assert_equal 'A wonder', session[:string], "Test session hash should allow indifferent access"
162
+ assert_equal 'it works', session['symbol'], "Test session hash should allow indifferent access"
163
+ assert_equal 'it works', session[:symbol], "Test session hash should allow indifferent access"
164
+ end
165
+
166
+ def test_process_with_session_arg
167
+ process :no_op, nil, { 'string' => 'value1', :symbol => 'value2' }
168
+ assert_equal 'value1', session['string']
169
+ assert_equal 'value1', session[:string]
170
+ assert_equal 'value2', session['symbol']
171
+ assert_equal 'value2', session[:symbol]
172
+ end
173
+
174
+ def test_process_with_request_uri_with_no_params
175
+ process :test_uri
176
+ assert_equal "/test_test/test/test_uri", @response.body
177
+ end
178
+
179
+ def test_process_with_request_uri_with_params
180
+ process :test_uri, :id => 7
181
+ assert_equal "/test_test/test/test_uri/7", @response.body
182
+ end
183
+
184
+ def test_process_with_request_uri_with_params_with_explicit_uri
185
+ @request.set_REQUEST_URI "/explicit/uri"
186
+ process :test_uri, :id => 7
187
+ assert_equal "/explicit/uri", @response.body
188
+ end
189
+
190
+ def test_process_with_query_string
191
+ process :test_query_string, :q => 'test'
192
+ assert_equal "q=test", @response.body
193
+ end
194
+
195
+ def test_process_with_query_string_with_explicit_uri
196
+ @request.set_REQUEST_URI "/explicit/uri?q=test?extra=question"
197
+ process :test_query_string
198
+ assert_equal "q=test?extra=question", @response.body
199
+ end
200
+
201
+ def test_multiple_calls
202
+ process :test_only_one_param, :left => true
203
+ assert_equal "OK", @response.body
204
+ process :test_only_one_param, :right => true
205
+ assert_equal "OK", @response.body
206
+ end
207
+
208
+ def test_assert_tag_tag
209
+ process :test_html_output
210
+
211
+ # there is a 'form' tag
212
+ assert_tag :tag => 'form'
213
+ # there is not an 'hr' tag
214
+ assert_no_tag :tag => 'hr'
215
+ end
216
+
217
+ def test_assert_tag_attributes
218
+ process :test_html_output
219
+
220
+ # there is a tag with an 'id' of 'bar'
221
+ assert_tag :attributes => { :id => "bar" }
222
+ # there is no tag with a 'name' of 'baz'
223
+ assert_no_tag :attributes => { :name => "baz" }
224
+ end
225
+
226
+ def test_assert_tag_parent
227
+ process :test_html_output
228
+
229
+ # there is a tag with a parent 'form' tag
230
+ assert_tag :parent => { :tag => "form" }
231
+ # there is no tag with a parent of 'input'
232
+ assert_no_tag :parent => { :tag => "input" }
233
+ end
234
+
235
+ def test_assert_tag_child
236
+ process :test_html_output
237
+
238
+ # there is a tag with a child 'input' tag
239
+ assert_tag :child => { :tag => "input" }
240
+ # there is no tag with a child 'strong' tag
241
+ assert_no_tag :child => { :tag => "strong" }
242
+ end
243
+
244
+ def test_assert_tag_ancestor
245
+ process :test_html_output
246
+
247
+ # there is a 'li' tag with an ancestor having an id of 'foo'
248
+ assert_tag :ancestor => { :attributes => { :id => "foo" } }, :tag => "li"
249
+ # there is no tag of any kind with an ancestor having an href matching 'foo'
250
+ assert_no_tag :ancestor => { :attributes => { :href => /foo/ } }
251
+ end
252
+
253
+ def test_assert_tag_descendant
254
+ process :test_html_output
255
+
256
+ # there is a tag with a descendant 'li' tag
257
+ assert_tag :descendant => { :tag => "li" }
258
+ # there is no tag with a descendant 'html' tag
259
+ assert_no_tag :descendant => { :tag => "html" }
260
+ end
261
+
262
+ def test_assert_tag_sibling
263
+ process :test_html_output
264
+
265
+ # there is a tag with a sibling of class 'item'
266
+ assert_tag :sibling => { :attributes => { :class => "item" } }
267
+ # there is no tag with a sibling 'ul' tag
268
+ assert_no_tag :sibling => { :tag => "ul" }
269
+ end
270
+
271
+ def test_assert_tag_after
272
+ process :test_html_output
273
+
274
+ # there is a tag following a sibling 'div' tag
275
+ assert_tag :after => { :tag => "div" }
276
+ # there is no tag following a sibling tag with id 'bar'
277
+ assert_no_tag :after => { :attributes => { :id => "bar" } }
278
+ end
279
+
280
+ def test_assert_tag_before
281
+ process :test_html_output
282
+
283
+ # there is a tag preceding a tag with id 'bar'
284
+ assert_tag :before => { :attributes => { :id => "bar" } }
285
+ # there is no tag preceding a 'form' tag
286
+ assert_no_tag :before => { :tag => "form" }
287
+ end
288
+
289
+ def test_assert_tag_children_count
290
+ process :test_html_output
291
+
292
+ # there is a tag with 2 children
293
+ assert_tag :children => { :count => 2 }
294
+ # in particular, there is a <ul> tag with two children (a nameless pair of <li>s)
295
+ assert_tag :tag => 'ul', :children => { :count => 2 }
296
+ # there is no tag with 4 children
297
+ assert_no_tag :children => { :count => 4 }
298
+ end
299
+
300
+ def test_assert_tag_children_less_than
301
+ process :test_html_output
302
+
303
+ # there is a tag with less than 5 children
304
+ assert_tag :children => { :less_than => 5 }
305
+ # there is no 'ul' tag with less than 2 children
306
+ assert_no_tag :children => { :less_than => 2 }, :tag => "ul"
307
+ end
308
+
309
+ def test_assert_tag_children_greater_than
310
+ process :test_html_output
311
+
312
+ # there is a 'body' tag with more than 1 children
313
+ assert_tag :children => { :greater_than => 1 }, :tag => "body"
314
+ # there is no tag with more than 10 children
315
+ assert_no_tag :children => { :greater_than => 10 }
316
+ end
317
+
318
+ def test_assert_tag_children_only
319
+ process :test_html_output
320
+
321
+ # there is a tag containing only one child with an id of 'foo'
322
+ assert_tag :children => { :count => 1,
323
+ :only => { :attributes => { :id => "foo" } } }
324
+ # there is no tag containing only one 'li' child
325
+ assert_no_tag :children => { :count => 1, :only => { :tag => "li" } }
326
+ end
327
+
328
+ def test_assert_tag_content
329
+ process :test_html_output
330
+
331
+ # the output contains the string "Name"
332
+ assert_tag :content => /Name/
333
+ # the output does not contain the string "test"
334
+ assert_no_tag :content => /test/
335
+ end
336
+
337
+ def test_assert_tag_multiple
338
+ process :test_html_output
339
+
340
+ # there is a 'div', id='bar', with an immediate child whose 'action'
341
+ # attribute matches the regexp /somewhere/.
342
+ assert_tag :tag => "div", :attributes => { :id => "bar" },
343
+ :child => { :attributes => { :action => /somewhere/ } }
344
+
345
+ # there is no 'div', id='foo', with a 'ul' child with more than
346
+ # 2 "li" children.
347
+ assert_no_tag :tag => "div", :attributes => { :id => "foo" },
348
+ :child => {
349
+ :tag => "ul",
350
+ :children => { :greater_than => 2,
351
+ :only => { :tag => "li" } } }
352
+ end
353
+
354
+ def test_assert_tag_children_without_content
355
+ process :test_html_output
356
+
357
+ # there is a form tag with an 'input' child which is a self closing tag
358
+ assert_tag :tag => "form",
359
+ :children => { :count => 1,
360
+ :only => { :tag => "input" } }
361
+
362
+ # the body tag has an 'a' child which in turn has an 'img' child
363
+ assert_tag :tag => "body",
364
+ :children => { :count => 1,
365
+ :only => { :tag => "a",
366
+ :children => { :count => 1,
367
+ :only => { :tag => "img" } } } }
368
+ end
369
+
370
+ def test_should_not_impose_childless_html_tags_in_xml
371
+ process :test_xml_output
372
+
373
+ begin
374
+ $stderr = StringIO.new
375
+ assert_select 'area' #This will cause a warning if content is processed as HTML
376
+ $stderr.rewind && err = $stderr.read
377
+ ensure
378
+ $stderr = STDERR
379
+ end
380
+
381
+ assert err.empty?
382
+ end
383
+
384
+ def test_assert_tag_attribute_matching
385
+ @response.body = '<input type="text" name="my_name">'
386
+ assert_tag :tag => 'input',
387
+ :attributes => { :name => /my/, :type => 'text' }
388
+ assert_no_tag :tag => 'input',
389
+ :attributes => { :name => 'my', :type => 'text' }
390
+ assert_no_tag :tag => 'input',
391
+ :attributes => { :name => /^my$/, :type => 'text' }
392
+ end
393
+
394
+ def test_assert_tag_content_matching
395
+ @response.body = "<p>hello world</p>"
396
+ assert_tag :tag => "p", :content => "hello world"
397
+ assert_tag :tag => "p", :content => /hello/
398
+ assert_no_tag :tag => "p", :content => "hello"
399
+ end
400
+
401
+ def test_assert_generates
402
+ assert_generates 'controller/action/5', :controller => 'controller', :action => 'action', :id => '5'
403
+ assert_generates 'controller/action/7', {:id => "7"}, {:controller => "controller", :action => "action"}
404
+ assert_generates 'controller/action/5', {:controller => "controller", :action => "action", :id => "5", :name => "bob"}, {}, {:name => "bob"}
405
+ assert_generates 'controller/action/7', {:id => "7", :name => "bob"}, {:controller => "controller", :action => "action"}, {:name => "bob"}
406
+ assert_generates 'controller/action/7', {:id => "7"}, {:controller => "controller", :action => "action", :name => "bob"}, {}
407
+ end
408
+
409
+ def test_assert_routing
410
+ assert_routing 'content', :controller => 'content', :action => 'index'
411
+ end
412
+
413
+ def test_assert_routing_with_method
414
+ with_routing do |set|
415
+ set.draw { |map| map.resources(:content) }
416
+ assert_routing({ :method => 'post', :path => 'content' }, { :controller => 'content', :action => 'create' })
417
+ end
418
+ end
419
+
420
+ def test_assert_routing_in_module
421
+ assert_routing 'admin/user', :controller => 'admin/user', :action => 'index'
422
+ end
423
+
424
+ def test_params_passing
425
+ get :test_params, :page => {:name => "Page name", :month => '4', :year => '2004', :day => '6'}
426
+ parsed_params = eval(@response.body)
427
+ assert_equal(
428
+ {'controller' => 'test_test/test', 'action' => 'test_params',
429
+ 'page' => {'name' => "Page name", 'month' => '4', 'year' => '2004', 'day' => '6'}},
430
+ parsed_params
431
+ )
432
+ end
433
+
434
+ def test_id_converted_to_string
435
+ get :test_params, :id => 20, :foo => Object.new
436
+ assert_kind_of String, @request.path_parameters['id']
437
+ end
438
+
439
+ def test_array_path_parameter_handled_properly
440
+ with_routing do |set|
441
+ set.draw do |map|
442
+ map.connect 'file/*path', :controller => 'test_test/test', :action => 'test_params'
443
+ map.connect ':controller/:action/:id'
444
+ end
445
+
446
+ get :test_params, :path => ['hello', 'world']
447
+ assert_equal ['hello', 'world'], @request.path_parameters['path']
448
+ assert_equal 'hello/world', @request.path_parameters['path'].to_s
449
+ end
450
+ end
451
+
452
+ def test_assert_realistic_path_parameters
453
+ get :test_params, :id => 20, :foo => Object.new
454
+
455
+ # All elements of path_parameters should use string keys
456
+ @request.path_parameters.keys.each do |key|
457
+ assert_kind_of String, key
458
+ end
459
+ end
460
+
461
+ def test_with_routing_places_routes_back
462
+ assert ActionController::Routing::Routes
463
+ routes_id = ActionController::Routing::Routes.object_id
464
+
465
+ begin
466
+ with_routing { raise 'fail' }
467
+ fail 'Should not be here.'
468
+ rescue RuntimeError
469
+ end
470
+
471
+ assert ActionController::Routing::Routes
472
+ assert_equal routes_id, ActionController::Routing::Routes.object_id
473
+ end
474
+
475
+ def test_remote_addr
476
+ get :test_remote_addr
477
+ assert_equal "0.0.0.0", @response.body
478
+
479
+ @request.remote_addr = "192.0.0.1"
480
+ get :test_remote_addr
481
+ assert_equal "192.0.0.1", @response.body
482
+ end
483
+
484
+ def test_header_properly_reset_after_remote_http_request
485
+ xhr :get, :test_params
486
+ assert_nil @request.env['HTTP_X_REQUESTED_WITH']
487
+ end
488
+
489
+ def test_header_properly_reset_after_get_request
490
+ get :test_params
491
+ @request.recycle!
492
+ assert_nil @request.instance_variable_get("@request_method")
493
+ end
494
+
495
+ %w(controller response request).each do |variable|
496
+ %w(get post put delete head process).each do |method|
497
+ define_method("test_#{variable}_missing_for_#{method}_raises_error") do
498
+ remove_instance_variable "@#{variable}"
499
+ begin
500
+ send(method, :test_remote_addr)
501
+ assert false, "expected RuntimeError, got nothing"
502
+ rescue RuntimeError => error
503
+ assert true
504
+ assert_match %r{@#{variable} is nil}, error.message
505
+ rescue => error
506
+ assert false, "expected RuntimeError, got #{error.class}"
507
+ end
508
+ end
509
+ end
510
+ end
511
+
512
+ FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart'
513
+
514
+ if RUBY_VERSION < '1.9'
515
+ READ_BINARY = 'rb'
516
+ READ_PLAIN = 'r'
517
+ else
518
+ READ_BINARY = 'rb:binary'
519
+ READ_PLAIN = 'r:binary'
520
+ end
521
+
522
+ def test_test_uploaded_file
523
+ filename = 'mona_lisa.jpg'
524
+ path = "#{FILES_DIR}/#{filename}"
525
+ content_type = 'image/png'
526
+ expected = File.read(path)
527
+ expected.force_encoding(Encoding::BINARY) if expected.respond_to?(:force_encoding)
528
+
529
+ file = ActionController::TestUploadedFile.new(path, content_type)
530
+ assert_equal filename, file.original_filename
531
+ assert_equal content_type, file.content_type
532
+ assert_equal file.path, file.local_path
533
+ assert_equal expected, file.read
534
+
535
+ new_content_type = "new content_type"
536
+ file.content_type = new_content_type
537
+ assert_equal new_content_type, file.content_type
538
+
539
+ end
540
+
541
+ def test_test_uploaded_file_with_binary
542
+ filename = 'mona_lisa.jpg'
543
+ path = "#{FILES_DIR}/#{filename}"
544
+ content_type = 'image/png'
545
+
546
+ binary_uploaded_file = ActionController::TestUploadedFile.new(path, content_type, :binary)
547
+ assert_equal File.open(path, READ_BINARY).read, binary_uploaded_file.read
548
+
549
+ plain_uploaded_file = ActionController::TestUploadedFile.new(path, content_type)
550
+ assert_equal File.open(path, READ_PLAIN).read, plain_uploaded_file.read
551
+ end
552
+
553
+ def test_fixture_file_upload_with_binary
554
+ filename = 'mona_lisa.jpg'
555
+ path = "#{FILES_DIR}/#{filename}"
556
+ content_type = 'image/jpg'
557
+
558
+ binary_file_upload = fixture_file_upload(path, content_type, :binary)
559
+ assert_equal File.open(path, READ_BINARY).read, binary_file_upload.read
560
+
561
+ plain_file_upload = fixture_file_upload(path, content_type)
562
+ assert_equal File.open(path, READ_PLAIN).read, plain_file_upload.read
563
+ end
564
+
565
+ def test_fixture_file_upload
566
+ post :test_file_upload, :file => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg")
567
+ assert_equal '159528', @response.body
568
+ end
569
+
570
+ def test_test_uploaded_file_exception_when_file_doesnt_exist
571
+ assert_raise(RuntimeError) { ActionController::TestUploadedFile.new('non_existent_file') }
572
+ end
573
+
574
+ def test_assert_follow_redirect_to_same_controller
575
+ with_foo_routing do |set|
576
+ get :redirect_to_same_controller
577
+ assert_response :redirect
578
+ assert_redirected_to :controller => 'test_test/test', :action => 'test_uri', :id => 5
579
+ assert_deprecated 'follow_redirect' do
580
+ assert_nothing_raised { follow_redirect }
581
+ end
582
+ end
583
+ end
584
+
585
+ def test_assert_follow_redirect_to_different_controller
586
+ with_foo_routing do |set|
587
+ get :redirect_to_different_controller
588
+ assert_response :redirect
589
+ assert_redirected_to :controller => 'fail', :id => 5
590
+ assert_raise(RuntimeError) do
591
+ assert_deprecated { follow_redirect }
592
+ end
593
+ end
594
+ end
595
+
596
+ def test_redirect_url_only_cares_about_location_header
597
+ get :create
598
+ assert_response :created
599
+
600
+ # Redirect url doesn't care that it wasn't a :redirect response.
601
+ assert_equal 'created resource', @response.redirect_url
602
+ assert_equal @response.redirect_url, redirect_to_url
603
+
604
+ # Must be a :redirect response.
605
+ assert_raise(Test::Unit::AssertionFailedError) do
606
+ assert_redirected_to 'created resource'
607
+ end
608
+ end
609
+
610
+ def test_binary_content_works_with_send_file
611
+ get :test_send_file
612
+ assert_nothing_raised(NoMethodError) { @response.binary_content }
613
+ end
614
+
615
+ protected
616
+ def with_foo_routing
617
+ with_routing do |set|
618
+ set.draw do |map|
619
+ map.generate_url 'foo', :controller => 'test'
620
+ map.connect ':controller/:action/:id'
621
+ end
622
+ yield set
623
+ end
624
+ end
625
+ end
626
+
627
+
628
+ class CleanBacktraceTest < Test::Unit::TestCase
629
+ def test_should_reraise_the_same_object
630
+ exception = Test::Unit::AssertionFailedError.new('message')
631
+ clean_backtrace { raise exception }
632
+ rescue => caught
633
+ assert_equal exception.object_id, caught.object_id
634
+ assert_equal exception.message, caught.message
635
+ end
636
+
637
+ def test_should_clean_assertion_lines_from_backtrace
638
+ path = File.expand_path("#{File.dirname(__FILE__)}/../../lib/action_controller")
639
+ exception = Test::Unit::AssertionFailedError.new('message')
640
+ exception.set_backtrace ["#{path}/abc", "#{path}/assertions/def"]
641
+ clean_backtrace { raise exception }
642
+ rescue => caught
643
+ assert_equal ["#{path}/abc"], caught.backtrace
644
+ end
645
+
646
+ def test_should_only_clean_assertion_failure_errors
647
+ clean_backtrace do
648
+ raise "can't touch this", [File.expand_path("#{File.dirname(__FILE__)}/../../lib/action_controller/assertions/abc")]
649
+ end
650
+ rescue => caught
651
+ assert !caught.backtrace.empty?
652
+ end
653
+ end
654
+
655
+ class InferringClassNameTest < Test::Unit::TestCase
656
+ def test_determine_controller_class
657
+ assert_equal ContentController, determine_class("ContentControllerTest")
658
+ end
659
+
660
+ def test_determine_controller_class_with_nonsense_name
661
+ assert_raises ActionController::NonInferrableControllerError do
662
+ determine_class("HelloGoodBye")
663
+ end
664
+ end
665
+
666
+ def test_determine_controller_class_with_sensible_name_where_no_controller_exists
667
+ assert_raises ActionController::NonInferrableControllerError do
668
+ determine_class("NoControllerWithThisNameTest")
669
+ end
670
+ end
671
+
672
+ private
673
+ def determine_class(name)
674
+ ActionController::TestCase.determine_default_controller_class(name)
675
+ end
676
+ end
677
+
678
+ class CrazyNameTest < ActionController::TestCase
679
+ tests ContentController
680
+
681
+ def test_controller_class_can_be_set_manually_not_just_inferred
682
+ assert_equal ContentController, self.class.controller_class
683
+ end
684
+ end
685
+
686
+ class NamedRoutesControllerTest < ActionController::TestCase
687
+ tests ContentController
688
+
689
+ def test_should_be_able_to_use_named_routes_before_a_request_is_done
690
+ with_routing do |set|
691
+ set.draw { |map| map.resources :contents }
692
+ assert_equal 'http://test.host/contents/new', new_content_url
693
+ end
694
+ end
695
+ end