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,84 @@
1
+ require 'abstract_unit'
2
+
3
+ class MimeTypeTest < Test::Unit::TestCase
4
+ Mime::Type.register "image/png", :png
5
+ Mime::Type.register "application/pdf", :pdf
6
+
7
+ def test_parse_single
8
+ Mime::LOOKUP.keys.each do |mime_type|
9
+ assert_equal [Mime::Type.lookup(mime_type)], Mime::Type.parse(mime_type)
10
+ end
11
+ end
12
+
13
+ def test_parse_without_q
14
+ accept = "text/xml,application/xhtml+xml,text/yaml,application/xml,text/html,image/png,text/plain,application/pdf,*/*"
15
+ expect = [Mime::HTML, Mime::XML, Mime::YAML, Mime::PNG, Mime::TEXT, Mime::PDF, Mime::ALL]
16
+ assert_equal expect, Mime::Type.parse(accept)
17
+ end
18
+
19
+ def test_parse_with_q
20
+ accept = "text/xml,application/xhtml+xml,text/yaml; q=0.3,application/xml,text/html; q=0.8,image/png,text/plain; q=0.5,application/pdf,*/*; q=0.2"
21
+ expect = [Mime::HTML, Mime::XML, Mime::PNG, Mime::PDF, Mime::TEXT, Mime::YAML, Mime::ALL]
22
+ assert_equal expect, Mime::Type.parse(accept)
23
+ end
24
+
25
+ # Accept header send with user HTTP_USER_AGENT: Sunrise/0.42j (Windows XP)
26
+ def test_parse_crappy_broken_acceptlines
27
+ accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/*,,*/*;q=0.5"
28
+ expect = [Mime::HTML, Mime::XML, "image/*", Mime::TEXT, Mime::ALL]
29
+ assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
30
+ end
31
+
32
+ # Accept header send with user HTTP_USER_AGENT: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
33
+ def test_parse_crappy_broken_acceptlines2
34
+ accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, , pronto/1.00.00, sslvpn/1.00.00.00, */*"
35
+ expect = ['image/gif', 'image/x-xbitmap', 'image/jpeg','image/pjpeg', 'application/x-shockwave-flash', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/msword', 'pronto/1.00.00', 'sslvpn/1.00.00.00', Mime::ALL ]
36
+ assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
37
+ end
38
+
39
+ def test_custom_type
40
+ Mime::Type.register("image/gif", :gif)
41
+ assert_nothing_raised do
42
+ Mime::GIF
43
+ assert_equal Mime::GIF, Mime::SET.last
44
+ end
45
+ ensure
46
+ Mime.module_eval { remove_const :GIF if const_defined?(:GIF) }
47
+ end
48
+
49
+ def test_type_should_be_equal_to_symbol
50
+ assert_equal Mime::HTML, 'application/xhtml+xml'
51
+ assert_equal Mime::HTML, :html
52
+ end
53
+
54
+ def test_type_convenience_methods
55
+ # Don't test Mime::ALL, since it Mime::ALL#html? == true
56
+ types = Mime::SET.to_a.map(&:to_sym).uniq - [:all]
57
+
58
+ # Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
59
+ types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
60
+
61
+ types.each do |type|
62
+ mime = Mime.const_get(type.to_s.upcase)
63
+ assert mime.send("#{type}?"), "#{mime.inspect} is not #{type}?"
64
+ (types - [type]).each { |other_type| assert !mime.send("#{other_type}?"), "#{mime.inspect} is #{other_type}?" }
65
+ end
66
+ end
67
+
68
+ def test_mime_all_is_html
69
+ assert Mime::ALL.all?, "Mime::ALL is not all?"
70
+ assert Mime::ALL.html?, "Mime::ALL is not html?"
71
+ end
72
+
73
+ def test_verifiable_mime_types
74
+ unverified_types = Mime::Type.unverifiable_types
75
+ all_types = Mime::SET.to_a.map(&:to_sym)
76
+ all_types.uniq!
77
+ # Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
78
+ all_types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
79
+
80
+ unverified, verified = all_types.partition { |type| Mime::Type.unverifiable_types.include? type }
81
+ assert verified.all? { |type| Mime.const_get(type.to_s.upcase).verify_request? }, "Not all Mime Types are verified: #{verified.inspect}"
82
+ assert unverified.all? { |type| !Mime.const_get(type.to_s.upcase).verify_request? }, "Some Mime Types are verified: #{unverified.inspect}"
83
+ end
84
+ end
@@ -0,0 +1,843 @@
1
+ require 'abstract_unit'
2
+ require 'controller/fake_models'
3
+
4
+ class CustomersController < ActionController::Base
5
+ end
6
+
7
+ module Fun
8
+ class GamesController < ActionController::Base
9
+ def hello_world
10
+ end
11
+ end
12
+ end
13
+
14
+ class LabellingFormBuilder < ActionView::Helpers::FormBuilder
15
+ end
16
+
17
+ class NewRenderTestController < ActionController::Base
18
+ layout :determine_layout
19
+
20
+ def self.controller_name; "test"; end
21
+ def self.controller_path; "test"; end
22
+
23
+ def hello_world
24
+ end
25
+
26
+ def render_hello_world
27
+ render :template => "test/hello_world"
28
+ end
29
+
30
+ def render_hello_world_from_variable
31
+ @person = "david"
32
+ render :text => "hello #{@person}"
33
+ end
34
+
35
+ def render_action_hello_world
36
+ render :action => "hello_world"
37
+ end
38
+
39
+ def render_action_hello_world_as_symbol
40
+ render :action => :hello_world
41
+ end
42
+
43
+ def render_text_hello_world
44
+ render :text => "hello world"
45
+ end
46
+
47
+ def render_text_hello_world_with_layout
48
+ @variable_for_layout = ", I'm here!"
49
+ render :text => "hello world", :layout => true
50
+ end
51
+
52
+ def hello_world_with_layout_false
53
+ render :layout => false
54
+ end
55
+
56
+ def render_custom_code
57
+ render :text => "hello world", :status => "404 Moved"
58
+ end
59
+
60
+ def render_file_with_instance_variables
61
+ @secret = 'in the sauce'
62
+ path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')
63
+ render :file => path
64
+ end
65
+
66
+ def render_file_from_template
67
+ @secret = 'in the sauce'
68
+ @path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb'))
69
+ end
70
+
71
+ def render_file_with_locals
72
+ path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.erb')
73
+ render :file => path, :locals => {:secret => 'in the sauce'}
74
+ end
75
+
76
+ def render_file_not_using_full_path
77
+ @secret = 'in the sauce'
78
+ render :file => 'test/render_file_with_ivar', :use_full_path => true
79
+ end
80
+
81
+ def render_file_not_using_full_path_with_dot_in_path
82
+ @secret = 'in the sauce'
83
+ render :file => 'test/dot.directory/render_file_with_ivar', :use_full_path => true
84
+ end
85
+
86
+ def render_xml_hello
87
+ @name = "David"
88
+ render :template => "test/hello"
89
+ end
90
+
91
+ def greeting
92
+ # let's just rely on the template
93
+ end
94
+
95
+ def layout_test
96
+ render :action => "hello_world"
97
+ end
98
+
99
+ def layout_test_with_different_layout
100
+ render :action => "hello_world", :layout => "standard"
101
+ end
102
+
103
+ def rendering_without_layout
104
+ render :action => "hello_world", :layout => false
105
+ end
106
+
107
+ def layout_overriding_layout
108
+ render :action => "hello_world", :layout => "standard"
109
+ end
110
+
111
+ def rendering_nothing_on_layout
112
+ render :nothing => true
113
+ end
114
+
115
+ def builder_layout_test
116
+ render :action => "hello"
117
+ end
118
+
119
+ def partials_list
120
+ @test_unchanged = 'hello'
121
+ @customers = [ Customer.new("david"), Customer.new("mary") ]
122
+ render :action => "list"
123
+ end
124
+
125
+ def partial_only
126
+ render :partial => true
127
+ end
128
+
129
+ def partial_only_with_layout
130
+ render :partial => "partial_only", :layout => true
131
+ end
132
+
133
+ def partial_with_locals
134
+ render :partial => "customer", :locals => { :customer => Customer.new("david") }
135
+ end
136
+
137
+ def partial_with_form_builder
138
+ render :partial => ActionView::Helpers::FormBuilder.new(:post, nil, @template, {}, Proc.new {})
139
+ end
140
+
141
+ def partial_with_form_builder_subclass
142
+ render :partial => LabellingFormBuilder.new(:post, nil, @template, {}, Proc.new {})
143
+ end
144
+
145
+ def partial_collection
146
+ render :partial => "customer", :collection => [ Customer.new("david"), Customer.new("mary") ]
147
+ end
148
+
149
+ def partial_collection_with_spacer
150
+ render :partial => "customer", :spacer_template => "partial_only", :collection => [ Customer.new("david"), Customer.new("mary") ]
151
+ end
152
+
153
+ def partial_collection_with_counter
154
+ render :partial => "customer_counter", :collection => [ Customer.new("david"), Customer.new("mary") ]
155
+ end
156
+
157
+ def partial_collection_with_locals
158
+ render :partial => "customer_greeting", :collection => [ Customer.new("david"), Customer.new("mary") ], :locals => { :greeting => "Bonjour" }
159
+ end
160
+
161
+ def partial_collection_shorthand_with_locals
162
+ render :partial => [ Customer.new("david"), Customer.new("mary") ], :locals => { :greeting => "Bonjour" }
163
+ end
164
+
165
+ def partial_collection_shorthand_with_different_types_of_records
166
+ render :partial => [
167
+ BadCustomer.new("mark"),
168
+ GoodCustomer.new("craig"),
169
+ BadCustomer.new("john"),
170
+ GoodCustomer.new("zach"),
171
+ GoodCustomer.new("brandon"),
172
+ BadCustomer.new("dan") ],
173
+ :locals => { :greeting => "Bonjour" }
174
+ end
175
+
176
+ def partial_collection_shorthand_with_different_types_of_records_with_counter
177
+ partial_collection_shorthand_with_different_types_of_records
178
+ end
179
+
180
+ def empty_partial_collection
181
+ render :partial => "customer", :collection => []
182
+ end
183
+
184
+ def partial_with_hash_object
185
+ render :partial => "hash_object", :object => {:first_name => "Sam"}
186
+ end
187
+
188
+ def partial_hash_collection
189
+ render :partial => "hash_object", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ]
190
+ end
191
+
192
+ def partial_hash_collection_with_locals
193
+ render :partial => "hash_greeting", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ], :locals => { :greeting => "Hola" }
194
+ end
195
+
196
+ def partial_with_implicit_local_assignment
197
+ @customer = Customer.new("Marcel")
198
+ render :partial => "customer"
199
+ end
200
+
201
+ def missing_partial
202
+ render :partial => 'thisFileIsntHere'
203
+ end
204
+
205
+ def hello_in_a_string
206
+ @customers = [ Customer.new("david"), Customer.new("mary") ]
207
+ render :text => "How's there? " << render_to_string(:template => "test/list")
208
+ end
209
+
210
+ def render_to_string_with_assigns
211
+ @before = "i'm before the render"
212
+ render_to_string :text => "foo"
213
+ @after = "i'm after the render"
214
+ render :action => "test/hello_world"
215
+ end
216
+
217
+ def render_to_string_with_partial
218
+ @partial_only = render_to_string :partial => "partial_only"
219
+ @partial_with_locals = render_to_string :partial => "customer", :locals => { :customer => Customer.new("david") }
220
+ render :action => "test/hello_world"
221
+ end
222
+
223
+ def render_to_string_with_exception
224
+ render_to_string :file => "exception that will not be caught - this will certainly not work", :use_full_path => true
225
+ end
226
+
227
+ def render_to_string_with_caught_exception
228
+ @before = "i'm before the render"
229
+ begin
230
+ render_to_string :file => "exception that will be caught- hope my future instance vars still work!", :use_full_path => true
231
+ rescue
232
+ end
233
+ @after = "i'm after the render"
234
+ render :action => "test/hello_world"
235
+ end
236
+
237
+ def accessing_params_in_template
238
+ render :inline => "Hello: <%= params[:name] %>"
239
+ end
240
+
241
+ def accessing_request_in_template
242
+ render :inline => "Hello: <%= request.host %>"
243
+ end
244
+
245
+ def accessing_logger_in_template
246
+ render :inline => "<%= logger.class %>"
247
+ end
248
+
249
+ def accessing_action_name_in_template
250
+ render :inline => "<%= action_name %>"
251
+ end
252
+
253
+ def accessing_params_in_template_with_layout
254
+ render :layout => nil, :inline => "Hello: <%= params[:name] %>"
255
+ end
256
+
257
+ def render_with_explicit_template
258
+ render :template => "test/hello_world"
259
+ end
260
+
261
+ def render_with_explicit_template_with_locals
262
+ render :template => "test/render_file_with_locals", :locals => { :secret => 'area51' }
263
+ end
264
+
265
+ def double_render
266
+ render :text => "hello"
267
+ render :text => "world"
268
+ end
269
+
270
+ def double_redirect
271
+ redirect_to :action => "double_render"
272
+ redirect_to :action => "double_render"
273
+ end
274
+
275
+ def render_and_redirect
276
+ render :text => "hello"
277
+ redirect_to :action => "double_render"
278
+ end
279
+
280
+ def render_to_string_and_render
281
+ @stuff = render_to_string :text => "here is some cached stuff"
282
+ render :text => "Hi web users! #{@stuff}"
283
+ end
284
+
285
+ def rendering_with_conflicting_local_vars
286
+ @name = "David"
287
+ def @template.name() nil end
288
+ render :action => "potential_conflicts"
289
+ end
290
+
291
+ def hello_world_from_rxml_using_action
292
+ render :action => "hello_world_from_rxml.builder"
293
+ end
294
+
295
+ def hello_world_from_rxml_using_template
296
+ render :template => "test/hello_world_from_rxml.builder"
297
+ end
298
+
299
+ def head_with_location_header
300
+ head :location => "/foo"
301
+ end
302
+
303
+ def head_with_symbolic_status
304
+ head :status => params[:status].intern
305
+ end
306
+
307
+ def head_with_integer_status
308
+ head :status => params[:status].to_i
309
+ end
310
+
311
+ def head_with_string_status
312
+ head :status => params[:status]
313
+ end
314
+
315
+ def head_with_custom_header
316
+ head :x_custom_header => "something"
317
+ end
318
+
319
+ def head_with_status_code_first
320
+ head :forbidden, :x_custom_header => "something"
321
+ end
322
+
323
+ def render_with_location
324
+ render :xml => "<hello/>", :location => "http://example.com", :status => 201
325
+ end
326
+
327
+ def render_with_object_location
328
+ customer = Customer.new("Some guy", 1)
329
+ render :xml => "<customer/>", :location => customer_url(customer), :status => :created
330
+ end
331
+
332
+ def render_with_to_xml
333
+ to_xmlable = Class.new do
334
+ def to_xml
335
+ "<i-am-xml/>"
336
+ end
337
+ end.new
338
+
339
+ render :xml => to_xmlable
340
+ end
341
+
342
+ def action_talk_to_layout
343
+ # Action template sets variable that's picked up by layout
344
+ end
345
+
346
+ def render_text_with_assigns
347
+ @hello = "world"
348
+ render :text => "foo"
349
+ end
350
+
351
+ def yield_content_for
352
+ render :action => "content_for", :layout => "yield"
353
+ end
354
+
355
+ def render_content_type_from_body
356
+ response.content_type = Mime::RSS
357
+ render :text => "hello world!"
358
+ end
359
+
360
+ def render_call_to_partial_with_layout
361
+ render :action => "calling_partial_with_layout"
362
+ end
363
+
364
+ def render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout
365
+ render :action => "calling_partial_with_layout"
366
+ end
367
+
368
+ def render_using_layout_around_block
369
+ render :action => "using_layout_around_block"
370
+ end
371
+
372
+ def render_using_layout_around_block_in_main_layout_and_within_content_for_layout
373
+ render :action => "using_layout_around_block"
374
+ end
375
+
376
+ def rescue_action(e) raise end
377
+
378
+ private
379
+ def determine_layout
380
+ case action_name
381
+ when "hello_world", "layout_test", "rendering_without_layout",
382
+ "rendering_nothing_on_layout", "render_text_hello_world",
383
+ "render_text_hello_world_with_layout",
384
+ "hello_world_with_layout_false",
385
+ "partial_only", "partial_only_with_layout",
386
+ "accessing_params_in_template",
387
+ "accessing_params_in_template_with_layout",
388
+ "render_with_explicit_template",
389
+ "render_js_with_explicit_template",
390
+ "render_js_with_explicit_action_template",
391
+ "delete_with_js", "update_page", "update_page_with_instance_variables"
392
+
393
+ "layouts/standard"
394
+ when "builder_layout_test"
395
+ "layouts/builder"
396
+ when "action_talk_to_layout", "layout_overriding_layout"
397
+ "layouts/talk_from_action"
398
+ when "render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout"
399
+ "layouts/partial_with_layout"
400
+ when "render_using_layout_around_block_in_main_layout_and_within_content_for_layout"
401
+ "layouts/block_with_layout"
402
+ end
403
+ end
404
+ end
405
+
406
+ NewRenderTestController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
407
+ Fun::GamesController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
408
+
409
+ class NewRenderTest < Test::Unit::TestCase
410
+ def setup
411
+ @controller = NewRenderTestController.new
412
+
413
+ # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
414
+ # a more accurate simulation of what happens in "real life".
415
+ @controller.logger = Logger.new(nil)
416
+
417
+ @request = ActionController::TestRequest.new
418
+ @response = ActionController::TestResponse.new
419
+
420
+ @request.host = "www.nextangle.com"
421
+ end
422
+
423
+ def test_simple_show
424
+ get :hello_world
425
+ assert_response :success
426
+ assert_template "test/hello_world"
427
+ assert_equal "<html>Hello world!</html>", @response.body
428
+ end
429
+
430
+ def test_do_with_render
431
+ get :render_hello_world
432
+ assert_template "test/hello_world"
433
+ end
434
+
435
+ def test_do_with_render_from_variable
436
+ get :render_hello_world_from_variable
437
+ assert_equal "hello david", @response.body
438
+ end
439
+
440
+ def test_do_with_render_action
441
+ get :render_action_hello_world
442
+ assert_template "test/hello_world"
443
+ end
444
+
445
+ def test_do_with_render_action_as_symbol
446
+ get :render_action_hello_world_as_symbol
447
+ assert_template "test/hello_world"
448
+ end
449
+
450
+ def test_do_with_render_text
451
+ get :render_text_hello_world
452
+ assert_equal "hello world", @response.body
453
+ end
454
+
455
+ def test_do_with_render_text_and_layout
456
+ get :render_text_hello_world_with_layout
457
+ assert_equal "<html>hello world, I'm here!</html>", @response.body
458
+ end
459
+
460
+ def test_do_with_render_action_and_layout_false
461
+ get :hello_world_with_layout_false
462
+ assert_equal 'Hello world!', @response.body
463
+ end
464
+
465
+ def test_do_with_render_custom_code
466
+ get :render_custom_code
467
+ assert_response :missing
468
+ end
469
+
470
+ def test_render_file_with_instance_variables
471
+ get :render_file_with_instance_variables
472
+ assert_equal "The secret is in the sauce\n", @response.body
473
+ end
474
+
475
+ def test_render_file_not_using_full_path
476
+ get :render_file_not_using_full_path
477
+ assert_equal "The secret is in the sauce\n", @response.body
478
+ end
479
+
480
+ def test_render_file_not_using_full_path_with_dot_in_path
481
+ get :render_file_not_using_full_path_with_dot_in_path
482
+ assert_equal "The secret is in the sauce\n", @response.body
483
+ end
484
+
485
+ def test_render_file_with_locals
486
+ get :render_file_with_locals
487
+ assert_equal "The secret is in the sauce\n", @response.body
488
+ end
489
+
490
+ def test_render_file_from_template
491
+ get :render_file_from_template
492
+ assert_equal "The secret is in the sauce\n", @response.body
493
+ end
494
+
495
+ def test_attempt_to_access_object_method
496
+ assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
497
+ end
498
+
499
+ def test_private_methods
500
+ assert_raises(ActionController::UnknownAction, "No action responded to [determine_layout]") { get :determine_layout }
501
+ end
502
+
503
+ def test_access_to_request_in_view
504
+ get :accessing_request_in_template
505
+ assert_equal "Hello: www.nextangle.com", @response.body
506
+ end
507
+
508
+ def test_access_to_logger_in_view
509
+ get :accessing_logger_in_template
510
+ assert_equal "Logger", @response.body
511
+ end
512
+
513
+ def test_access_to_action_name_in_view
514
+ get :accessing_action_name_in_template
515
+ assert_equal "accessing_action_name_in_template", @response.body
516
+ end
517
+
518
+ def test_render_xml
519
+ get :render_xml_hello
520
+ assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
521
+ end
522
+
523
+ def test_render_xml_with_default
524
+ get :greeting
525
+ assert_equal "<p>This is grand!</p>\n", @response.body
526
+ end
527
+
528
+ def test_layout_rendering
529
+ get :layout_test
530
+ assert_equal "<html>Hello world!</html>", @response.body
531
+ end
532
+
533
+ def test_layout_test_with_different_layout
534
+ get :layout_test_with_different_layout
535
+ assert_equal "<html>Hello world!</html>", @response.body
536
+ end
537
+
538
+ def test_rendering_without_layout
539
+ get :rendering_without_layout
540
+ assert_equal "Hello world!", @response.body
541
+ end
542
+
543
+ def test_layout_overriding_layout
544
+ get :layout_overriding_layout
545
+ assert_no_match %r{<title>}, @response.body
546
+ end
547
+
548
+ def test_rendering_nothing_on_layout
549
+ get :rendering_nothing_on_layout
550
+ assert_equal " ", @response.body
551
+ end
552
+
553
+ def test_render_xml_with_layouts
554
+ get :builder_layout_test
555
+ assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body
556
+ end
557
+
558
+ def test_partial_only
559
+ get :partial_only
560
+ assert_equal "only partial", @response.body
561
+ end
562
+
563
+ def test_partial_only_with_layout
564
+ get :partial_only_with_layout
565
+ assert_equal "<html>only partial</html>", @response.body
566
+ end
567
+
568
+ def test_render_to_string
569
+ assert_not_deprecated { get :hello_in_a_string }
570
+ assert_equal "How's there? goodbyeHello: davidHello: marygoodbye\n", @response.body
571
+ end
572
+
573
+ def test_render_to_string_doesnt_break_assigns
574
+ get :render_to_string_with_assigns
575
+ assert_equal "i'm before the render", assigns(:before)
576
+ assert_equal "i'm after the render", assigns(:after)
577
+ end
578
+
579
+ def test_render_to_string_partial
580
+ get :render_to_string_with_partial
581
+ assert_equal "only partial", assigns(:partial_only)
582
+ assert_equal "Hello: david", assigns(:partial_with_locals)
583
+ end
584
+
585
+ def test_bad_render_to_string_still_throws_exception
586
+ assert_raises(ActionView::MissingTemplate) { get :render_to_string_with_exception }
587
+ end
588
+
589
+ def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns
590
+ assert_nothing_raised { get :render_to_string_with_caught_exception }
591
+ assert_equal "i'm before the render", assigns(:before)
592
+ assert_equal "i'm after the render", assigns(:after)
593
+ end
594
+
595
+ def test_nested_rendering
596
+ get :hello_world
597
+ assert_equal "Living in a nested world", Fun::GamesController.process(@request, @response).body
598
+ end
599
+
600
+ def test_accessing_params_in_template
601
+ get :accessing_params_in_template, :name => "David"
602
+ assert_equal "Hello: David", @response.body
603
+ end
604
+
605
+ def test_accessing_params_in_template_with_layout
606
+ get :accessing_params_in_template_with_layout, :name => "David"
607
+ assert_equal "<html>Hello: David</html>", @response.body
608
+ end
609
+
610
+ def test_render_with_explicit_template
611
+ get :render_with_explicit_template
612
+ assert_response :success
613
+ end
614
+
615
+ def test_double_render
616
+ assert_raises(ActionController::DoubleRenderError) { get :double_render }
617
+ end
618
+
619
+ def test_double_redirect
620
+ assert_raises(ActionController::DoubleRenderError) { get :double_redirect }
621
+ end
622
+
623
+ def test_render_and_redirect
624
+ assert_raises(ActionController::DoubleRenderError) { get :render_and_redirect }
625
+ end
626
+
627
+ # specify the one exception to double render rule - render_to_string followed by render
628
+ def test_render_to_string_and_render
629
+ get :render_to_string_and_render
630
+ assert_equal("Hi web users! here is some cached stuff", @response.body)
631
+ end
632
+
633
+ def test_rendering_with_conflicting_local_vars
634
+ get :rendering_with_conflicting_local_vars
635
+ assert_equal("First: David\nSecond: Stephan\nThird: David\nFourth: David\nFifth: ", @response.body)
636
+ end
637
+
638
+ def test_action_talk_to_layout
639
+ get :action_talk_to_layout
640
+ assert_equal "<title>Talking to the layout</title>\nAction was here!", @response.body
641
+ end
642
+
643
+ def test_partials_list
644
+ get :partials_list
645
+ assert_equal "goodbyeHello: davidHello: marygoodbye\n", @response.body
646
+ end
647
+
648
+ def test_partial_with_locals
649
+ get :partial_with_locals
650
+ assert_equal "Hello: david", @response.body
651
+ end
652
+
653
+ def test_partial_with_form_builder
654
+ get :partial_with_form_builder
655
+ assert_match(/<label/, @response.body)
656
+ assert_template('test/_form')
657
+ end
658
+
659
+ def test_partial_with_form_builder_subclass
660
+ get :partial_with_form_builder_subclass
661
+ assert_match(/<label/, @response.body)
662
+ assert_template('test/_labelling_form')
663
+ end
664
+
665
+ def test_partial_collection
666
+ get :partial_collection
667
+ assert_equal "Hello: davidHello: mary", @response.body
668
+ end
669
+
670
+ def test_partial_collection_with_counter
671
+ get :partial_collection_with_counter
672
+ assert_equal "david0mary1", @response.body
673
+ end
674
+
675
+ def test_partial_collection_with_locals
676
+ get :partial_collection_with_locals
677
+ assert_equal "Bonjour: davidBonjour: mary", @response.body
678
+ end
679
+
680
+ def test_partial_collection_with_spacer
681
+ get :partial_collection_with_spacer
682
+ assert_equal "Hello: davidonly partialHello: mary", @response.body
683
+ end
684
+
685
+ def test_partial_collection_shorthand_with_locals
686
+ get :partial_collection_shorthand_with_locals
687
+ assert_equal "Bonjour: davidBonjour: mary", @response.body
688
+ end
689
+
690
+ def test_partial_collection_shorthand_with_different_types_of_records
691
+ get :partial_collection_shorthand_with_different_types_of_records
692
+ assert_equal "Bonjour bad customer: mark0Bonjour good customer: craig1Bonjour bad customer: john2Bonjour good customer: zach3Bonjour good customer: brandon4Bonjour bad customer: dan5", @response.body
693
+ end
694
+
695
+ def test_empty_partial_collection
696
+ get :empty_partial_collection
697
+ assert_equal " ", @response.body
698
+ end
699
+
700
+ def test_partial_with_hash_object
701
+ get :partial_with_hash_object
702
+ assert_equal "Sam\nmaS\n", @response.body
703
+ end
704
+
705
+ def test_hash_partial_collection
706
+ get :partial_hash_collection
707
+ assert_equal "Pratik\nkitarP\nAmy\nymA\n", @response.body
708
+ end
709
+
710
+ def test_partial_hash_collection_with_locals
711
+ get :partial_hash_collection_with_locals
712
+ assert_equal "Hola: PratikHola: Amy", @response.body
713
+ end
714
+
715
+ def test_partial_with_implicit_local_assignment
716
+ get :partial_with_implicit_local_assignment
717
+ assert_equal "Hello: Marcel", @response.body
718
+ end
719
+
720
+ def test_render_missing_partial_template
721
+ assert_raises(ActionView::MissingTemplate) do
722
+ get :missing_partial
723
+ end
724
+ end
725
+
726
+ def test_render_text_with_assigns
727
+ get :render_text_with_assigns
728
+ assert_equal "world", assigns["hello"]
729
+ end
730
+
731
+ def test_template_with_locals
732
+ get :render_with_explicit_template_with_locals
733
+ assert_equal "The secret is area51\n", @response.body
734
+ end
735
+
736
+ def test_yield_content_for
737
+ assert_not_deprecated { get :yield_content_for }
738
+ assert_equal "<title>Putting stuff in the title!</title>\n\nGreat stuff!\n", @response.body
739
+ end
740
+
741
+
742
+ def test_overwritting_rendering_relative_file_with_extension
743
+ get :hello_world_from_rxml_using_template
744
+ assert_equal "<html>\n <p>Hello</p>\n</html>\n", @response.body
745
+
746
+ get :hello_world_from_rxml_using_action
747
+ assert_equal "<html>\n <p>Hello</p>\n</html>\n", @response.body
748
+ end
749
+
750
+
751
+ def test_head_with_location_header
752
+ get :head_with_location_header
753
+ assert @response.body.blank?
754
+ assert_equal "/foo", @response.headers["Location"]
755
+ assert_response :ok
756
+ end
757
+
758
+ def test_head_with_custom_header
759
+ get :head_with_custom_header
760
+ assert @response.body.blank?
761
+ assert_equal "something", @response.headers["X-Custom-Header"]
762
+ assert_response :ok
763
+ end
764
+
765
+ def test_head_with_symbolic_status
766
+ get :head_with_symbolic_status, :status => "ok"
767
+ assert_equal "200 OK", @response.headers["Status"]
768
+ assert_response :ok
769
+
770
+ get :head_with_symbolic_status, :status => "not_found"
771
+ assert_equal "404 Not Found", @response.headers["Status"]
772
+ assert_response :not_found
773
+
774
+ ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code|
775
+ get :head_with_symbolic_status, :status => status.to_s
776
+ assert_equal code, @response.response_code
777
+ assert_response status
778
+ end
779
+ end
780
+
781
+ def test_head_with_integer_status
782
+ ActionController::StatusCodes::STATUS_CODES.each do |code, message|
783
+ get :head_with_integer_status, :status => code.to_s
784
+ assert_equal message, @response.message
785
+ end
786
+ end
787
+
788
+ def test_head_with_string_status
789
+ get :head_with_string_status, :status => "404 Eat Dirt"
790
+ assert_equal 404, @response.response_code
791
+ assert_equal "Eat Dirt", @response.message
792
+ assert_response :not_found
793
+ end
794
+
795
+ def test_head_with_status_code_first
796
+ get :head_with_status_code_first
797
+ assert_equal 403, @response.response_code
798
+ assert_equal "Forbidden", @response.message
799
+ assert_equal "something", @response.headers["X-Custom-Header"]
800
+ assert_response :forbidden
801
+ end
802
+
803
+ def test_rendering_with_location_should_set_header
804
+ get :render_with_location
805
+ assert_equal "http://example.com", @response.headers["Location"]
806
+ end
807
+
808
+ def test_rendering_xml_should_call_to_xml_if_possible
809
+ get :render_with_to_xml
810
+ assert_equal "<i-am-xml/>", @response.body
811
+ end
812
+
813
+ def test_rendering_with_object_location_should_set_header_with_url_for
814
+ ActionController::Routing::Routes.draw do |map|
815
+ map.resources :customers
816
+ map.connect ':controller/:action/:id'
817
+ end
818
+
819
+ get :render_with_object_location
820
+ assert_equal "http://www.nextangle.com/customers/1", @response.headers["Location"]
821
+ end
822
+
823
+ def test_render_call_to_partial_with_layout
824
+ get :render_call_to_partial_with_layout
825
+ assert_equal "Before (David)\nInside from partial (David)\nAfter", @response.body
826
+ end
827
+
828
+ def test_render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout
829
+ get :render_call_to_partial_with_layout_in_main_layout_and_within_content_for_layout
830
+ assert_equal "Before (Anthony)\nInside from partial (Anthony)\nAfter\nBefore (David)\nInside from partial (David)\nAfter\nBefore (Ramm)\nInside from partial (Ramm)\nAfter", @response.body
831
+ end
832
+
833
+ def test_using_layout_around_block
834
+ get :render_using_layout_around_block
835
+ assert_equal "Before (David)\nInside from block\nAfter", @response.body
836
+ end
837
+
838
+ def test_using_layout_around_block_in_main_layout_and_within_content_for_layout
839
+ get :render_using_layout_around_block_in_main_layout_and_within_content_for_layout
840
+ assert_equal "Before (Anthony)\nInside from first block in layout\nAfter\nBefore (David)\nInside from block\nAfter\nBefore (Ramm)\nInside from second block in layout\nAfter\n", @response.body
841
+ end
842
+
843
+ end