actionpack 2.2.3 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (264) hide show
  1. data/CHANGELOG +433 -375
  2. data/MIT-LICENSE +1 -1
  3. data/README +21 -75
  4. data/Rakefile +1 -1
  5. data/lib/action_controller.rb +80 -43
  6. data/lib/action_controller/assertions/model_assertions.rb +1 -0
  7. data/lib/action_controller/assertions/response_assertions.rb +43 -16
  8. data/lib/action_controller/assertions/routing_assertions.rb +1 -1
  9. data/lib/action_controller/assertions/selector_assertions.rb +17 -12
  10. data/lib/action_controller/assertions/tag_assertions.rb +1 -4
  11. data/lib/action_controller/base.rb +153 -82
  12. data/lib/action_controller/benchmarking.rb +9 -9
  13. data/lib/action_controller/caching.rb +9 -11
  14. data/lib/action_controller/caching/actions.rb +11 -18
  15. data/lib/action_controller/caching/fragments.rb +28 -20
  16. data/lib/action_controller/caching/pages.rb +13 -15
  17. data/lib/action_controller/caching/sweeping.rb +2 -2
  18. data/lib/action_controller/cgi_ext.rb +0 -1
  19. data/lib/action_controller/cgi_ext/cookie.rb +2 -0
  20. data/lib/action_controller/cgi_process.rb +54 -162
  21. data/lib/action_controller/cookies.rb +13 -25
  22. data/lib/action_controller/dispatcher.rb +43 -122
  23. data/lib/action_controller/failsafe.rb +52 -0
  24. data/lib/action_controller/flash.rb +38 -47
  25. data/lib/action_controller/helpers.rb +13 -9
  26. data/lib/action_controller/http_authentication.rb +203 -23
  27. data/lib/action_controller/integration.rb +126 -70
  28. data/lib/action_controller/layout.rb +36 -39
  29. data/lib/action_controller/middleware_stack.rb +119 -0
  30. data/lib/action_controller/middlewares.rb +13 -0
  31. data/lib/action_controller/mime_responds.rb +19 -4
  32. data/lib/action_controller/mime_type.rb +8 -0
  33. data/lib/action_controller/params_parser.rb +71 -0
  34. data/lib/action_controller/performance_test.rb +0 -1
  35. data/lib/action_controller/polymorphic_routes.rb +36 -30
  36. data/lib/action_controller/reloader.rb +14 -0
  37. data/lib/action_controller/request.rb +107 -499
  38. data/lib/action_controller/request_forgery_protection.rb +7 -39
  39. data/lib/action_controller/rescue.rb +55 -35
  40. data/lib/action_controller/resources.rb +34 -31
  41. data/lib/action_controller/response.rb +99 -57
  42. data/lib/action_controller/rewindable_input.rb +28 -0
  43. data/lib/action_controller/routing.rb +7 -7
  44. data/lib/action_controller/routing/builder.rb +4 -1
  45. data/lib/action_controller/routing/optimisations.rb +1 -1
  46. data/lib/action_controller/routing/recognition_optimisation.rb +1 -2
  47. data/lib/action_controller/routing/route.rb +15 -5
  48. data/lib/action_controller/routing/route_set.rb +82 -35
  49. data/lib/action_controller/routing/segments.rb +35 -0
  50. data/lib/action_controller/session/abstract_store.rb +181 -0
  51. data/lib/action_controller/session/cookie_store.rb +197 -175
  52. data/lib/action_controller/session/mem_cache_store.rb +36 -83
  53. data/lib/action_controller/session_management.rb +26 -134
  54. data/lib/action_controller/streaming.rb +24 -7
  55. data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
  56. data/lib/action_controller/templates/rescues/template_error.erb +2 -2
  57. data/lib/action_controller/test_case.rb +87 -30
  58. data/lib/action_controller/test_process.rb +145 -104
  59. data/lib/action_controller/uploaded_file.rb +44 -0
  60. data/lib/action_controller/url_rewriter.rb +3 -6
  61. data/lib/action_controller/vendor/html-scanner.rb +16 -0
  62. data/lib/action_controller/vendor/html-scanner/html/selector.rb +1 -1
  63. data/lib/action_controller/vendor/rack-1.0/rack.rb +89 -0
  64. data/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +22 -0
  65. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +37 -0
  66. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +37 -0
  67. data/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +58 -0
  68. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +124 -0
  69. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +51 -0
  70. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +55 -0
  71. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +40 -0
  72. data/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +480 -0
  73. data/lib/action_controller/vendor/rack-1.0/rack/builder.rb +63 -0
  74. data/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +36 -0
  75. data/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +49 -0
  76. data/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +61 -0
  77. data/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +45 -0
  78. data/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +29 -0
  79. data/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +23 -0
  80. data/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +85 -0
  81. data/lib/action_controller/vendor/rack-1.0/rack/directory.rb +153 -0
  82. data/lib/action_controller/vendor/rack-1.0/rack/file.rb +88 -0
  83. data/lib/action_controller/vendor/rack-1.0/rack/handler.rb +48 -0
  84. data/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +61 -0
  85. data/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +8 -0
  86. data/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +89 -0
  87. data/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +55 -0
  88. data/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +84 -0
  89. data/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +59 -0
  90. data/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +8 -0
  91. data/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +18 -0
  92. data/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +67 -0
  93. data/lib/action_controller/vendor/rack-1.0/rack/head.rb +19 -0
  94. data/lib/action_controller/vendor/rack-1.0/rack/lint.rb +462 -0
  95. data/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +65 -0
  96. data/lib/action_controller/vendor/rack-1.0/rack/lock.rb +16 -0
  97. data/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +27 -0
  98. data/lib/action_controller/vendor/rack-1.0/rack/mime.rb +204 -0
  99. data/lib/action_controller/vendor/rack-1.0/rack/mock.rb +160 -0
  100. data/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +57 -0
  101. data/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +64 -0
  102. data/lib/action_controller/vendor/rack-1.0/rack/request.rb +241 -0
  103. data/lib/action_controller/vendor/rack-1.0/rack/response.rb +179 -0
  104. data/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +142 -0
  105. data/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +91 -0
  106. data/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +109 -0
  107. data/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +100 -0
  108. data/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +349 -0
  109. data/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +106 -0
  110. data/lib/action_controller/vendor/rack-1.0/rack/static.rb +38 -0
  111. data/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +55 -0
  112. data/lib/action_controller/vendor/rack-1.0/rack/utils.rb +392 -0
  113. data/lib/action_controller/verification.rb +1 -1
  114. data/lib/action_pack.rb +1 -1
  115. data/lib/action_pack/version.rb +2 -2
  116. data/lib/action_view.rb +22 -17
  117. data/lib/action_view/base.rb +53 -79
  118. data/lib/action_view/erb/util.rb +38 -0
  119. data/lib/action_view/helpers.rb +24 -5
  120. data/lib/action_view/helpers/active_record_helper.rb +2 -2
  121. data/lib/action_view/helpers/asset_tag_helper.rb +81 -50
  122. data/lib/action_view/helpers/atom_feed_helper.rb +1 -1
  123. data/lib/action_view/helpers/benchmark_helper.rb +26 -5
  124. data/lib/action_view/helpers/date_helper.rb +82 -7
  125. data/lib/action_view/helpers/form_helper.rb +295 -64
  126. data/lib/action_view/helpers/form_options_helper.rb +160 -18
  127. data/lib/action_view/helpers/form_tag_helper.rb +2 -2
  128. data/lib/action_view/helpers/number_helper.rb +31 -18
  129. data/lib/action_view/helpers/prototype_helper.rb +2 -12
  130. data/lib/action_view/helpers/sanitize_helper.rb +0 -10
  131. data/lib/action_view/helpers/scriptaculous_helper.rb +1 -0
  132. data/lib/action_view/helpers/tag_helper.rb +3 -4
  133. data/lib/action_view/helpers/text_helper.rb +99 -122
  134. data/lib/action_view/helpers/translation_helper.rb +19 -1
  135. data/lib/action_view/helpers/url_helper.rb +25 -2
  136. data/lib/action_view/inline_template.rb +1 -1
  137. data/lib/action_view/locale/en.yml +19 -1
  138. data/lib/action_view/partials.rb +46 -9
  139. data/lib/action_view/paths.rb +28 -84
  140. data/lib/action_view/reloadable_template.rb +117 -0
  141. data/lib/action_view/renderable.rb +28 -35
  142. data/lib/action_view/renderable_partial.rb +3 -4
  143. data/lib/action_view/template.rb +172 -31
  144. data/lib/action_view/template_error.rb +8 -9
  145. data/lib/action_view/template_handler.rb +1 -1
  146. data/lib/action_view/template_handlers.rb +9 -6
  147. data/lib/action_view/template_handlers/erb.rb +2 -39
  148. data/lib/action_view/template_handlers/rjs.rb +1 -0
  149. data/lib/action_view/test_case.rb +27 -1
  150. data/test/abstract_unit.rb +23 -17
  151. data/test/active_record_unit.rb +5 -4
  152. data/test/activerecord/active_record_store_test.rb +139 -106
  153. data/test/activerecord/render_partial_with_record_identification_test.rb +5 -21
  154. data/test/controller/action_pack_assertions_test.rb +25 -23
  155. data/test/controller/addresses_render_test.rb +3 -6
  156. data/test/controller/assert_select_test.rb +83 -70
  157. data/test/controller/base_test.rb +11 -13
  158. data/test/controller/benchmark_test.rb +3 -3
  159. data/test/controller/caching_test.rb +34 -24
  160. data/test/controller/capture_test.rb +3 -6
  161. data/test/controller/content_type_test.rb +3 -6
  162. data/test/controller/cookie_test.rb +31 -66
  163. data/test/controller/deprecation/deprecated_base_methods_test.rb +9 -11
  164. data/test/controller/dispatcher_test.rb +23 -28
  165. data/test/controller/fake_models.rb +8 -0
  166. data/test/controller/filters_test.rb +6 -2
  167. data/test/controller/flash_test.rb +2 -6
  168. data/test/controller/helper_test.rb +15 -1
  169. data/test/controller/html-scanner/document_test.rb +1 -1
  170. data/test/controller/html-scanner/sanitizer_test.rb +1 -1
  171. data/test/controller/http_basic_authentication_test.rb +88 -0
  172. data/test/controller/http_digest_authentication_test.rb +178 -0
  173. data/test/controller/integration_test.rb +56 -52
  174. data/test/controller/layout_test.rb +46 -44
  175. data/test/controller/middleware_stack_test.rb +90 -0
  176. data/test/controller/mime_responds_test.rb +7 -11
  177. data/test/controller/mime_type_test.rb +9 -0
  178. data/test/controller/polymorphic_routes_test.rb +235 -151
  179. data/test/controller/rack_test.rb +52 -81
  180. data/test/controller/redirect_test.rb +6 -14
  181. data/test/controller/render_test.rb +273 -60
  182. data/test/controller/request/json_params_parsing_test.rb +45 -0
  183. data/test/controller/request/multipart_params_parsing_test.rb +223 -0
  184. data/test/controller/request/query_string_parsing_test.rb +120 -0
  185. data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
  186. data/test/controller/request/xml_params_parsing_test.rb +88 -0
  187. data/test/controller/request_forgery_protection_test.rb +17 -98
  188. data/test/controller/request_test.rb +45 -530
  189. data/test/controller/rescue_test.rb +45 -22
  190. data/test/controller/resources_test.rb +112 -37
  191. data/test/controller/routing_test.rb +1442 -1384
  192. data/test/controller/selector_test.rb +3 -3
  193. data/test/controller/send_file_test.rb +30 -3
  194. data/test/controller/session/cookie_store_test.rb +169 -240
  195. data/test/controller/session/mem_cache_store_test.rb +94 -148
  196. data/test/controller/session/test_session_test.rb +58 -0
  197. data/test/controller/test_test.rb +32 -13
  198. data/test/controller/url_rewriter_test.rb +54 -4
  199. data/test/controller/verification_test.rb +1 -1
  200. data/test/controller/view_paths_test.rb +15 -15
  201. data/test/controller/webservice_test.rb +178 -147
  202. data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
  203. data/test/fixtures/layout_tests/alt/layouts/alt.rhtml +0 -0
  204. data/test/fixtures/layouts/default_html.html.erb +1 -0
  205. data/test/fixtures/layouts/xhr.html.erb +2 -0
  206. data/test/fixtures/multipart/empty +10 -0
  207. data/test/fixtures/multipart/hello.txt +1 -0
  208. data/test/fixtures/multipart/none +9 -0
  209. data/test/fixtures/public/500.da.html +1 -0
  210. data/test/fixtures/quiz/questions/_question.html.erb +1 -0
  211. data/test/fixtures/replies.yml +1 -1
  212. data/test/fixtures/test/_one.html.erb +1 -0
  213. data/test/fixtures/test/_two.html.erb +1 -0
  214. data/test/fixtures/test/dont_pick_me +1 -0
  215. data/test/fixtures/test/hello.builder +1 -1
  216. data/test/fixtures/test/hello_world.da.html.erb +1 -0
  217. data/test/fixtures/test/hello_world.erb~ +1 -0
  218. data/test/fixtures/test/hello_world.pt-BR.html.erb +1 -0
  219. data/test/fixtures/test/malformed/malformed.en.html.erb~ +1 -0
  220. data/test/fixtures/test/malformed/malformed.erb~ +1 -0
  221. data/test/fixtures/test/malformed/malformed.html.erb~ +1 -0
  222. data/test/fixtures/test/render_explicit_html_template.js.rjs +1 -0
  223. data/test/fixtures/test/render_implicit_html_template.js.rjs +1 -0
  224. data/test/fixtures/test/render_implicit_html_template_from_xhr_request.da.html.erb +1 -0
  225. data/test/fixtures/test/render_implicit_html_template_from_xhr_request.html.erb +1 -0
  226. data/test/fixtures/test/render_implicit_js_template_without_layout.js.erb +1 -0
  227. data/test/fixtures/test/utf8.html.erb +2 -0
  228. data/test/template/active_record_helper_i18n_test.rb +31 -33
  229. data/test/template/active_record_helper_test.rb +34 -0
  230. data/test/template/asset_tag_helper_test.rb +52 -14
  231. data/test/template/atom_feed_helper_test.rb +3 -5
  232. data/test/template/benchmark_helper_test.rb +50 -24
  233. data/test/template/compiled_templates_test.rb +177 -33
  234. data/test/template/date_helper_i18n_test.rb +88 -81
  235. data/test/template/date_helper_test.rb +427 -43
  236. data/test/template/form_helper_test.rb +243 -44
  237. data/test/template/form_options_helper_test.rb +631 -565
  238. data/test/template/form_tag_helper_test.rb +9 -2
  239. data/test/template/javascript_helper_test.rb +0 -5
  240. data/test/template/number_helper_i18n_test.rb +60 -48
  241. data/test/template/number_helper_test.rb +1 -0
  242. data/test/template/render_test.rb +117 -35
  243. data/test/template/test_test.rb +4 -6
  244. data/test/template/text_helper_test.rb +129 -50
  245. data/test/template/translation_helper_test.rb +23 -19
  246. data/test/template/url_helper_test.rb +35 -2
  247. data/test/view/test_case_test.rb +8 -0
  248. metadata +197 -23
  249. data/lib/action_controller/assertions.rb +0 -69
  250. data/lib/action_controller/caching/sql_cache.rb +0 -18
  251. data/lib/action_controller/cgi_ext/session.rb +0 -53
  252. data/lib/action_controller/components.rb +0 -169
  253. data/lib/action_controller/rack_process.rb +0 -297
  254. data/lib/action_controller/request_profiler.rb +0 -169
  255. data/lib/action_controller/session/active_record_store.rb +0 -340
  256. data/lib/action_controller/session/drb_server.rb +0 -32
  257. data/lib/action_controller/session/drb_store.rb +0 -35
  258. data/test/controller/cgi_test.rb +0 -269
  259. data/test/controller/components_test.rb +0 -156
  260. data/test/controller/http_authentication_test.rb +0 -54
  261. data/test/controller/integration_upload_test.rb +0 -43
  262. data/test/controller/session_fixation_test.rb +0 -89
  263. data/test/controller/session_management_test.rb +0 -178
  264. data/test/fixtures/test/hello_world.js +0 -1
@@ -266,11 +266,18 @@ class FormTagHelperTest < ActionView::TestCase
266
266
 
267
267
  def test_submit_tag_with_confirmation
268
268
  assert_dom_equal(
269
- %(<input name='commit' type='submit' value='Save' onclick="return confirm('Are you sure?');"/>),
269
+ %(<input name='commit' type='submit' value='Save' onclick="if (!confirm('Are you sure?')) return false; return true;"/>),
270
270
  submit_tag("Save", :confirm => "Are you sure?")
271
271
  )
272
272
  end
273
-
273
+
274
+ def test_submit_tag_with_confirmation_and_with_disable_with
275
+ assert_dom_equal(
276
+ %(<input name="commit" type="submit" value="Save" onclick="if (!confirm('Are you sure?')) return false; if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }else { hiddenCommit = this.cloneNode(false);hiddenCommit.setAttribute('type', 'hidden');this.form.appendChild(hiddenCommit); }this.setAttribute('originalValue', this.value);this.disabled = true;this.value='Saving...';result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" />),
277
+ submit_tag("Save", :disable_with => "Saving...", :confirm => "Are you sure?")
278
+ )
279
+ end
280
+
274
281
  def test_image_submit_tag_with_confirmation
275
282
  assert_dom_equal(
276
283
  %(<input type="image" src="/images/save.gif" onclick="return confirm('Are you sure?');"/>),
@@ -45,11 +45,6 @@ class JavaScriptHelperTest < ActionView::TestCase
45
45
  link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/')
46
46
  end
47
47
 
48
- def test_link_to_function_with_href
49
- assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>),
50
- link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/')
51
- end
52
-
53
48
  def test_button_to_function
54
49
  assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />),
55
50
  button_to_function("Greeting", "alert('Hello world!')")
@@ -5,53 +5,65 @@ class NumberHelperI18nTests < Test::Unit::TestCase
5
5
 
6
6
  attr_reader :request
7
7
 
8
- uses_mocha 'number_helper_i18n_tests' do
9
- def setup
10
- @number_defaults = { :precision => 3, :delimiter => ',', :separator => '.' }
11
- @currency_defaults = { :unit => '$', :format => '%u%n', :precision => 2 }
12
- @human_defaults = { :precision => 1 }
13
- @human_storage_units_defaults = %w(Bytes KB MB GB TB)
14
- @percentage_defaults = { :delimiter => '' }
15
- @precision_defaults = { :delimiter => '' }
16
-
17
- I18n.backend.store_translations 'en', :number => { :format => @number_defaults,
18
- :currency => { :format => @currency_defaults }, :human => @human_defaults }
19
- end
20
-
21
- def test_number_to_currency_translates_currency_formats
22
- I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
23
- I18n.expects(:translate).with(:'number.currency.format', :locale => 'en',
24
- :raise => true).returns(@currency_defaults)
25
- number_to_currency(1, :locale => 'en')
26
- end
27
-
28
- def test_number_with_precision_translates_number_formats
29
- I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
30
- I18n.expects(:translate).with(:'number.precision.format', :locale => 'en',
31
- :raise => true).returns(@precision_defaults)
32
- number_with_precision(1, :locale => 'en')
33
- end
34
-
35
- def test_number_with_delimiter_translates_number_formats
36
- I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
37
- number_with_delimiter(1, :locale => 'en')
38
- end
39
-
40
- def test_number_to_percentage_translates_number_formats
41
- I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
42
- I18n.expects(:translate).with(:'number.percentage.format', :locale => 'en',
43
- :raise => true).returns(@percentage_defaults)
44
- number_to_percentage(1, :locale => 'en')
45
- end
46
-
47
- def test_number_to_human_size_translates_human_formats
48
- I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
49
- I18n.expects(:translate).with(:'number.human.format', :locale => 'en',
50
- :raise => true).returns(@human_defaults)
51
- I18n.expects(:translate).with(:'number.human.storage_units', :locale => 'en',
52
- :raise => true).returns(@human_storage_units_defaults)
53
- # can't be called with 1 because this directly returns without calling I18n.translate
54
- number_to_human_size(1025, :locale => 'en')
55
- end
8
+ def setup
9
+ @number_defaults = { :precision => 3, :delimiter => ',', :separator => '.' }
10
+ @currency_defaults = { :unit => '$', :format => '%u%n', :precision => 2 }
11
+ @human_defaults = { :precision => 1 }
12
+ @human_storage_units_format_default = "%n %u"
13
+ @human_storage_units_units_byte_other = "Bytes"
14
+ @human_storage_units_units_kb_other = "KB"
15
+ @percentage_defaults = { :delimiter => '' }
16
+ @precision_defaults = { :delimiter => '' }
17
+
18
+ I18n.backend.store_translations 'en', :number => { :format => @number_defaults,
19
+ :currency => { :format => @currency_defaults }, :human => @human_defaults }
20
+ end
21
+
22
+ def test_number_to_currency_translates_currency_formats
23
+ I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
24
+ I18n.expects(:translate).with(:'number.currency.format', :locale => 'en',
25
+ :raise => true).returns(@currency_defaults)
26
+ number_to_currency(1, :locale => 'en')
27
+ end
28
+
29
+ def test_number_with_precision_translates_number_formats
30
+ I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
31
+ I18n.expects(:translate).with(:'number.precision.format', :locale => 'en',
32
+ :raise => true).returns(@precision_defaults)
33
+ number_with_precision(1, :locale => 'en')
34
+ end
35
+
36
+ def test_number_with_delimiter_translates_number_formats
37
+ I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
38
+ number_with_delimiter(1, :locale => 'en')
39
+ end
40
+
41
+ def test_number_to_percentage_translates_number_formats
42
+ I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
43
+ I18n.expects(:translate).with(:'number.percentage.format', :locale => 'en',
44
+ :raise => true).returns(@percentage_defaults)
45
+ number_to_percentage(1, :locale => 'en')
46
+ end
47
+
48
+ def test_number_to_human_size_translates_human_formats
49
+ I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
50
+ I18n.expects(:translate).with(:'number.human.format', :locale => 'en',
51
+ :raise => true).returns(@human_defaults)
52
+ I18n.expects(:translate).with(:'number.human.storage_units.format', :locale => 'en',
53
+ :raise => true).returns(@human_storage_units_format_default)
54
+ I18n.expects(:translate).with(:'number.human.storage_units.units.kb', :locale => 'en', :count => 2,
55
+ :raise => true).returns(@human_storage_units_units_kb_other)
56
+ # 2KB
57
+ number_to_human_size(2048, :locale => 'en')
58
+
59
+ I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
60
+ I18n.expects(:translate).with(:'number.human.format', :locale => 'en',
61
+ :raise => true).returns(@human_defaults)
62
+ I18n.expects(:translate).with(:'number.human.storage_units.format', :locale => 'en',
63
+ :raise => true).returns(@human_storage_units_format_default)
64
+ I18n.expects(:translate).with(:'number.human.storage_units.units.byte', :locale => 'en', :count => 42,
65
+ :raise => true).returns(@human_storage_units_units_byte_other)
66
+ # 42 Bytes
67
+ number_to_human_size(42, :locale => 'en')
56
68
  end
57
69
  end
@@ -4,6 +4,7 @@ class NumberHelperTest < ActionView::TestCase
4
4
  tests ActionView::Helpers::NumberHelper
5
5
 
6
6
  def test_number_to_phone
7
+ assert_equal("555-1234", number_to_phone(5551234))
7
8
  assert_equal("800-555-1212", number_to_phone(8005551212))
8
9
  assert_equal("(800) 555-1212", number_to_phone(8005551212, {:area_code => true}))
9
10
  assert_equal("800 555 1212", number_to_phone(8005551212, {:delimiter => " "}))
@@ -1,16 +1,23 @@
1
+ # encoding: utf-8
1
2
  require 'abstract_unit'
2
3
  require 'controller/fake_models'
3
4
 
4
- class ViewRenderTest < Test::Unit::TestCase
5
- def setup
5
+ module RenderTestCases
6
+ def setup_view(paths)
6
7
  @assigns = { :secret => 'in the sauce' }
7
- @view = ActionView::Base.new(ActionController::Base.view_paths, @assigns)
8
+ @view = ActionView::Base.new(paths, @assigns)
9
+
10
+ # Reload and register danish language for testing
11
+ I18n.reload!
12
+ I18n.backend.store_translations 'da', {}
13
+ I18n.backend.store_translations 'pt-BR', {}
14
+
15
+ # Ensure original are still the same since we are reindexing view paths
16
+ assert_equal ORIGINAL_LOCALES, I18n.available_locales.map(&:to_s).sort
8
17
  end
9
18
 
10
19
  def test_render_file
11
- assert_deprecated do
12
- assert_equal "Hello world!", @view.render("test/hello_world.erb")
13
- end
20
+ assert_equal "Hello world!", @view.render(:file => "test/hello_world.erb")
14
21
  end
15
22
 
16
23
  def test_render_file_not_using_full_path
@@ -18,15 +25,46 @@ class ViewRenderTest < Test::Unit::TestCase
18
25
  end
19
26
 
20
27
  def test_render_file_without_specific_extension
21
- assert_deprecated do
22
- assert_equal "Hello world!", @view.render("test/hello_world")
23
- end
28
+ assert_equal "Hello world!", @view.render(:file => "test/hello_world")
29
+ end
30
+
31
+ def test_render_file_with_localization
32
+ old_locale = I18n.locale
33
+ I18n.locale = :da
34
+ assert_equal "Hey verden", @view.render(:file => "test/hello_world")
35
+ ensure
36
+ I18n.locale = old_locale
37
+ end
38
+
39
+ def test_render_file_with_dashed_locale
40
+ old_locale = I18n.locale
41
+ I18n.locale = :"pt-BR"
42
+ assert_equal "Ola mundo", @view.render(:file => "test/hello_world")
43
+ ensure
44
+ I18n.locale = old_locale
45
+ end
46
+
47
+ def test_render_implicit_html_template_from_xhr_request
48
+ old_format = @view.template_format
49
+ @view.template_format = :js
50
+ assert_equal "Hello HTML!", @view.render(:file => "test/render_implicit_html_template_from_xhr_request")
51
+ ensure
52
+ @view.template_format = old_format
53
+ end
54
+
55
+ def test_render_implicit_html_template_from_xhr_request_with_localization
56
+ old_locale = I18n.locale
57
+ old_format = @view.template_format
58
+ I18n.locale = :da
59
+ @view.template_format = :js
60
+ assert_equal "Hey HTML!\n", @view.render(:file => "test/render_implicit_html_template_from_xhr_request")
61
+ ensure
62
+ I18n.locale = old_locale
63
+ @view.template_format = old_format
24
64
  end
25
65
 
26
66
  def test_render_file_at_top_level
27
- assert_deprecated do
28
- assert_equal 'Elastica', @view.render('/shared')
29
- end
67
+ assert_equal 'Elastica', @view.render(:file => '/shared')
30
68
  end
31
69
 
32
70
  def test_render_file_with_full_path
@@ -34,33 +72,21 @@ class ViewRenderTest < Test::Unit::TestCase
34
72
  assert_equal "Hello world!", @view.render(:file => template_path)
35
73
  end
36
74
 
37
- def test_render_file_not_using_template_handler_extension
38
- assert_equal "var greeting = 'Hallo World!';", @view.render(:file => 'test/hello_world.js')
39
- end
40
-
41
75
  def test_render_file_with_instance_variables
42
- assert_deprecated do
43
- assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_ivar.erb")
44
- end
76
+ assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_ivar.erb")
45
77
  end
46
78
 
47
79
  def test_render_file_with_locals
48
80
  locals = { :secret => 'in the sauce' }
49
- assert_deprecated do
50
- assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_locals.erb", locals)
51
- end
81
+ assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_locals.erb", :locals => locals)
52
82
  end
53
83
 
54
84
  def test_render_file_not_using_full_path_with_dot_in_path
55
- assert_deprecated do
56
- assert_equal "The secret is in the sauce\n", @view.render("test/dot.directory/render_file_with_ivar")
57
- end
85
+ assert_equal "The secret is in the sauce\n", @view.render(:file => "test/dot.directory/render_file_with_ivar")
58
86
  end
59
87
 
60
88
  def test_render_has_access_current_template
61
- assert_deprecated do
62
- assert_equal "test/template.erb", @view.render("test/template.erb")
63
- end
89
+ assert_equal "test/template.erb", @view.render(:file => "test/template.erb")
64
90
  end
65
91
 
66
92
  def test_render_update
@@ -69,6 +95,10 @@ class ViewRenderTest < Test::Unit::TestCase
69
95
  assert_equal 'alert("Hello, World!");', @view.render(:update) { |page| page.alert('Hello, World!') }
70
96
  end
71
97
 
98
+ def test_render_partial_from_default
99
+ assert_equal "only partial", @view.render("test/partial_only")
100
+ end
101
+
72
102
  def test_render_partial
73
103
  assert_equal "only partial", @view.render(:partial => "test/partial_only")
74
104
  end
@@ -91,6 +121,10 @@ class ViewRenderTest < Test::Unit::TestCase
91
121
  assert_equal "5", @view.render(:partial => "test/counter", :locals => { :counter_counter => 5 })
92
122
  end
93
123
 
124
+ def test_render_partial_with_locals_from_default
125
+ assert_equal "only partial", @view.render("test/partial_only", :counter_counter => 5)
126
+ end
127
+
94
128
  def test_render_partial_with_errors
95
129
  @view.render(:partial => "test/raise")
96
130
  flunk "Render did not raise TemplateError"
@@ -111,6 +145,10 @@ class ViewRenderTest < Test::Unit::TestCase
111
145
  assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name
112
146
  end
113
147
 
148
+ def test_render_object
149
+ assert_equal "Hello: david", @view.render(:partial => "test/customer", :object => Customer.new("david"))
150
+ end
151
+
114
152
  def test_render_partial_collection
115
153
  assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ])
116
154
  end
@@ -146,12 +184,6 @@ class ViewRenderTest < Test::Unit::TestCase
146
184
  assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" })
147
185
  end
148
186
 
149
- # TODO: The reason for this test is unclear, improve documentation
150
- def test_render_js_partial_and_fallback_to_erb_layout
151
- @view.template_format = :js
152
- assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" })
153
- end
154
-
155
187
  # TODO: The reason for this test is unclear, improve documentation
156
188
  def test_render_missing_xml_partial_and_raise_missing_template
157
189
  @view.template_format = :xml
@@ -167,7 +199,7 @@ class ViewRenderTest < Test::Unit::TestCase
167
199
  end
168
200
 
169
201
  def test_render_fallbacks_to_erb_for_unknown_types
170
- assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :foo)
202
+ assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :bar)
171
203
  end
172
204
 
173
205
  CustomHandler = lambda do |template|
@@ -196,6 +228,16 @@ class ViewRenderTest < Test::Unit::TestCase
196
228
  assert_equal 'source: Hello, <%= name %>!; locals: {:name=>"Josh"}', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
197
229
  end
198
230
 
231
+ def test_render_ignores_templates_with_malformed_template_handlers
232
+ %w(malformed malformed.erb malformed.html.erb malformed.en.html.erb).each do |name|
233
+ assert_raise(ActionView::MissingTemplate) { @view.render(:file => "test/malformed/#{name}") }
234
+ end
235
+ end
236
+
237
+ def test_template_with_malformed_template_handler_is_reachable_through_its_exact_filename
238
+ assert_equal "Don't render me!", @view.render(:file => 'test/malformed/malformed.html.erb~')
239
+ end
240
+
199
241
  def test_render_with_layout
200
242
  assert_equal %(<title></title>\nHello world!\n),
201
243
  @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield")
@@ -205,4 +247,44 @@ class ViewRenderTest < Test::Unit::TestCase
205
247
  assert_equal %(<title>title</title>\n<div id="column">column</div>\n<div id="content">content</div>\n),
206
248
  @view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield")
207
249
  end
250
+
251
+ if '1.9'.respond_to?(:force_encoding)
252
+ def test_render_utf8_template
253
+ result = @view.render(:file => "test/utf8.html.erb", :layouts => "layouts/yield")
254
+ assert_equal "Русский текст\n日本語のテキスト", result
255
+ assert_equal Encoding::UTF_8, result.encoding
256
+ end
257
+ end
258
+ end
259
+
260
+ module TemplatesSetupTeardown
261
+ def setup_view_paths_for(new_cache_template_loading)
262
+ @previous_cache_template_loading, ActionView::Base.cache_template_loading = ActionView::Base.cache_template_loading, new_cache_template_loading
263
+ view_paths = new_cache_template_loading ? CACHED_VIEW_PATHS : ActionView::Base.process_view_paths(CACHED_VIEW_PATHS.map(&:to_s))
264
+ assert_equal(new_cache_template_loading ? ActionView::Template::EagerPath : ActionView::ReloadableTemplate::ReloadablePath, view_paths.first.class)
265
+ setup_view(view_paths)
266
+ end
267
+
268
+ def teardown
269
+ ActionView::Base.cache_template_loading = @previous_cache_template_loading
270
+ end
271
+ end
272
+
273
+ class CachedRenderTest < Test::Unit::TestCase
274
+ include TemplatesSetupTeardown
275
+ include RenderTestCases
276
+
277
+ def setup
278
+ setup_view_paths_for(cache_templates = true)
279
+ end
208
280
  end
281
+
282
+ class ReloadableRenderTest < Test::Unit::TestCase
283
+ include TemplatesSetupTeardown
284
+ include RenderTestCases
285
+
286
+ def setup
287
+ setup_view_paths_for(cache_templates = false)
288
+ end
289
+ end
290
+
@@ -38,12 +38,10 @@ class PeopleHelperTest < ActionView::TestCase
38
38
  assert_equal "http://test.host/people", homepage_url
39
39
  end
40
40
 
41
- uses_mocha "link_to_person" do
42
- def test_link_to_person
43
- person = mock(:name => "David")
44
- expects(:mocha_mock_path).with(person).returns("/people/1")
45
- assert_equal '<a href="/people/1">David</a>', link_to_person(person)
46
- end
41
+ def test_link_to_person
42
+ person = mock(:name => "David")
43
+ expects(:mocha_mock_path).with(person).returns("/people/1")
44
+ assert_equal '<a href="/people/1">David</a>', link_to_person(person)
47
45
  end
48
46
  end
49
47
 
@@ -122,6 +122,29 @@ class TextHelperTest < ActionView::TestCase
122
122
  )
123
123
  end
124
124
 
125
+ def test_highlight_with_html
126
+ assert_equal(
127
+ "<p>This is a <strong class=\"highlight\">beautiful</strong> morning, but also a <strong class=\"highlight\">beautiful</strong> day</p>",
128
+ highlight("<p>This is a beautiful morning, but also a beautiful day</p>", "beautiful")
129
+ )
130
+ assert_equal(
131
+ "<p>This is a <em><strong class=\"highlight\">beautiful</strong></em> morning, but also a <strong class=\"highlight\">beautiful</strong> day</p>",
132
+ highlight("<p>This is a <em>beautiful</em> morning, but also a beautiful day</p>", "beautiful")
133
+ )
134
+ assert_equal(
135
+ "<p>This is a <em class=\"error\"><strong class=\"highlight\">beautiful</strong></em> morning, but also a <strong class=\"highlight\">beautiful</strong> <span class=\"last\">day</span></p>",
136
+ highlight("<p>This is a <em class=\"error\">beautiful</em> morning, but also a beautiful <span class=\"last\">day</span></p>", "beautiful")
137
+ )
138
+ assert_equal(
139
+ "<p class=\"beautiful\">This is a <strong class=\"highlight\">beautiful</strong> morning, but also a <strong class=\"highlight\">beautiful</strong> day</p>",
140
+ highlight("<p class=\"beautiful\">This is a beautiful morning, but also a beautiful day</p>", "beautiful")
141
+ )
142
+ assert_equal(
143
+ "<p>This is a <strong class=\"highlight\">beautiful</strong> <a href=\"http://example.com/beautiful\#top?what=beautiful%20morning&when=now+then\">morning</a>, but also a <strong class=\"highlight\">beautiful</strong> day</p>",
144
+ highlight("<p>This is a beautiful <a href=\"http://example.com/beautiful\#top?what=beautiful%20morning&when=now+then\">morning</a>, but also a beautiful day</p>", "beautiful")
145
+ )
146
+ end
147
+
125
148
  def test_excerpt
126
149
  assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", 5))
127
150
  assert_equal("This is a...", excerpt("This is a beautiful morning", "this", 5))
@@ -205,56 +228,48 @@ class TextHelperTest < ActionView::TestCase
205
228
  end
206
229
 
207
230
  def test_auto_link_parsing
208
- urls = %w(http://www.rubyonrails.com
209
- http://www.rubyonrails.com:80
210
- http://www.rubyonrails.com/~minam
211
- https://www.rubyonrails.com/~minam
212
- http://www.rubyonrails.com/~minam/url%20with%20spaces
213
- http://www.rubyonrails.com/foo.cgi?something=here
214
- http://www.rubyonrails.com/foo.cgi?something=here&and=here
215
- http://www.rubyonrails.com/contact;new
216
- http://www.rubyonrails.com/contact;new%20with%20spaces
217
- http://www.rubyonrails.com/contact;new?with=query&string=params
218
- http://www.rubyonrails.com/~minam/contact;new?with=query&string=params
219
- http://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_picture_%28animation%29/January_20%2C_2007
220
- http://www.mail-archive.com/rails@lists.rubyonrails.org/
221
- http://www.amazon.com/Testing-Equal-Sign-In-Path/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1198861734&sr=8-1
222
- http://en.wikipedia.org/wiki/Sprite_(computer_graphics)
223
- http://en.wikipedia.org/wiki/Texas_hold'em
224
- https://www.google.com/doku.php?id=gps:resource:scs:start
225
- )
231
+ urls = %w(
232
+ http://www.rubyonrails.com
233
+ http://www.rubyonrails.com:80
234
+ http://www.rubyonrails.com/~minam
235
+ https://www.rubyonrails.com/~minam
236
+ http://www.rubyonrails.com/~minam/url%20with%20spaces
237
+ http://www.rubyonrails.com/foo.cgi?something=here
238
+ http://www.rubyonrails.com/foo.cgi?something=here&and=here
239
+ http://www.rubyonrails.com/contact;new
240
+ http://www.rubyonrails.com/contact;new%20with%20spaces
241
+ http://www.rubyonrails.com/contact;new?with=query&string=params
242
+ http://www.rubyonrails.com/~minam/contact;new?with=query&string=params
243
+ http://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_picture_%28animation%29/January_20%2C_2007
244
+ http://www.mail-archive.com/rails@lists.rubyonrails.org/
245
+ http://www.amazon.com/Testing-Equal-Sign-In-Path/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1198861734&sr=8-1
246
+ http://en.wikipedia.org/wiki/Texas_hold'em
247
+ https://www.google.com/doku.php?id=gps:resource:scs:start
248
+ http://connect.oraclecorp.com/search?search[q]=green+france&search[type]=Group
249
+ http://of.openfoundry.org/projects/492/download#4th.Release.3
250
+ http://maps.google.co.uk/maps?f=q&q=the+london+eye&ie=UTF8&ll=51.503373,-0.11939&spn=0.007052,0.012767&z=16&iwloc=A
251
+ )
226
252
 
227
253
  urls.each do |url|
228
- assert_equal %(<a href="#{url}">#{url}</a>), auto_link(url)
254
+ assert_equal generate_result(url), auto_link(url)
229
255
  end
230
256
  end
231
257
 
258
+ def generate_result(link_text, href = nil)
259
+ href ||= link_text
260
+ %{<a href="#{CGI::escapeHTML href}">#{CGI::escapeHTML link_text}</a>}
261
+ end
262
+
232
263
  def test_auto_linking
233
264
  email_raw = 'david@loudthinking.com'
234
265
  email_result = %{<a href="mailto:#{email_raw}">#{email_raw}</a>}
235
- email2_raw = '+david@loudthinking.com'
236
- email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>}
237
266
  link_raw = 'http://www.rubyonrails.com'
238
- link_result = %{<a href="#{link_raw}">#{link_raw}</a>}
239
- link_result_with_options = %{<a href="#{link_raw}" target="_blank">#{link_raw}</a>}
240
- link2_raw = 'www.rubyonrails.com'
241
- link2_result = %{<a href="http://#{link2_raw}">#{link2_raw}</a>}
242
- link3_raw = 'http://manuals.ruby-on-rails.com/read/chapter.need_a-period/103#page281'
243
- link3_result = %{<a href="#{link3_raw}">#{link3_raw}</a>}
244
- link4_raw = 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor123'
245
- link4_result = %{<a href="#{link4_raw}">#{link4_raw}</a>}
246
- link5_raw = 'http://foo.example.com:3000/controller/action'
247
- link5_result = %{<a href="#{link5_raw}">#{link5_raw}</a>}
248
- link6_raw = 'http://foo.example.com:3000/controller/action+pack'
249
- link6_result = %{<a href="#{link6_raw}">#{link6_raw}</a>}
250
- link7_raw = 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor-123'
251
- link7_result = %{<a href="#{link7_raw}">#{link7_raw}</a>}
252
- link8_raw = 'http://foo.example.com:3000/controller/action.html'
253
- link8_result = %{<a href="#{link8_raw}">#{link8_raw}</a>}
254
- link9_raw = 'http://business.timesonline.co.uk/article/0,,9065-2473189,00.html'
255
- link9_result = %{<a href="#{link9_raw}">#{link9_raw}</a>}
256
- link10_raw = 'http://www.mail-archive.com/ruby-talk@ruby-lang.org/'
257
- link10_result = %{<a href="#{link10_raw}">#{link10_raw}</a>}
267
+ link_result = generate_result(link_raw)
268
+ link_result_with_options = %{<a href="#{link_raw}" target="_blank">#{link_raw}</a>}
269
+
270
+ assert_equal '', auto_link(nil)
271
+ assert_equal '', auto_link('')
272
+ assert_equal "#{link_result} #{link_result} #{link_result}", auto_link("#{link_raw} #{link_raw} #{link_raw}")
258
273
 
259
274
  assert_equal %(hello #{email_result}), auto_link("hello #{email_raw}", :email_addresses)
260
275
  assert_equal %(Go to #{link_result}), auto_link("Go to #{link_raw}", :urls)
@@ -265,41 +280,105 @@ class TextHelperTest < ActionView::TestCase
265
280
  assert_equal %(<p>Link #{link_result_with_options}</p>), auto_link("<p>Link #{link_raw}</p>", :all, {:target => "_blank"})
266
281
  assert_equal %(Go to #{link_result}.), auto_link(%(Go to #{link_raw}.))
267
282
  assert_equal %(<p>Go to #{link_result}, then say hello to #{email_result}.</p>), auto_link(%(<p>Go to #{link_raw}, then say hello to #{email_raw}.</p>))
283
+
284
+ email2_raw = '+david@loudthinking.com'
285
+ email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>}
286
+ assert_equal email2_result, auto_link(email2_raw)
287
+
288
+ email3_raw = '+david@loudthinking.com'
289
+ email3_result = %{<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;+%64%61%76%69%64@%6c%6f%75%64%74%68%69%6e%6b%69%6e%67.%63%6f%6d">#{email3_raw}</a>}
290
+ assert_equal email3_result, auto_link(email3_raw, :all, :encode => :hex)
291
+ assert_equal email3_result, auto_link(email3_raw, :email_addresses, :encode => :hex)
292
+
293
+ link2_raw = 'www.rubyonrails.com'
294
+ link2_result = generate_result(link2_raw, "http://#{link2_raw}")
268
295
  assert_equal %(Go to #{link2_result}), auto_link("Go to #{link2_raw}", :urls)
269
296
  assert_equal %(Go to #{link2_raw}), auto_link("Go to #{link2_raw}", :email_addresses)
270
297
  assert_equal %(<p>Link #{link2_result}</p>), auto_link("<p>Link #{link2_raw}</p>")
271
298
  assert_equal %(<p>#{link2_result} Link</p>), auto_link("<p>#{link2_raw} Link</p>")
272
299
  assert_equal %(Go to #{link2_result}.), auto_link(%(Go to #{link2_raw}.))
273
300
  assert_equal %(<p>Say hello to #{email_result}, then go to #{link2_result}.</p>), auto_link(%(<p>Say hello to #{email_raw}, then go to #{link2_raw}.</p>))
301
+
302
+ link3_raw = 'http://manuals.ruby-on-rails.com/read/chapter.need_a-period/103#page281'
303
+ link3_result = generate_result(link3_raw)
274
304
  assert_equal %(Go to #{link3_result}), auto_link("Go to #{link3_raw}", :urls)
275
305
  assert_equal %(Go to #{link3_raw}), auto_link("Go to #{link3_raw}", :email_addresses)
276
306
  assert_equal %(<p>Link #{link3_result}</p>), auto_link("<p>Link #{link3_raw}</p>")
277
307
  assert_equal %(<p>#{link3_result} Link</p>), auto_link("<p>#{link3_raw} Link</p>")
278
308
  assert_equal %(Go to #{link3_result}.), auto_link(%(Go to #{link3_raw}.))
279
- assert_equal %(<p>Go to #{link3_result}. seriously, #{link3_result}? i think I'll say hello to #{email_result}. instead.</p>), auto_link(%(<p>Go to #{link3_raw}. seriously, #{link3_raw}? i think I'll say hello to #{email_raw}. instead.</p>))
309
+ assert_equal %(<p>Go to #{link3_result}. Seriously, #{link3_result}? I think I'll say hello to #{email_result}. Instead.</p>),
310
+ auto_link(%(<p>Go to #{link3_raw}. Seriously, #{link3_raw}? I think I'll say hello to #{email_raw}. Instead.</p>))
311
+
312
+ link4_raw = 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor123'
313
+ link4_result = generate_result(link4_raw)
280
314
  assert_equal %(<p>Link #{link4_result}</p>), auto_link("<p>Link #{link4_raw}</p>")
281
315
  assert_equal %(<p>#{link4_result} Link</p>), auto_link("<p>#{link4_raw} Link</p>")
316
+
317
+ link5_raw = 'http://foo.example.com:3000/controller/action'
318
+ link5_result = generate_result(link5_raw)
282
319
  assert_equal %(<p>#{link5_result} Link</p>), auto_link("<p>#{link5_raw} Link</p>")
320
+
321
+ link6_raw = 'http://foo.example.com:3000/controller/action+pack'
322
+ link6_result = generate_result(link6_raw)
283
323
  assert_equal %(<p>#{link6_result} Link</p>), auto_link("<p>#{link6_raw} Link</p>")
324
+
325
+ link7_raw = 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor-123'
326
+ link7_result = generate_result(link7_raw)
284
327
  assert_equal %(<p>#{link7_result} Link</p>), auto_link("<p>#{link7_raw} Link</p>")
328
+
329
+ link8_raw = 'http://foo.example.com:3000/controller/action.html'
330
+ link8_result = generate_result(link8_raw)
285
331
  assert_equal %(Go to #{link8_result}), auto_link("Go to #{link8_raw}", :urls)
286
332
  assert_equal %(Go to #{link8_raw}), auto_link("Go to #{link8_raw}", :email_addresses)
287
333
  assert_equal %(<p>Link #{link8_result}</p>), auto_link("<p>Link #{link8_raw}</p>")
288
334
  assert_equal %(<p>#{link8_result} Link</p>), auto_link("<p>#{link8_raw} Link</p>")
289
335
  assert_equal %(Go to #{link8_result}.), auto_link(%(Go to #{link8_raw}.))
290
- assert_equal %(<p>Go to #{link8_result}. seriously, #{link8_result}? i think I'll say hello to #{email_result}. instead.</p>), auto_link(%(<p>Go to #{link8_raw}. seriously, #{link8_raw}? i think I'll say hello to #{email_raw}. instead.</p>))
336
+ assert_equal %(<p>Go to #{link8_result}. Seriously, #{link8_result}? I think I'll say hello to #{email_result}. Instead.</p>),
337
+ auto_link(%(<p>Go to #{link8_raw}. Seriously, #{link8_raw}? I think I'll say hello to #{email_raw}. Instead.</p>))
338
+
339
+ link9_raw = 'http://business.timesonline.co.uk/article/0,,9065-2473189,00.html'
340
+ link9_result = generate_result(link9_raw)
291
341
  assert_equal %(Go to #{link9_result}), auto_link("Go to #{link9_raw}", :urls)
292
342
  assert_equal %(Go to #{link9_raw}), auto_link("Go to #{link9_raw}", :email_addresses)
293
343
  assert_equal %(<p>Link #{link9_result}</p>), auto_link("<p>Link #{link9_raw}</p>")
294
344
  assert_equal %(<p>#{link9_result} Link</p>), auto_link("<p>#{link9_raw} Link</p>")
295
345
  assert_equal %(Go to #{link9_result}.), auto_link(%(Go to #{link9_raw}.))
296
- assert_equal %(<p>Go to #{link9_result}. seriously, #{link9_result}? i think I'll say hello to #{email_result}. instead.</p>), auto_link(%(<p>Go to #{link9_raw}. seriously, #{link9_raw}? i think I'll say hello to #{email_raw}. instead.</p>))
346
+ assert_equal %(<p>Go to #{link9_result}. Seriously, #{link9_result}? I think I'll say hello to #{email_result}. Instead.</p>),
347
+ auto_link(%(<p>Go to #{link9_raw}. Seriously, #{link9_raw}? I think I'll say hello to #{email_raw}. Instead.</p>))
348
+
349
+ link10_raw = 'http://www.mail-archive.com/ruby-talk@ruby-lang.org/'
350
+ link10_result = generate_result(link10_raw)
297
351
  assert_equal %(<p>#{link10_result} Link</p>), auto_link("<p>#{link10_raw} Link</p>")
298
- assert_equal email2_result, auto_link(email2_raw)
299
- assert_equal '', auto_link(nil)
300
- assert_equal '', auto_link('')
301
- assert_equal "#{link_result} #{link_result} #{link_result}", auto_link("#{link_raw} #{link_raw} #{link_raw}")
302
- assert_equal '<a href="http://www.rubyonrails.com">Ruby On Rails</a>', auto_link('<a href="http://www.rubyonrails.com">Ruby On Rails</a>')
352
+ end
353
+
354
+ def test_auto_link_already_linked
355
+ linked1 = generate_result('Ruby On Rails', 'http://www.rubyonrails.com')
356
+ linked2 = generate_result('www.rubyonrails.com', 'http://www.rubyonrails.com')
357
+ assert_equal linked1, auto_link(linked1)
358
+ assert_equal linked2, auto_link(linked2)
359
+ end
360
+
361
+ def test_auto_link_with_brackets
362
+ link1_raw = 'http://en.wikipedia.org/wiki/Sprite_(computer_graphics)'
363
+ link1_result = generate_result(link1_raw)
364
+ assert_equal link1_result, auto_link(link1_raw)
365
+ assert_equal "(link: #{link1_result})", auto_link("(link: #{link1_raw})")
366
+
367
+ link2_raw = 'http://en.wikipedia.org/wiki/Sprite_[computer_graphics]'
368
+ link2_result = generate_result(link2_raw)
369
+ assert_equal link2_result, auto_link(link2_raw)
370
+ assert_equal "[link: #{link2_result}]", auto_link("[link: #{link2_raw}]")
371
+
372
+ link3_raw = 'http://en.wikipedia.org/wiki/Sprite_{computer_graphics}'
373
+ link3_result = generate_result(link3_raw)
374
+ assert_equal link3_result, auto_link(link3_raw)
375
+ assert_equal "{link: #{link3_result}}", auto_link("{link: #{link3_raw}}")
376
+ end
377
+
378
+ def test_auto_link_in_tags
379
+ link_raw = 'http://www.rubyonrails.org/images/rails.png'
380
+ link_result = %Q(<img src="#{link_raw}" />)
381
+ assert_equal link_result, auto_link(link_result)
303
382
  end
304
383
 
305
384
  def test_auto_link_at_eol
@@ -317,7 +396,7 @@ class TextHelperTest < ActionView::TestCase
317
396
  end
318
397
 
319
398
  def test_auto_link_with_options_hash
320
- assert_equal 'Welcome to my new blog at <a href="http://www.myblog.com/" class="menu" target="_blank">http://www.myblog.com/</a>. Please e-mail me at <a href="mailto:me@email.com">me@email.com</a>.',
399
+ assert_dom_equal 'Welcome to my new blog at <a href="http://www.myblog.com/" class="menu" target="_blank">http://www.myblog.com/</a>. Please e-mail me at <a href="mailto:me@email.com" class="menu" target="_blank">me@email.com</a>.',
321
400
  auto_link("Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.",
322
401
  :link => :all, :html => { :class => "menu", :target => "_blank" })
323
402
  end