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,2 @@
1
+ <% content_for :title do %>Putting stuff in the title!<% end %>
2
+ Great stuff!
@@ -0,0 +1,3 @@
1
+ <% content_for :title, "Putting stuff "
2
+ content_for :title, "in the title!" %>
3
+ Great stuff!
@@ -0,0 +1,2 @@
1
+ <% content_for :title, "Putting stuff in the title!" %>
2
+ Great stuff!
@@ -0,0 +1,2 @@
1
+ page.remove 'person'
2
+ page.visual_effect :highlight, "project-#{@project_id}"
@@ -0,0 +1 @@
1
+ The secret is <%= @secret %>
@@ -0,0 +1,6 @@
1
+ page.select('.product').each do |value|
2
+ page.visual_effect :highlight
3
+ page.visual_effect :highlight, value
4
+ page.sortable(value, :url => { :action => "order" })
5
+ page.draggable(value)
6
+ end
@@ -0,0 +1,2 @@
1
+ <% erb_content_for :title do %>Putting stuff in the title!<% end %>
2
+ Great stuff!
@@ -0,0 +1 @@
1
+ formatted html erb
@@ -0,0 +1 @@
1
+ xml.test 'failed'
@@ -0,0 +1 @@
1
+ <test>passed formatted html erb</test>
@@ -0,0 +1 @@
1
+ <test>passed formatted xml erb</test>
@@ -0,0 +1 @@
1
+ <p>This is grand!</p>
@@ -0,0 +1 @@
1
+ page[:body].visual_effect :highlight
@@ -0,0 +1,4 @@
1
+ xml.html do
2
+ xml.p "Hello #{@name}"
3
+ xml << render_file("test/greeting")
4
+ end
@@ -0,0 +1 @@
1
+ Hello world!
@@ -0,0 +1,3 @@
1
+ xml.test do
2
+ render :partial => 'hello', :locals => { :xm => xml }
3
+ end
@@ -0,0 +1,4 @@
1
+ xml.html do
2
+ xml.p "Hello"
3
+ end
4
+ "String return value"
@@ -0,0 +1 @@
1
+ Hello world!
@@ -0,0 +1,11 @@
1
+ xml.html do
2
+ xml.head do
3
+ xml.title "Hello World"
4
+ end
5
+
6
+ xml.body do
7
+ xml.p "abes"
8
+ xml.p "monks"
9
+ xml.p "wiseguys"
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ <%= @test_unchanged = 'goodbye' %><%= render :partial => 'customer', :collection => @customers %><%= @test_unchanged %>
@@ -0,0 +1,4 @@
1
+ content_for :title do
2
+ 'Putting stuff in the title!'
3
+ end
4
+ xml << "\nGreat stuff!"
@@ -0,0 +1,4 @@
1
+ First: <%= @name %>
2
+ <%= render :partial => "person", :locals => { :name => "Stephan" } -%>
3
+ Fourth: <%= @name %>
4
+ Fifth: <%= name %>
@@ -0,0 +1 @@
1
+ <%= render :file => @path %>
@@ -0,0 +1 @@
1
+ The secret is <%= @secret %>
@@ -0,0 +1 @@
1
+ The secret is <%= secret %>
@@ -0,0 +1 @@
1
+ The value of foo is: ::<%= @foo %>::
@@ -0,0 +1,9 @@
1
+ <% replacement_function = update_element_function("products", :action => :update) do %>
2
+ <p>Product 1</p>
3
+ <p>Product 2</p>
4
+ <% end %>
5
+ <%= javascript_tag(replacement_function) %>
6
+
7
+ <% update_element_function("status", :action => :update, :binding => binding) do %>
8
+ <b>You bought something!</b>
9
+ <% end %>
@@ -0,0 +1 @@
1
+ <% render(:layout => "layout_for_partial", :locals => { :name => "David" }) do %>Inside from block<% end %>
@@ -0,0 +1,3 @@
1
+ class Topic < ActiveRecord::Base
2
+ has_many :replies, :dependent => :destroy
3
+ end
@@ -0,0 +1,22 @@
1
+ futurama:
2
+ id: 1
3
+ title: Isnt futurama awesome?
4
+ subtitle: It really is, isnt it.
5
+ content: I like futurama
6
+ created_at: <%= 1.day.ago.to_s(:db) %>
7
+ updated_at:
8
+
9
+ harvey_birdman:
10
+ id: 2
11
+ title: Harvey Birdman is the king of all men
12
+ subtitle: yup
13
+ content: It really is
14
+ created_at: <%= 2.hours.ago.to_s(:db) %>
15
+ updated_at:
16
+
17
+ rails:
18
+ id: 3
19
+ title: Rails is nice
20
+ subtitle: It makes me happy
21
+ content: except when I have to hack internals to fix pagination. even then really.
22
+ created_at: <%= 20.minutes.ago.to_s(:db) %>
@@ -0,0 +1 @@
1
+ <%= topic.title %>
@@ -0,0 +1,268 @@
1
+ require 'abstract_unit'
2
+
3
+ class ActiveRecordHelperTest < ActionView::TestCase
4
+ tests ActionView::Helpers::ActiveRecordHelper
5
+
6
+ silence_warnings do
7
+ Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on)
8
+ Post.class_eval do
9
+ alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast)
10
+ alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
11
+ alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
12
+ end
13
+
14
+ User = Struct.new("User", :email)
15
+ User.class_eval do
16
+ alias_method :email_before_type_cast, :email unless respond_to?(:email_before_type_cast)
17
+ end
18
+
19
+ Column = Struct.new("Column", :type, :name, :human_name)
20
+ end
21
+
22
+ def setup_post
23
+ @post = Post.new
24
+ def @post.errors
25
+ Class.new {
26
+ def on(field)
27
+ case field.to_s
28
+ when "author_name"
29
+ "can't be empty"
30
+ when "body"
31
+ true
32
+ else
33
+ false
34
+ end
35
+ end
36
+ def empty?() false end
37
+ def count() 1 end
38
+ def full_messages() [ "Author name can't be empty" ] end
39
+ }.new
40
+ end
41
+
42
+ def @post.new_record?() true end
43
+ def @post.to_param() nil end
44
+
45
+ def @post.column_for_attribute(attr_name)
46
+ Post.content_columns.select { |column| column.name == attr_name }.first
47
+ end
48
+
49
+ silence_warnings do
50
+ def Post.content_columns() [ Column.new(:string, "title", "Title"), Column.new(:text, "body", "Body") ] end
51
+ end
52
+
53
+ @post.title = "Hello World"
54
+ @post.author_name = ""
55
+ @post.body = "Back to the hill and over it again!"
56
+ @post.secret = 1
57
+ @post.written_on = Date.new(2004, 6, 15)
58
+ end
59
+
60
+ def setup_user
61
+ @user = User.new
62
+ def @user.errors
63
+ Class.new {
64
+ def on(field) field == "email" end
65
+ def empty?() false end
66
+ def count() 1 end
67
+ def full_messages() [ "User email can't be empty" ] end
68
+ }.new
69
+ end
70
+
71
+ def @user.new_record?() true end
72
+ def @user.to_param() nil end
73
+
74
+ def @user.column_for_attribute(attr_name)
75
+ User.content_columns.select { |column| column.name == attr_name }.first
76
+ end
77
+
78
+ silence_warnings do
79
+ def User.content_columns() [ Column.new(:string, "email", "Email") ] end
80
+ end
81
+
82
+ @user.email = ""
83
+ end
84
+
85
+ def protect_against_forgery?
86
+ @protect_against_forgery ? true : false
87
+ end
88
+ attr_accessor :request_forgery_protection_token, :form_authenticity_token
89
+
90
+ def setup
91
+ setup_post
92
+ setup_user
93
+
94
+ @response = ActionController::TestResponse.new
95
+
96
+ @controller = Object.new
97
+ def @controller.url_for(options)
98
+ options = options.symbolize_keys
99
+
100
+ [options[:action], options[:id].to_param].compact.join('/')
101
+ end
102
+ end
103
+
104
+ def test_generic_input_tag
105
+ assert_dom_equal(
106
+ %(<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />), input("post", "title")
107
+ )
108
+ end
109
+
110
+ def test_text_area_with_errors
111
+ assert_dom_equal(
112
+ %(<div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div>),
113
+ text_area("post", "body")
114
+ )
115
+ end
116
+
117
+ def test_text_field_with_errors
118
+ assert_dom_equal(
119
+ %(<div class="fieldWithErrors"><input id="post_author_name" name="post[author_name]" size="30" type="text" value="" /></div>),
120
+ text_field("post", "author_name")
121
+ )
122
+ end
123
+
124
+ def test_form_with_string
125
+ assert_dom_equal(
126
+ %(<form action="create" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
127
+ form("post")
128
+ )
129
+
130
+ silence_warnings do
131
+ class << @post
132
+ def new_record?() false end
133
+ def to_param() id end
134
+ def id() 1 end
135
+ end
136
+ end
137
+
138
+ assert_dom_equal(
139
+ %(<form action="update/1" method="post"><input id="post_id" name="post[id]" type="hidden" value="1" /><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Update" /></form>),
140
+ form("post")
141
+ )
142
+ end
143
+
144
+ def test_form_with_protect_against_forgery
145
+ @protect_against_forgery = true
146
+ @request_forgery_protection_token = 'authenticity_token'
147
+ @form_authenticity_token = '123'
148
+ assert_dom_equal(
149
+ %(<form action="create" method="post"><div style='margin:0;padding:0'><input type='hidden' name='authenticity_token' value='123' /></div><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
150
+ form("post")
151
+ )
152
+ end
153
+
154
+ def test_form_with_method_option
155
+ assert_dom_equal(
156
+ %(<form action="create" method="get"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
157
+ form("post", :method=>'get')
158
+ )
159
+ end
160
+
161
+ def test_form_with_action_option
162
+ @response.body = form("post", :action => "sign")
163
+ assert_select "form[action=sign]" do |form|
164
+ assert_select "input[type=submit][value=Sign]"
165
+ end
166
+ end
167
+
168
+ def test_form_with_date
169
+ silence_warnings do
170
+ def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
171
+ end
172
+
173
+ assert_dom_equal(
174
+ %(<form action="create" method="post"><p><label for="post_written_on">Written on</label><br /><select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select id="post_written_on_2i" name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="post_written_on_3i" name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>),
175
+ form("post")
176
+ )
177
+ end
178
+
179
+ def test_form_with_datetime
180
+ silence_warnings do
181
+ def Post.content_columns() [ Column.new(:datetime, "written_on", "Written on") ] end
182
+ end
183
+ @post.written_on = Time.gm(2004, 6, 15, 16, 30)
184
+
185
+ assert_dom_equal(
186
+ %(<form action="create" method="post"><p><label for="post_written_on">Written on</label><br /><select id="post_written_on_1i" name="post[written_on(1i)]">\n<option value="1999">1999</option>\n<option value="2000">2000</option>\n<option value="2001">2001</option>\n<option value="2002">2002</option>\n<option value="2003">2003</option>\n<option value="2004" selected="selected">2004</option>\n<option value="2005">2005</option>\n<option value="2006">2006</option>\n<option value="2007">2007</option>\n<option value="2008">2008</option>\n<option value="2009">2009</option>\n</select>\n<select id="post_written_on_2i" name="post[written_on(2i)]">\n<option value="1">January</option>\n<option value="2">February</option>\n<option value="3">March</option>\n<option value="4">April</option>\n<option value="5">May</option>\n<option value="6" selected="selected">June</option>\n<option value="7">July</option>\n<option value="8">August</option>\n<option value="9">September</option>\n<option value="10">October</option>\n<option value="11">November</option>\n<option value="12">December</option>\n</select>\n<select id="post_written_on_3i" name="post[written_on(3i)]">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="4">4</option>\n<option value="5">5</option>\n<option value="6">6</option>\n<option value="7">7</option>\n<option value="8">8</option>\n<option value="9">9</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15" selected="selected">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30">30</option>\n<option value="31">31</option>\n</select>\n &mdash; <select id="post_written_on_4i" name="post[written_on(4i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16" selected="selected">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n</select>\n : <select id="post_written_on_5i" name="post[written_on(5i)]">\n<option value="00">00</option>\n<option value="01">01</option>\n<option value="02">02</option>\n<option value="03">03</option>\n<option value="04">04</option>\n<option value="05">05</option>\n<option value="06">06</option>\n<option value="07">07</option>\n<option value="08">08</option>\n<option value="09">09</option>\n<option value="10">10</option>\n<option value="11">11</option>\n<option value="12">12</option>\n<option value="13">13</option>\n<option value="14">14</option>\n<option value="15">15</option>\n<option value="16">16</option>\n<option value="17">17</option>\n<option value="18">18</option>\n<option value="19">19</option>\n<option value="20">20</option>\n<option value="21">21</option>\n<option value="22">22</option>\n<option value="23">23</option>\n<option value="24">24</option>\n<option value="25">25</option>\n<option value="26">26</option>\n<option value="27">27</option>\n<option value="28">28</option>\n<option value="29">29</option>\n<option value="30" selected="selected">30</option>\n<option value="31">31</option>\n<option value="32">32</option>\n<option value="33">33</option>\n<option value="34">34</option>\n<option value="35">35</option>\n<option value="36">36</option>\n<option value="37">37</option>\n<option value="38">38</option>\n<option value="39">39</option>\n<option value="40">40</option>\n<option value="41">41</option>\n<option value="42">42</option>\n<option value="43">43</option>\n<option value="44">44</option>\n<option value="45">45</option>\n<option value="46">46</option>\n<option value="47">47</option>\n<option value="48">48</option>\n<option value="49">49</option>\n<option value="50">50</option>\n<option value="51">51</option>\n<option value="52">52</option>\n<option value="53">53</option>\n<option value="54">54</option>\n<option value="55">55</option>\n<option value="56">56</option>\n<option value="57">57</option>\n<option value="58">58</option>\n<option value="59">59</option>\n</select>\n</p><input name="commit" type="submit" value="Create" /></form>),
187
+ form("post")
188
+ )
189
+ end
190
+
191
+ def test_error_for_block
192
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post")
193
+ assert_equal %(<div class="errorDeathByClass" id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
194
+ assert_equal %(<div id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => nil, :id => "errorDeathById", :header_tag => "h1")
195
+ assert_equal %(<div class="errorDeathByClass"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1")
196
+ end
197
+
198
+ def test_error_messages_for_handles_nil
199
+ assert_equal "", error_messages_for("notthere")
200
+ end
201
+
202
+ def test_error_message_on_handles_nil
203
+ assert_equal "", error_message_on("notthere", "notthere")
204
+ end
205
+
206
+ def test_error_message_on
207
+ assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(:post, :author_name)
208
+ end
209
+
210
+ def test_error_message_on_no_instance_variable
211
+ other_post = @post
212
+ assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(other_post, :author_name)
213
+ end
214
+
215
+ def test_error_message_on_should_use_options
216
+ assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", error_message_on(:post, :author_name, "before", "after", "differentError")
217
+ end
218
+
219
+ def test_error_messages_for_many_objects
220
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li><li>User email can't be empty</li></ul></div>), error_messages_for("post", "user")
221
+
222
+ # reverse the order, error order changes and so does the title
223
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post")
224
+
225
+ # add the default to put post back in the title
226
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post", :object_name => "post")
227
+
228
+ # symbols work as well
229
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => :post)
230
+
231
+ # any default works too
232
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this monkey from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "monkey")
233
+
234
+ # should space object name
235
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this chunky bacon from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "chunky_bacon")
236
+
237
+ # hide header and explanation messages with nil or empty string
238
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :header_message => nil, :message => "")
239
+
240
+ # override header and explanation messages
241
+ header_message = "Yikes! Some errors"
242
+ message = "Please fix the following fields and resubmit:"
243
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>#{header_message}</h2><p>#{message}</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :header_message => header_message, :message => message)
244
+ end
245
+
246
+ def test_error_messages_for_non_instance_variable
247
+ actual_user = @user
248
+ actual_post = @post
249
+ @user = nil
250
+ @post = nil
251
+
252
+ #explicitly set object
253
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :object => actual_post)
254
+
255
+ #multiple objects
256
+ assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post", :object => [actual_user, actual_post])
257
+
258
+ #nil object
259
+ assert_equal '', error_messages_for('user', :object => nil)
260
+ end
261
+
262
+ def test_form_with_string_multipart
263
+ assert_dom_equal(
264
+ %(<form action="create" enctype="multipart/form-data" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
265
+ form("post", :multipart => true)
266
+ )
267
+ end
268
+ end
@@ -0,0 +1,514 @@
1
+ require 'abstract_unit'
2
+
3
+ class AssetTagHelperTest < ActionView::TestCase
4
+ tests ActionView::Helpers::AssetTagHelper
5
+
6
+ def setup
7
+ silence_warnings do
8
+ ActionView::Helpers::AssetTagHelper.send(
9
+ :const_set,
10
+ :JAVASCRIPTS_DIR,
11
+ File.dirname(__FILE__) + "/../fixtures/public/javascripts"
12
+ )
13
+
14
+ ActionView::Helpers::AssetTagHelper.send(
15
+ :const_set,
16
+ :STYLESHEETS_DIR,
17
+ File.dirname(__FILE__) + "/../fixtures/public/stylesheets"
18
+ )
19
+
20
+ ActionView::Helpers::AssetTagHelper.send(
21
+ :const_set,
22
+ :ASSETS_DIR,
23
+ File.dirname(__FILE__) + "/../fixtures/public"
24
+ )
25
+ end
26
+
27
+ @controller = Class.new do
28
+ attr_accessor :request
29
+ def url_for(*args) "http://www.example.com" end
30
+ end.new
31
+
32
+ @request = Class.new do
33
+ def relative_url_root() "" end
34
+ def protocol() 'http://' end
35
+ def ssl?() false end
36
+ def host_with_port() 'localhost' end
37
+ end.new
38
+
39
+ @controller.request = @request
40
+
41
+ ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
42
+
43
+ ActionView::Base.computed_public_paths.clear
44
+ end
45
+
46
+ def teardown
47
+ ActionController::Base.perform_caching = false
48
+ ActionController::Base.asset_host = nil
49
+ ENV.delete('RAILS_ASSET_ID')
50
+ end
51
+
52
+ AutoDiscoveryToTag = {
53
+ %(auto_discovery_link_tag) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
54
+ %(auto_discovery_link_tag(:rss)) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
55
+ %(auto_discovery_link_tag(:atom)) => %(<link href="http://www.example.com" rel="alternate" title="ATOM" type="application/atom+xml" />),
56
+ %(auto_discovery_link_tag(:xml)) => %(<link href="http://www.example.com" rel="alternate" title="XML" type="application/xml" />),
57
+ %(auto_discovery_link_tag(:rss, :action => "feed")) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
58
+ %(auto_discovery_link_tag(:rss, "http://localhost/feed")) => %(<link href="http://localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />),
59
+ %(auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "My RSS"})) => %(<link href="http://www.example.com" rel="alternate" title="My RSS" type="application/rss+xml" />),
60
+ %(auto_discovery_link_tag(:rss, {}, {:title => "My RSS"})) => %(<link href="http://www.example.com" rel="alternate" title="My RSS" type="application/rss+xml" />),
61
+ %(auto_discovery_link_tag(nil, {}, {:type => "text/html"})) => %(<link href="http://www.example.com" rel="alternate" title="" type="text/html" />),
62
+ %(auto_discovery_link_tag(nil, {}, {:title => "No stream.. really", :type => "text/html"})) => %(<link href="http://www.example.com" rel="alternate" title="No stream.. really" type="text/html" />),
63
+ %(auto_discovery_link_tag(:rss, {}, {:title => "My RSS", :type => "text/html"})) => %(<link href="http://www.example.com" rel="alternate" title="My RSS" type="text/html" />),
64
+ %(auto_discovery_link_tag(:atom, {}, {:rel => "Not so alternate"})) => %(<link href="http://www.example.com" rel="Not so alternate" title="ATOM" type="application/atom+xml" />),
65
+ }
66
+
67
+ JavascriptPathToTag = {
68
+ %(javascript_path("xmlhr")) => %(/javascripts/xmlhr.js),
69
+ %(javascript_path("super/xmlhr")) => %(/javascripts/super/xmlhr.js),
70
+ %(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js)
71
+ }
72
+
73
+ PathToJavascriptToTag = {
74
+ %(path_to_javascript("xmlhr")) => %(/javascripts/xmlhr.js),
75
+ %(path_to_javascript("super/xmlhr")) => %(/javascripts/super/xmlhr.js),
76
+ %(path_to_javascript("/super/xmlhr.js")) => %(/super/xmlhr.js)
77
+ }
78
+
79
+ JavascriptIncludeToTag = {
80
+ %(javascript_include_tag("xmlhr")) => %(<script src="/javascripts/xmlhr.js" type="text/javascript"></script>),
81
+ %(javascript_include_tag("xmlhr.js")) => %(<script src="/javascripts/xmlhr.js" type="text/javascript"></script>),
82
+ %(javascript_include_tag("xmlhr", :lang => "vbscript")) => %(<script lang="vbscript" src="/javascripts/xmlhr.js" type="text/javascript"></script>),
83
+ %(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(<script src="/javascripts/common.javascript" type="text/javascript"></script>\n<script src="/elsewhere/cools.js" type="text/javascript"></script>),
84
+ %(javascript_include_tag(:all)) => %(<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>),
85
+ }
86
+
87
+ StylePathToTag = {
88
+ %(stylesheet_path("style")) => %(/stylesheets/style.css),
89
+ %(stylesheet_path("style.css")) => %(/stylesheets/style.css),
90
+ %(stylesheet_path('dir/file')) => %(/stylesheets/dir/file.css),
91
+ %(stylesheet_path('/dir/file.rcss')) => %(/dir/file.rcss)
92
+ }
93
+
94
+ PathToStyleToTag = {
95
+ %(path_to_stylesheet("style")) => %(/stylesheets/style.css),
96
+ %(path_to_stylesheet("style.css")) => %(/stylesheets/style.css),
97
+ %(path_to_stylesheet('dir/file')) => %(/stylesheets/dir/file.css),
98
+ %(path_to_stylesheet('/dir/file.rcss')) => %(/dir/file.rcss)
99
+ }
100
+
101
+ StyleLinkToTag = {
102
+ %(stylesheet_link_tag("style")) => %(<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />),
103
+ %(stylesheet_link_tag("style.css")) => %(<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />),
104
+ %(stylesheet_link_tag("/dir/file")) => %(<link href="/dir/file.css" media="screen" rel="stylesheet" type="text/css" />),
105
+ %(stylesheet_link_tag("dir/file")) => %(<link href="/stylesheets/dir/file.css" media="screen" rel="stylesheet" type="text/css" />),
106
+ %(stylesheet_link_tag("style", :media => "all")) => %(<link href="/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />),
107
+ %(stylesheet_link_tag(:all)) => %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />),
108
+ %(stylesheet_link_tag(:all, :media => "all")) => %(<link href="/stylesheets/bank.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="all" rel="stylesheet" type="text/css" />),
109
+ %(stylesheet_link_tag("random.styles", "/css/stylish")) => %(<link href="/stylesheets/random.styles" media="screen" rel="stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="stylesheet" type="text/css" />),
110
+ %(stylesheet_link_tag("http://www.example.com/styles/style")) => %(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" type="text/css" />)
111
+ }
112
+
113
+ ImagePathToTag = {
114
+ %(image_path("xml")) => %(/images/xml),
115
+ %(image_path("xml.png")) => %(/images/xml.png),
116
+ %(image_path("dir/xml.png")) => %(/images/dir/xml.png),
117
+ %(image_path("/dir/xml.png")) => %(/dir/xml.png)
118
+ }
119
+
120
+ PathToImageToTag = {
121
+ %(path_to_image("xml")) => %(/images/xml),
122
+ %(path_to_image("xml.png")) => %(/images/xml.png),
123
+ %(path_to_image("dir/xml.png")) => %(/images/dir/xml.png),
124
+ %(path_to_image("/dir/xml.png")) => %(/dir/xml.png)
125
+ }
126
+
127
+ ImageLinkToTag = {
128
+ %(image_tag("xml.png")) => %(<img alt="Xml" src="/images/xml.png" />),
129
+ %(image_tag("..jpg")) => %(<img alt="" src="/images/..jpg" />),
130
+ %(image_tag("rss.gif", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/images/rss.gif" />),
131
+ %(image_tag("gold.png", :size => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />),
132
+ %(image_tag("gold.png", "size" => "45x70")) => %(<img alt="Gold" height="70" src="/images/gold.png" width="45" />),
133
+ %(image_tag("error.png", "size" => "45")) => %(<img alt="Error" src="/images/error.png" />),
134
+ %(image_tag("error.png", "size" => "45 x 70")) => %(<img alt="Error" src="/images/error.png" />),
135
+ %(image_tag("error.png", "size" => "x")) => %(<img alt="Error" src="/images/error.png" />),
136
+ %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />),
137
+ %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />),
138
+ %(image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />),
139
+ %(image_tag("mouse.png", :mouseover => image_path("mouse_over.png"))) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />)
140
+ }
141
+
142
+
143
+ def test_auto_discovery_link_tag
144
+ AutoDiscoveryToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
145
+ end
146
+
147
+ def test_javascript_path
148
+ JavascriptPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
149
+ end
150
+
151
+ def test_path_to_javascript_alias_for_javascript_path
152
+ PathToJavascriptToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
153
+ end
154
+
155
+ def test_javascript_include_tag
156
+ ENV["RAILS_ASSET_ID"] = ""
157
+ JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
158
+
159
+ ActionView::Base.computed_public_paths.clear
160
+
161
+ ENV["RAILS_ASSET_ID"] = "1"
162
+ assert_dom_equal(%(<script type="text/javascript" src="/javascripts/application.js?1"></script>\n<script type="text/javascript" src="/javascripts/bank.js?1"></script>\n<script type="text/javascript" src="/javascripts/robber.js?1"></script>\n<script type="text/javascript" src="/javascripts/version.1.0.js?1"></script>), javascript_include_tag(:all))
163
+ end
164
+
165
+ def test_custom_javascript_expansions
166
+ ActionView::Helpers::AssetTagHelper::register_javascript_expansion :monkey => ["head", "body", "tail"]
167
+ assert_dom_equal %(<script src="/javascripts/first.js" type="text/javascript"></script>\n<script src="/javascripts/head.js" type="text/javascript"></script>\n<script src="/javascripts/body.js" type="text/javascript"></script>\n<script src="/javascripts/tail.js" type="text/javascript"></script>\n<script src="/javascripts/last.js" type="text/javascript"></script>), javascript_include_tag('first', :monkey, 'last')
168
+ end
169
+
170
+ def test_custom_javascript_expansions_and_defaults_puts_application_js_at_the_end
171
+ ENV["RAILS_ASSET_ID"] = ""
172
+ ActionView::Helpers::AssetTagHelper::register_javascript_expansion :monkey => ["head", "body", "tail"]
173
+ assert_dom_equal %(<script src="/javascripts/first.js" type="text/javascript"></script>\n<script src="/javascripts/head.js" type="text/javascript"></script>\n<script src="/javascripts/body.js" type="text/javascript"></script>\n<script src="/javascripts/tail.js" type="text/javascript"></script>\n<script src="/javascripts/last.js" type="text/javascript"></script>), javascript_include_tag('first', :monkey, 'last')
174
+ end
175
+
176
+ def test_custom_javascript_expansions_with_undefined_symbol
177
+ ActionView::Helpers::AssetTagHelper::register_javascript_expansion :monkey => nil
178
+ assert_raise(ArgumentError) { javascript_include_tag('first', :monkey, 'last') }
179
+ end
180
+
181
+ def test_stylesheet_path
182
+ StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
183
+ end
184
+
185
+ def test_path_to_stylesheet_alias_for_stylesheet_path
186
+ PathToStyleToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
187
+ end
188
+
189
+ def test_stylesheet_link_tag
190
+ ENV["RAILS_ASSET_ID"] = ""
191
+ StyleLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
192
+ end
193
+
194
+ def test_custom_stylesheet_expansions
195
+ ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :monkey => ["head", "body", "tail"]
196
+ assert_dom_equal %(<link href="/stylesheets/first.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/head.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/body.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/tail.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/last.css" media="screen" rel="stylesheet" type="text/css" />), stylesheet_link_tag('first', :monkey, 'last')
197
+ end
198
+
199
+ def test_custom_stylesheet_expansions_with_undefined_symbol
200
+ ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :monkey => nil
201
+ assert_raise(ArgumentError) { stylesheet_link_tag('first', :monkey, 'last') }
202
+ end
203
+
204
+ def test_image_path
205
+ ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
206
+ end
207
+
208
+ def test_path_to_image_alias_for_image_path
209
+ PathToImageToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
210
+ end
211
+
212
+ def test_image_tag
213
+ ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
214
+ end
215
+
216
+ def test_timebased_asset_id
217
+ expected_time = File.stat(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).mtime.to_i.to_s
218
+ assert_equal %(<img alt="Rails" src="/images/rails.png?#{expected_time}" />), image_tag("rails.png")
219
+ end
220
+
221
+ def test_should_skip_asset_id_on_complete_url
222
+ assert_equal %(<img alt="Rails" src="http://www.example.com/rails.png" />), image_tag("http://www.example.com/rails.png")
223
+ end
224
+
225
+ def test_should_use_preset_asset_id
226
+ ENV["RAILS_ASSET_ID"] = "4500"
227
+ assert_equal %(<img alt="Rails" src="/images/rails.png?4500" />), image_tag("rails.png")
228
+ end
229
+
230
+ def test_preset_empty_asset_id
231
+ ENV["RAILS_ASSET_ID"] = ""
232
+ assert_equal %(<img alt="Rails" src="/images/rails.png" />), image_tag("rails.png")
233
+ end
234
+
235
+ def test_should_not_modify_source_string
236
+ source = '/images/rails.png'
237
+ copy = source.dup
238
+ image_tag(source)
239
+ assert_equal copy, source
240
+ end
241
+
242
+ def test_caching_javascript_include_tag_when_caching_on
243
+ ENV["RAILS_ASSET_ID"] = ""
244
+ ActionController::Base.asset_host = 'http://a0.example.com'
245
+ ActionController::Base.perform_caching = true
246
+
247
+ assert_dom_equal(
248
+ %(<script src="http://a0.example.com/javascripts/all.js" type="text/javascript"></script>),
249
+ javascript_include_tag(:all, :cache => true)
250
+ )
251
+
252
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
253
+
254
+ assert_dom_equal(
255
+ %(<script src="http://a0.example.com/javascripts/money.js" type="text/javascript"></script>),
256
+ javascript_include_tag(:all, :cache => "money")
257
+ )
258
+
259
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
260
+
261
+ ensure
262
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
263
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
264
+ end
265
+
266
+ def test_caching_javascript_include_tag_when_caching_on_with_proc_asset_host
267
+ ENV['RAILS_ASSET_ID'] = ''
268
+ ActionController::Base.asset_host = Proc.new { |source| "http://a#{source.length}.example.com" }
269
+ ActionController::Base.perform_caching = true
270
+
271
+ assert_equal '/javascripts/scripts.js'.length, 23
272
+ assert_dom_equal(
273
+ %(<script src="http://a23.example.com/javascripts/scripts.js" type="text/javascript"></script>),
274
+ javascript_include_tag(:all, :cache => 'scripts')
275
+ )
276
+
277
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'scripts.js'))
278
+
279
+ ensure
280
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'scripts.js'))
281
+ end
282
+
283
+ def test_caching_javascript_include_tag_when_caching_on_with_2_argument_proc_asset_host
284
+ ENV['RAILS_ASSET_ID'] = ''
285
+ ActionController::Base.asset_host = Proc.new { |source, request|
286
+ if request.ssl?
287
+ "#{request.protocol}#{request.host_with_port}"
288
+ else
289
+ "#{request.protocol}assets#{source.length}.example.com"
290
+ end
291
+ }
292
+ ActionController::Base.perform_caching = true
293
+
294
+ assert_equal '/javascripts/vanilla.js'.length, 23
295
+ assert_dom_equal(
296
+ %(<script src="http://assets23.example.com/javascripts/vanilla.js" type="text/javascript"></script>),
297
+ javascript_include_tag(:all, :cache => 'vanilla')
298
+ )
299
+
300
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js'))
301
+
302
+ class << @controller.request
303
+ def protocol() 'https://' end
304
+ def ssl?() true end
305
+ end
306
+
307
+ assert_equal '/javascripts/secure.js'.length, 22
308
+ assert_dom_equal(
309
+ %(<script src="https://localhost/javascripts/secure.js" type="text/javascript"></script>),
310
+ javascript_include_tag(:all, :cache => 'secure')
311
+ )
312
+
313
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js'))
314
+
315
+ ensure
316
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'vanilla.js'))
317
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'secure.js'))
318
+ end
319
+
320
+ def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory
321
+ ENV["RAILS_ASSET_ID"] = ""
322
+ ActionController::Base.asset_host = 'http://a%d.example.com'
323
+ ActionController::Base.perform_caching = true
324
+
325
+ assert_dom_equal(
326
+ %(<script src="http://a3.example.com/javascripts/cache/money.js" type="text/javascript"></script>),
327
+ javascript_include_tag(:all, :cache => "cache/money")
328
+ )
329
+
330
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js'))
331
+ ensure
332
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js'))
333
+ end
334
+
335
+ def test_caching_javascript_include_tag_with_all_puts_defaults_at_the_start_of_the_file
336
+ ENV["RAILS_ASSET_ID"] = ""
337
+ ActionController::Base.asset_host = 'http://a0.example.com'
338
+ ActionController::Base.perform_caching = true
339
+
340
+ assert_dom_equal(
341
+ %(<script src="http://a0.example.com/javascripts/combined.js" type="text/javascript"></script>),
342
+ javascript_include_tag(:all, :cache => "combined")
343
+ )
344
+
345
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js'))
346
+
347
+ assert_equal(
348
+ %(// application js\n\n// bank js\n\n// robber js\n\n// version.1.0 js),
349
+ IO.read(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js'))
350
+ )
351
+
352
+ ensure
353
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js'))
354
+ end
355
+
356
+ def test_caching_javascript_include_tag_when_caching_off
357
+ ENV["RAILS_ASSET_ID"] = ""
358
+ ActionController::Base.perform_caching = false
359
+
360
+ assert_dom_equal(
361
+ %(<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>),
362
+ javascript_include_tag(:all, :cache => true)
363
+ )
364
+
365
+ assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
366
+
367
+ assert_dom_equal(
368
+ %(<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>),
369
+ javascript_include_tag(:all, :cache => "money")
370
+ )
371
+
372
+ assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
373
+ end
374
+
375
+ def test_caching_stylesheet_link_tag_when_caching_on
376
+ ENV["RAILS_ASSET_ID"] = ""
377
+ ActionController::Base.asset_host = 'http://a0.example.com'
378
+ ActionController::Base.perform_caching = true
379
+
380
+ assert_dom_equal(
381
+ %(<link href="http://a0.example.com/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />),
382
+ stylesheet_link_tag(:all, :cache => true)
383
+ )
384
+
385
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
386
+
387
+ assert_dom_equal(
388
+ %(<link href="http://a0.example.com/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />),
389
+ stylesheet_link_tag(:all, :cache => "money")
390
+ )
391
+
392
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
393
+ ensure
394
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
395
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
396
+ end
397
+
398
+ def test_caching_stylesheet_link_tag_when_caching_on_with_proc_asset_host
399
+ ENV["RAILS_ASSET_ID"] = ""
400
+ ActionController::Base.asset_host = Proc.new { |source| "http://a#{source.length}.example.com" }
401
+ ActionController::Base.perform_caching = true
402
+
403
+ assert_equal '/stylesheets/styles.css'.length, 23
404
+ assert_dom_equal(
405
+ %(<link href="http://a23.example.com/stylesheets/styles.css" media="screen" rel="stylesheet" type="text/css" />),
406
+ stylesheet_link_tag(:all, :cache => 'styles')
407
+ )
408
+
409
+ assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'styles.css'))
410
+
411
+ ensure
412
+ FileUtils.rm_f(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'styles.css'))
413
+ end
414
+
415
+ def test_caching_stylesheet_include_tag_when_caching_off
416
+ ENV["RAILS_ASSET_ID"] = ""
417
+ ActionController::Base.perform_caching = false
418
+
419
+ assert_dom_equal(
420
+ %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />),
421
+ stylesheet_link_tag(:all, :cache => true)
422
+ )
423
+
424
+ assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
425
+
426
+ assert_dom_equal(
427
+ %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />),
428
+ stylesheet_link_tag(:all, :cache => "money")
429
+ )
430
+
431
+ assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
432
+ end
433
+ end
434
+
435
+ class AssetTagHelperNonVhostTest < ActionView::TestCase
436
+ tests ActionView::Helpers::AssetTagHelper
437
+
438
+ def setup
439
+ @controller = Class.new do
440
+ attr_accessor :request
441
+
442
+ def url_for(options)
443
+ "http://www.example.com/collaboration/hieraki"
444
+ end
445
+ end.new
446
+
447
+ @request = Class.new do
448
+ def relative_url_root
449
+ "/collaboration/hieraki"
450
+ end
451
+
452
+ def protocol
453
+ 'gopher://'
454
+ end
455
+ end.new
456
+
457
+ @controller.request = @request
458
+
459
+ ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
460
+ end
461
+
462
+ def test_should_compute_proper_path
463
+ assert_dom_equal(%(<link href="http://www.example.com/collaboration/hieraki" rel="alternate" title="RSS" type="application/rss+xml" />), auto_discovery_link_tag)
464
+ assert_dom_equal(%(/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr"))
465
+ assert_dom_equal(%(/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style"))
466
+ assert_dom_equal(%(/collaboration/hieraki/images/xml.png), image_path("xml.png"))
467
+ assert_dom_equal(%(<img alt="Mouse" onmouseover="this.src='/collaboration/hieraki/images/mouse_over.png'" onmouseout="this.src='/collaboration/hieraki/images/mouse.png'" src="/collaboration/hieraki/images/mouse.png" />), image_tag("mouse.png", :mouseover => "/images/mouse_over.png"))
468
+ assert_dom_equal(%(<img alt="Mouse2" onmouseover="this.src='/collaboration/hieraki/images/mouse_over2.png'" onmouseout="this.src='/collaboration/hieraki/images/mouse2.png'" src="/collaboration/hieraki/images/mouse2.png" />), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png")))
469
+ end
470
+
471
+ def test_should_ignore_relative_root_path_on_complete_url
472
+ assert_dom_equal(%(http://www.example.com/images/xml.png), image_path("http://www.example.com/images/xml.png"))
473
+ end
474
+
475
+ def test_should_compute_proper_path_with_asset_host
476
+ ActionController::Base.asset_host = "http://assets.example.com"
477
+ assert_dom_equal(%(<link href="http://www.example.com/collaboration/hieraki" rel="alternate" title="RSS" type="application/rss+xml" />), auto_discovery_link_tag)
478
+ assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr"))
479
+ assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style"))
480
+ assert_dom_equal(%(http://assets.example.com/collaboration/hieraki/images/xml.png), image_path("xml.png"))
481
+ assert_dom_equal(%(<img alt="Mouse" onmouseover="this.src='http://assets.example.com/collaboration/hieraki/images/mouse_over.png'" onmouseout="this.src='http://assets.example.com/collaboration/hieraki/images/mouse.png'" src="http://assets.example.com/collaboration/hieraki/images/mouse.png" />), image_tag("mouse.png", :mouseover => "/images/mouse_over.png"))
482
+ assert_dom_equal(%(<img alt="Mouse2" onmouseover="this.src='http://assets.example.com/collaboration/hieraki/images/mouse_over2.png'" onmouseout="this.src='http://assets.example.com/collaboration/hieraki/images/mouse2.png'" src="http://assets.example.com/collaboration/hieraki/images/mouse2.png" />), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png")))
483
+ ensure
484
+ ActionController::Base.asset_host = ""
485
+ end
486
+
487
+ def test_should_ignore_asset_host_on_complete_url
488
+ ActionController::Base.asset_host = "http://assets.example.com"
489
+ assert_dom_equal(%(<link href="http://bar.example.com/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />), stylesheet_link_tag("http://bar.example.com/stylesheets/style.css"))
490
+ ensure
491
+ ActionController::Base.asset_host = ""
492
+ end
493
+
494
+ def test_should_wildcard_asset_host_between_zero_and_four
495
+ ActionController::Base.asset_host = 'http://a%d.example.com'
496
+ assert_match %r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_path('xml.png')
497
+ ensure
498
+ ActionController::Base.asset_host = nil
499
+ end
500
+
501
+ def test_asset_host_without_protocol_should_use_request_protocol
502
+ ActionController::Base.asset_host = 'a.example.com'
503
+ assert_equal 'gopher://a.example.com/collaboration/hieraki/images/xml.png', image_path('xml.png')
504
+ ensure
505
+ ActionController::Base.asset_host = nil
506
+ end
507
+
508
+ def test_asset_host_without_protocol_should_use_request_protocol_even_if_path_present
509
+ ActionController::Base.asset_host = 'a.example.com/files/go/here'
510
+ assert_equal 'gopher://a.example.com/files/go/here/collaboration/hieraki/images/xml.png', image_path('xml.png')
511
+ ensure
512
+ ActionController::Base.asset_host = nil
513
+ end
514
+ end