eactionpack 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,43 @@
1
+ require 'abstract_unit'
2
+ require 'action_controller/integration'
3
+ require 'action_controller/routing'
4
+
5
+ unless defined? ApplicationController
6
+ class ApplicationController < ActionController::Base
7
+ end
8
+ end
9
+
10
+ class UploadTestController < ActionController::Base
11
+ session :off
12
+
13
+ def update
14
+ SessionUploadTest.last_request_type = ActionController::Base.param_parsers[request.content_type]
15
+ render :text => "got here"
16
+ end
17
+ end
18
+
19
+ class SessionUploadTest < ActionController::IntegrationTest
20
+ FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart'
21
+
22
+ class << self
23
+ attr_accessor :last_request_type
24
+ end
25
+
26
+ # def setup
27
+ # @session = ActionController::Integration::Session.new
28
+ # end
29
+ def test_post_with_upload
30
+ uses_mocha "test_post_with_upload" do
31
+ ActiveSupport::Dependencies.stubs(:load?).returns(false)
32
+ with_routing do |set|
33
+ set.draw do |map|
34
+ map.update 'update', :controller => "upload_test", :action => "update", :method => :post
35
+ end
36
+
37
+ params = { :uploaded_data => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg") }
38
+ post '/update', params, :location => 'blah'
39
+ assert_equal(:multipart_form, SessionUploadTest.last_request_type)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,255 @@
1
+ require 'abstract_unit'
2
+
3
+ # The view_paths array must be set on Base and not LayoutTest so that LayoutTest's inherited
4
+ # method has access to the view_paths array when looking for a layout to automatically assign.
5
+ old_load_paths = ActionController::Base.view_paths
6
+ ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/layout_tests/' ]
7
+
8
+ class LayoutTest < ActionController::Base
9
+ def self.controller_path; 'views' end
10
+ self.view_paths = ActionController::Base.view_paths.dup
11
+ end
12
+
13
+ # Restore view_paths to previous value
14
+ ActionController::Base.view_paths = old_load_paths
15
+
16
+ class ProductController < LayoutTest
17
+ end
18
+
19
+ class ItemController < LayoutTest
20
+ end
21
+
22
+ class ThirdPartyTemplateLibraryController < LayoutTest
23
+ end
24
+
25
+ module ControllerNameSpace
26
+ end
27
+
28
+ class ControllerNameSpace::NestedController < LayoutTest
29
+ end
30
+
31
+ class MultipleExtensions < LayoutTest
32
+ end
33
+
34
+ class MabView < ActionView::TemplateHandler
35
+ def initialize(view)
36
+ end
37
+
38
+ def render(template)
39
+ template.source
40
+ end
41
+ end
42
+
43
+ ActionView::Template::register_template_handler :mab, MabView
44
+
45
+ class LayoutAutoDiscoveryTest < Test::Unit::TestCase
46
+ def setup
47
+ @request = ActionController::TestRequest.new
48
+ @response = ActionController::TestResponse.new
49
+
50
+ @request.host = "www.nextangle.com"
51
+ end
52
+
53
+ def test_application_layout_is_default_when_no_controller_match
54
+ @controller = ProductController.new
55
+ get :hello
56
+ assert_equal 'layout_test.rhtml hello.rhtml', @response.body
57
+ end
58
+
59
+ def test_controller_name_layout_name_match
60
+ @controller = ItemController.new
61
+ get :hello
62
+ assert_equal 'item.rhtml hello.rhtml', @response.body
63
+ end
64
+
65
+ def test_third_party_template_library_auto_discovers_layout
66
+ @controller = ThirdPartyTemplateLibraryController.new
67
+ get :hello
68
+ assert_equal 'layouts/third_party_template_library', @controller.active_layout
69
+ assert_equal 'layouts/third_party_template_library', @response.layout
70
+ assert_response :success
71
+ assert_equal 'Mab', @response.body
72
+ end
73
+
74
+ def test_namespaced_controllers_auto_detect_layouts
75
+ @controller = ControllerNameSpace::NestedController.new
76
+ get :hello
77
+ assert_equal 'layouts/controller_name_space/nested', @controller.active_layout
78
+ assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body
79
+ end
80
+
81
+ def test_namespaced_controllers_auto_detect_layouts
82
+ @controller = MultipleExtensions.new
83
+ get :hello
84
+ assert_equal 'layouts/multiple_extensions', @controller.active_layout
85
+ assert_equal 'multiple_extensions.html.erb hello.rhtml', @response.body.strip
86
+ end
87
+ end
88
+
89
+ class ExemptFromLayoutTest < Test::Unit::TestCase
90
+ def setup
91
+ @controller = LayoutTest.new
92
+ @request = ActionController::TestRequest.new
93
+ @response = ActionController::TestResponse.new
94
+ end
95
+
96
+ def test_rhtml_and_rxml_not_exempt_from_layout
97
+ assert !@controller.send!(:template_exempt_from_layout?, 'test.rhtml')
98
+ assert !@controller.send!(:template_exempt_from_layout?, 'test.rxml')
99
+ end
100
+
101
+ def test_other_extension_not_exempt_from_layout
102
+ assert !@controller.send!(:template_exempt_from_layout?, 'test.random')
103
+ end
104
+
105
+ def test_add_extension_to_exempt_from_layout
106
+ ['rpdf', :rpdf].each do |ext|
107
+ assert_nothing_raised do
108
+ ActionController::Base.exempt_from_layout ext
109
+ end
110
+ assert @controller.send!(:template_exempt_from_layout?, "test.#{ext}")
111
+ end
112
+ end
113
+
114
+ def test_add_regexp_to_exempt_from_layout
115
+ ActionController::Base.exempt_from_layout /\.rdoc/
116
+ assert @controller.send!(:template_exempt_from_layout?, 'test.rdoc')
117
+ end
118
+
119
+ def test_rhtml_exempt_from_layout_status_should_prevent_layout_render
120
+ ActionController::Base.exempt_from_layout :rhtml
121
+
122
+ assert @controller.send!(:template_exempt_from_layout?, 'test.rhtml')
123
+ assert @controller.send!(:template_exempt_from_layout?, 'hello.rhtml')
124
+
125
+ get :hello
126
+ assert_equal 'hello.rhtml', @response.body
127
+ ActionController::Base.exempt_from_layout.delete(/\.rhtml$/)
128
+ end
129
+ end
130
+
131
+
132
+ class DefaultLayoutController < LayoutTest
133
+ end
134
+
135
+ class HasOwnLayoutController < LayoutTest
136
+ layout 'item'
137
+ end
138
+
139
+ class SetsLayoutInRenderController < LayoutTest
140
+ def hello
141
+ render :layout => 'third_party_template_library'
142
+ end
143
+ end
144
+
145
+ class RendersNoLayoutController < LayoutTest
146
+ def hello
147
+ render :layout => false
148
+ end
149
+ end
150
+
151
+ class LayoutSetInResponseTest < Test::Unit::TestCase
152
+ def setup
153
+ @request = ActionController::TestRequest.new
154
+ @response = ActionController::TestResponse.new
155
+ end
156
+
157
+ def test_layout_set_when_using_default_layout
158
+ @controller = DefaultLayoutController.new
159
+ get :hello
160
+ assert_equal 'layouts/layout_test', @response.layout
161
+ end
162
+
163
+ def test_layout_set_when_set_in_controller
164
+ @controller = HasOwnLayoutController.new
165
+ get :hello
166
+ assert_equal 'layouts/item', @response.layout
167
+ end
168
+
169
+ def test_layout_set_when_using_render
170
+ @controller = SetsLayoutInRenderController.new
171
+ get :hello
172
+ assert_equal 'layouts/third_party_template_library', @response.layout
173
+ end
174
+
175
+ def test_layout_is_not_set_when_none_rendered
176
+ @controller = RendersNoLayoutController.new
177
+ get :hello
178
+ assert_nil @response.layout
179
+ end
180
+
181
+ def test_exempt_from_layout_honored_by_render_template
182
+ ActionController::Base.exempt_from_layout :rhtml
183
+ @controller = RenderWithTemplateOptionController.new
184
+
185
+ assert @controller.send(:template_exempt_from_layout?, 'alt/hello.rhtml')
186
+
187
+ get :hello
188
+ assert_equal "alt/hello.rhtml", @response.body.strip
189
+
190
+ ensure
191
+ ActionController::Base.exempt_from_layout.delete(/\.rhtml$/)
192
+ end
193
+ end
194
+
195
+ class RenderWithTemplateOptionController < LayoutTest
196
+ def hello
197
+ render :template => 'alt/hello'
198
+ end
199
+ end
200
+
201
+ class SetsNonExistentLayoutFile < LayoutTest
202
+ layout "nofile.rhtml"
203
+ end
204
+
205
+ class LayoutExceptionRaised < Test::Unit::TestCase
206
+ def setup
207
+ @request = ActionController::TestRequest.new
208
+ @response = ActionController::TestResponse.new
209
+ end
210
+
211
+ def test_exception_raised_when_layout_file_not_found
212
+ @controller = SetsNonExistentLayoutFile.new
213
+ get :hello
214
+ @response.template.class.module_eval { attr_accessor :exception }
215
+ assert_equal ActionView::MissingTemplate, @response.template.exception.class
216
+ end
217
+ end
218
+
219
+ class LayoutStatusIsRendered < LayoutTest
220
+ def hello
221
+ render :status => 401
222
+ end
223
+ end
224
+
225
+ class LayoutStatusIsRenderedTest < Test::Unit::TestCase
226
+ def setup
227
+ @request = ActionController::TestRequest.new
228
+ @response = ActionController::TestResponse.new
229
+ end
230
+
231
+ def test_layout_status_is_rendered
232
+ @controller = LayoutStatusIsRendered.new
233
+ get :hello
234
+ assert_response 401
235
+ end
236
+ end
237
+
238
+ class LayoutSymlinkedTest < LayoutTest
239
+ layout "symlinked/symlinked_layout"
240
+ end
241
+
242
+ class LayoutSymlinkedIsRenderedTest < Test::Unit::TestCase
243
+ def setup
244
+ @request = ActionController::TestRequest.new
245
+ @response = ActionController::TestResponse.new
246
+ end
247
+
248
+ def test_symlinked_layout_is_rendered
249
+ @controller = LayoutSymlinkedTest.new
250
+ get :hello
251
+ assert_response 200
252
+ assert_equal "layouts/symlinked/symlinked_layout", @response.layout
253
+ end
254
+ end
255
+
@@ -0,0 +1,514 @@
1
+ require 'abstract_unit'
2
+
3
+ class RespondToController < ActionController::Base
4
+ layout :set_layout
5
+
6
+ def html_xml_or_rss
7
+ respond_to do |type|
8
+ type.html { render :text => "HTML" }
9
+ type.xml { render :text => "XML" }
10
+ type.rss { render :text => "RSS" }
11
+ type.all { render :text => "Nothing" }
12
+ end
13
+ end
14
+
15
+ def js_or_html
16
+ respond_to do |type|
17
+ type.html { render :text => "HTML" }
18
+ type.js { render :text => "JS" }
19
+ type.all { render :text => "Nothing" }
20
+ end
21
+ end
22
+
23
+ def json_or_yaml
24
+ respond_to do |type|
25
+ type.json { render :text => "JSON" }
26
+ type.yaml { render :text => "YAML" }
27
+ end
28
+ end
29
+
30
+ def html_or_xml
31
+ respond_to do |type|
32
+ type.html { render :text => "HTML" }
33
+ type.xml { render :text => "XML" }
34
+ type.all { render :text => "Nothing" }
35
+ end
36
+ end
37
+
38
+ def forced_xml
39
+ request.format = :xml
40
+
41
+ respond_to do |type|
42
+ type.html { render :text => "HTML" }
43
+ type.xml { render :text => "XML" }
44
+ end
45
+ end
46
+
47
+ def just_xml
48
+ respond_to do |type|
49
+ type.xml { render :text => "XML" }
50
+ end
51
+ end
52
+
53
+ def using_defaults
54
+ respond_to do |type|
55
+ type.html
56
+ type.js
57
+ type.xml
58
+ end
59
+ end
60
+
61
+ def using_defaults_with_type_list
62
+ respond_to(:html, :js, :xml)
63
+ end
64
+
65
+ def made_for_content_type
66
+ respond_to do |type|
67
+ type.rss { render :text => "RSS" }
68
+ type.atom { render :text => "ATOM" }
69
+ type.all { render :text => "Nothing" }
70
+ end
71
+ end
72
+
73
+ def custom_type_handling
74
+ respond_to do |type|
75
+ type.html { render :text => "HTML" }
76
+ type.custom("application/crazy-xml") { render :text => "Crazy XML" }
77
+ type.all { render :text => "Nothing" }
78
+ end
79
+ end
80
+
81
+ def custom_constant_handling
82
+ Mime::Type.register("text/x-mobile", :mobile)
83
+
84
+ respond_to do |type|
85
+ type.html { render :text => "HTML" }
86
+ type.mobile { render :text => "Mobile" }
87
+ end
88
+ ensure
89
+ Mime.module_eval { remove_const :MOBILE if const_defined?(:MOBILE) }
90
+ end
91
+
92
+ def custom_constant_handling_without_block
93
+ Mime::Type.register("text/x-mobile", :mobile)
94
+
95
+ respond_to do |type|
96
+ type.html { render :text => "HTML" }
97
+ type.mobile
98
+ end
99
+
100
+ ensure
101
+ Mime.module_eval { remove_const :MOBILE if const_defined?(:MOBILE) }
102
+ end
103
+
104
+ def handle_any
105
+ respond_to do |type|
106
+ type.html { render :text => "HTML" }
107
+ type.any(:js, :xml) { render :text => "Either JS or XML" }
108
+ end
109
+ end
110
+
111
+ def handle_any_any
112
+ respond_to do |type|
113
+ type.html { render :text => 'HTML' }
114
+ type.any { render :text => 'Whatever you ask for, I got it' }
115
+ end
116
+ end
117
+
118
+ def all_types_with_layout
119
+ respond_to do |type|
120
+ type.html
121
+ type.js
122
+ end
123
+ end
124
+
125
+ def iphone_with_html_response_type
126
+ Mime::Type.register_alias("text/html", :iphone)
127
+ request.format = :iphone if request.env["HTTP_ACCEPT"] == "text/iphone"
128
+
129
+ respond_to do |type|
130
+ type.html { @type = "Firefox" }
131
+ type.iphone { @type = "iPhone" }
132
+ end
133
+
134
+ ensure
135
+ Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
136
+ end
137
+
138
+ def iphone_with_html_response_type_without_layout
139
+ Mime::Type.register_alias("text/html", :iphone)
140
+ request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"
141
+
142
+ respond_to do |type|
143
+ type.html { @type = "Firefox"; render :action => "iphone_with_html_response_type" }
144
+ type.iphone { @type = "iPhone" ; render :action => "iphone_with_html_response_type" }
145
+ end
146
+
147
+ ensure
148
+ Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
149
+ end
150
+
151
+ def rescue_action(e)
152
+ raise
153
+ end
154
+
155
+ protected
156
+ def set_layout
157
+ if ["all_types_with_layout", "iphone_with_html_response_type"].include?(action_name)
158
+ "respond_to/layouts/standard"
159
+ elsif action_name == "iphone_with_html_response_type_without_layout"
160
+ "respond_to/layouts/missing"
161
+ end
162
+ end
163
+ end
164
+
165
+ RespondToController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
166
+
167
+ class MimeControllerTest < Test::Unit::TestCase
168
+ def setup
169
+ @request = ActionController::TestRequest.new
170
+ @response = ActionController::TestResponse.new
171
+
172
+ @controller = RespondToController.new
173
+ @request.host = "www.example.com"
174
+ end
175
+
176
+ def test_html
177
+ @request.env["HTTP_ACCEPT"] = "text/html"
178
+ get :js_or_html
179
+ assert_equal 'HTML', @response.body
180
+
181
+ get :html_or_xml
182
+ assert_equal 'HTML', @response.body
183
+
184
+ get :just_xml
185
+ assert_response 406
186
+ end
187
+
188
+ def test_all
189
+ @request.env["HTTP_ACCEPT"] = "*/*"
190
+ get :js_or_html
191
+ assert_equal 'HTML', @response.body # js is not part of all
192
+
193
+ get :html_or_xml
194
+ assert_equal 'HTML', @response.body
195
+
196
+ get :just_xml
197
+ assert_equal 'XML', @response.body
198
+ end
199
+
200
+ def test_xml
201
+ @request.env["HTTP_ACCEPT"] = "application/xml"
202
+ get :html_xml_or_rss
203
+ assert_equal 'XML', @response.body
204
+ end
205
+
206
+ def test_js_or_html
207
+ @request.env["HTTP_ACCEPT"] = "text/javascript, text/html"
208
+ get :js_or_html
209
+ assert_equal 'JS', @response.body
210
+
211
+ get :html_or_xml
212
+ assert_equal 'HTML', @response.body
213
+
214
+ get :just_xml
215
+ assert_response 406
216
+ end
217
+
218
+ def test_json_or_yaml
219
+ get :json_or_yaml
220
+ assert_equal 'JSON', @response.body
221
+
222
+ get :json_or_yaml, :format => 'json'
223
+ assert_equal 'JSON', @response.body
224
+
225
+ get :json_or_yaml, :format => 'yaml'
226
+ assert_equal 'YAML', @response.body
227
+
228
+ { 'YAML' => %w(text/yaml),
229
+ 'JSON' => %w(application/json text/x-json)
230
+ }.each do |body, content_types|
231
+ content_types.each do |content_type|
232
+ @request.env['HTTP_ACCEPT'] = content_type
233
+ get :json_or_yaml
234
+ assert_equal body, @response.body
235
+ end
236
+ end
237
+ end
238
+
239
+ def test_js_or_anything
240
+ @request.env["HTTP_ACCEPT"] = "text/javascript, */*"
241
+ get :js_or_html
242
+ assert_equal 'JS', @response.body
243
+
244
+ get :html_or_xml
245
+ assert_equal 'HTML', @response.body
246
+
247
+ get :just_xml
248
+ assert_equal 'XML', @response.body
249
+ end
250
+
251
+ def test_using_defaults
252
+ @request.env["HTTP_ACCEPT"] = "*/*"
253
+ get :using_defaults
254
+ assert_equal "text/html", @response.content_type
255
+ assert_equal 'Hello world!', @response.body
256
+
257
+ @request.env["HTTP_ACCEPT"] = "application/xml"
258
+ get :using_defaults
259
+ assert_equal "application/xml", @response.content_type
260
+ assert_equal "<p>Hello world!</p>\n", @response.body
261
+ end
262
+
263
+ def test_using_defaults_with_type_list
264
+ @request.env["HTTP_ACCEPT"] = "*/*"
265
+ get :using_defaults_with_type_list
266
+ assert_equal "text/html", @response.content_type
267
+ assert_equal 'Hello world!', @response.body
268
+
269
+ @request.env["HTTP_ACCEPT"] = "application/xml"
270
+ get :using_defaults_with_type_list
271
+ assert_equal "application/xml", @response.content_type
272
+ assert_equal "<p>Hello world!</p>\n", @response.body
273
+ end
274
+
275
+ def test_with_atom_content_type
276
+ @request.env["CONTENT_TYPE"] = "application/atom+xml"
277
+ get :made_for_content_type
278
+ assert_equal "ATOM", @response.body
279
+ end
280
+
281
+ def test_with_rss_content_type
282
+ @request.env["CONTENT_TYPE"] = "application/rss+xml"
283
+ get :made_for_content_type
284
+ assert_equal "RSS", @response.body
285
+ end
286
+
287
+ def test_synonyms
288
+ @request.env["HTTP_ACCEPT"] = "application/javascript"
289
+ get :js_or_html
290
+ assert_equal 'JS', @response.body
291
+
292
+ @request.env["HTTP_ACCEPT"] = "application/x-xml"
293
+ get :html_xml_or_rss
294
+ assert_equal "XML", @response.body
295
+ end
296
+
297
+ def test_custom_types
298
+ @request.env["HTTP_ACCEPT"] = "application/crazy-xml"
299
+ get :custom_type_handling
300
+ assert_equal "application/crazy-xml", @response.content_type
301
+ assert_equal 'Crazy XML', @response.body
302
+
303
+ @request.env["HTTP_ACCEPT"] = "text/html"
304
+ get :custom_type_handling
305
+ assert_equal "text/html", @response.content_type
306
+ assert_equal 'HTML', @response.body
307
+ end
308
+
309
+ def test_xhtml_alias
310
+ @request.env["HTTP_ACCEPT"] = "application/xhtml+xml,application/xml"
311
+ get :html_or_xml
312
+ assert_equal 'HTML', @response.body
313
+ end
314
+
315
+ def test_firefox_simulation
316
+ @request.env["HTTP_ACCEPT"] = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
317
+ get :html_or_xml
318
+ assert_equal 'HTML', @response.body
319
+ end
320
+
321
+ def test_handle_any
322
+ @request.env["HTTP_ACCEPT"] = "*/*"
323
+ get :handle_any
324
+ assert_equal 'HTML', @response.body
325
+
326
+ @request.env["HTTP_ACCEPT"] = "text/javascript"
327
+ get :handle_any
328
+ assert_equal 'Either JS or XML', @response.body
329
+
330
+ @request.env["HTTP_ACCEPT"] = "text/xml"
331
+ get :handle_any
332
+ assert_equal 'Either JS or XML', @response.body
333
+ end
334
+
335
+ def test_handle_any_any
336
+ @request.env["HTTP_ACCEPT"] = "*/*"
337
+ get :handle_any_any
338
+ assert_equal 'HTML', @response.body
339
+ end
340
+
341
+ def test_handle_any_any_parameter_format
342
+ get :handle_any_any, {:format=>'html'}
343
+ assert_equal 'HTML', @response.body
344
+ end
345
+
346
+ def test_handle_any_any_explicit_html
347
+ @request.env["HTTP_ACCEPT"] = "text/html"
348
+ get :handle_any_any
349
+ assert_equal 'HTML', @response.body
350
+ end
351
+
352
+ def test_handle_any_any_javascript
353
+ @request.env["HTTP_ACCEPT"] = "text/javascript"
354
+ get :handle_any_any
355
+ assert_equal 'Whatever you ask for, I got it', @response.body
356
+ end
357
+
358
+ def test_handle_any_any_xml
359
+ @request.env["HTTP_ACCEPT"] = "text/xml"
360
+ get :handle_any_any
361
+ assert_equal 'Whatever you ask for, I got it', @response.body
362
+ end
363
+
364
+ def test_html_type_with_layout
365
+ @request.env["HTTP_ACCEPT"] = "text/html"
366
+ get :all_types_with_layout
367
+ assert_equal '<html><div id="html">HTML for all_types_with_layout</div></html>', @response.body
368
+ end
369
+
370
+ def test_custom_constant
371
+ get :custom_constant_handling, :format => "mobile"
372
+ assert_equal "text/x-mobile", @response.content_type
373
+ assert_equal "Mobile", @response.body
374
+ end
375
+
376
+ def test_custom_constant_handling_without_block
377
+ get :custom_constant_handling_without_block, :format => "mobile"
378
+ assert_equal "text/x-mobile", @response.content_type
379
+ assert_equal "Mobile", @response.body
380
+ end
381
+
382
+ def test_forced_format
383
+ get :html_xml_or_rss
384
+ assert_equal "HTML", @response.body
385
+
386
+ get :html_xml_or_rss, :format => "html"
387
+ assert_equal "HTML", @response.body
388
+
389
+ get :html_xml_or_rss, :format => "xml"
390
+ assert_equal "XML", @response.body
391
+
392
+ get :html_xml_or_rss, :format => "rss"
393
+ assert_equal "RSS", @response.body
394
+ end
395
+
396
+ def test_internally_forced_format
397
+ get :forced_xml
398
+ assert_equal "XML", @response.body
399
+
400
+ get :forced_xml, :format => "html"
401
+ assert_equal "XML", @response.body
402
+ end
403
+
404
+ def test_extension_synonyms
405
+ get :html_xml_or_rss, :format => "xhtml"
406
+ assert_equal "HTML", @response.body
407
+ end
408
+
409
+ def test_render_action_for_html
410
+ @controller.instance_eval do
411
+ def render(*args)
412
+ unless args.empty?
413
+ @action = args.first[:action]
414
+ end
415
+ response.body = "#{@action} - #{@template.template_format}"
416
+ end
417
+ end
418
+
419
+ get :using_defaults
420
+ assert_equal "using_defaults - html", @response.body
421
+
422
+ get :using_defaults, :format => "xml"
423
+ assert_equal "using_defaults - xml", @response.body
424
+ end
425
+
426
+ def test_format_with_custom_response_type
427
+ get :iphone_with_html_response_type
428
+ assert_equal '<html><div id="html">Hello future from Firefox!</div></html>', @response.body
429
+
430
+ get :iphone_with_html_response_type, :format => "iphone"
431
+ assert_equal "text/html", @response.content_type
432
+ assert_equal '<html><div id="iphone">Hello iPhone future from iPhone!</div></html>', @response.body
433
+ end
434
+
435
+ def test_format_with_custom_response_type_and_request_headers
436
+ @request.env["HTTP_ACCEPT"] = "text/iphone"
437
+ get :iphone_with_html_response_type
438
+ assert_equal '<html><div id="iphone">Hello iPhone future from iPhone!</div></html>', @response.body
439
+ assert_equal "text/html", @response.content_type
440
+ end
441
+
442
+ def test_format_with_custom_response_type_and_request_headers_with_only_one_layout_present
443
+ get :iphone_with_html_response_type_without_layout
444
+ assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body
445
+
446
+ @request.env["HTTP_ACCEPT"] = "text/iphone"
447
+ assert_raises(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
448
+ end
449
+ end
450
+
451
+ class AbstractPostController < ActionController::Base
452
+ self.view_paths = File.dirname(__FILE__) + "/../fixtures/post_test/"
453
+ end
454
+
455
+ # For testing layouts which are set automatically
456
+ class PostController < AbstractPostController
457
+ around_filter :with_iphone
458
+
459
+ def index
460
+ respond_to do |type|
461
+ type.html
462
+ type.iphone
463
+ end
464
+ end
465
+
466
+ protected
467
+ def with_iphone
468
+ Mime::Type.register_alias("text/html", :iphone)
469
+ request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"
470
+ yield
471
+ ensure
472
+ Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
473
+ end
474
+ end
475
+
476
+ class SuperPostController < PostController
477
+ def index
478
+ respond_to do |type|
479
+ type.html
480
+ type.iphone
481
+ end
482
+ end
483
+ end
484
+
485
+ class MimeControllerLayoutsTest < Test::Unit::TestCase
486
+ def setup
487
+ @request = ActionController::TestRequest.new
488
+ @response = ActionController::TestResponse.new
489
+
490
+ @controller = PostController.new
491
+ @request.host = "www.example.com"
492
+ end
493
+
494
+ def test_missing_layout_renders_properly
495
+ get :index
496
+ assert_equal '<html><div id="html">Hello Firefox</div></html>', @response.body
497
+
498
+ @request.env["HTTP_ACCEPT"] = "text/iphone"
499
+ get :index
500
+ assert_equal 'Hello iPhone', @response.body
501
+ end
502
+
503
+ def test_format_with_inherited_layouts
504
+ @controller = SuperPostController.new
505
+
506
+ get :index
507
+ assert_equal 'Super Firefox', @response.body
508
+
509
+ @request.env["HTTP_ACCEPT"] = "text/iphone"
510
+ get :index
511
+ assert_equal '<html><div id="super_iphone">Super iPhone</div></html>', @response.body
512
+ end
513
+ end
514
+