actionpack 3.2.22.5 → 5.2.4

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 (271) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +279 -603
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +13 -297
  5. data/lib/abstract_controller/asset_paths.rb +4 -2
  6. data/lib/abstract_controller/base.rb +82 -52
  7. data/lib/abstract_controller/caching/fragments.rb +166 -0
  8. data/lib/abstract_controller/caching.rb +66 -0
  9. data/lib/abstract_controller/callbacks.rb +117 -103
  10. data/lib/abstract_controller/collector.rb +18 -7
  11. data/lib/abstract_controller/error.rb +6 -0
  12. data/lib/abstract_controller/helpers.rb +65 -38
  13. data/lib/abstract_controller/logger.rb +3 -2
  14. data/lib/abstract_controller/railties/routes_helpers.rb +5 -3
  15. data/lib/abstract_controller/rendering.rb +77 -129
  16. data/lib/abstract_controller/translation.rb +21 -3
  17. data/lib/abstract_controller/url_for.rb +9 -7
  18. data/lib/abstract_controller.rb +12 -13
  19. data/lib/action_controller/api/api_rendering.rb +16 -0
  20. data/lib/action_controller/api.rb +149 -0
  21. data/lib/action_controller/base.rb +81 -40
  22. data/lib/action_controller/caching.rb +22 -62
  23. data/lib/action_controller/form_builder.rb +50 -0
  24. data/lib/action_controller/log_subscriber.rb +30 -18
  25. data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
  26. data/lib/action_controller/metal/conditional_get.rb +190 -47
  27. data/lib/action_controller/metal/content_security_policy.rb +52 -0
  28. data/lib/action_controller/metal/cookies.rb +3 -3
  29. data/lib/action_controller/metal/data_streaming.rb +40 -65
  30. data/lib/action_controller/metal/etag_with_flash.rb +18 -0
  31. data/lib/action_controller/metal/etag_with_template_digest.rb +57 -0
  32. data/lib/action_controller/metal/exceptions.rb +19 -12
  33. data/lib/action_controller/metal/flash.rb +42 -9
  34. data/lib/action_controller/metal/force_ssl.rb +79 -19
  35. data/lib/action_controller/metal/head.rb +35 -10
  36. data/lib/action_controller/metal/helpers.rb +31 -21
  37. data/lib/action_controller/metal/http_authentication.rb +182 -134
  38. data/lib/action_controller/metal/implicit_render.rb +62 -8
  39. data/lib/action_controller/metal/instrumentation.rb +28 -26
  40. data/lib/action_controller/metal/live.rb +312 -0
  41. data/lib/action_controller/metal/mime_responds.rb +159 -163
  42. data/lib/action_controller/metal/parameter_encoding.rb +51 -0
  43. data/lib/action_controller/metal/params_wrapper.rb +146 -93
  44. data/lib/action_controller/metal/redirecting.rb +80 -56
  45. data/lib/action_controller/metal/renderers.rb +119 -47
  46. data/lib/action_controller/metal/rendering.rb +89 -32
  47. data/lib/action_controller/metal/request_forgery_protection.rb +373 -41
  48. data/lib/action_controller/metal/rescue.rb +9 -16
  49. data/lib/action_controller/metal/streaming.rb +39 -45
  50. data/lib/action_controller/metal/strong_parameters.rb +1086 -0
  51. data/lib/action_controller/metal/testing.rb +8 -29
  52. data/lib/action_controller/metal/url_for.rb +43 -32
  53. data/lib/action_controller/metal.rb +112 -106
  54. data/lib/action_controller/railtie.rb +56 -18
  55. data/lib/action_controller/railties/helpers.rb +24 -0
  56. data/lib/action_controller/renderer.rb +117 -0
  57. data/lib/action_controller/template_assertions.rb +11 -0
  58. data/lib/action_controller/test_case.rb +402 -347
  59. data/lib/action_controller.rb +31 -30
  60. data/lib/action_dispatch/http/cache.rb +133 -34
  61. data/lib/action_dispatch/http/content_security_policy.rb +272 -0
  62. data/lib/action_dispatch/http/filter_parameters.rb +40 -24
  63. data/lib/action_dispatch/http/filter_redirect.rb +37 -0
  64. data/lib/action_dispatch/http/headers.rb +117 -16
  65. data/lib/action_dispatch/http/mime_negotiation.rb +98 -33
  66. data/lib/action_dispatch/http/mime_type.rb +198 -146
  67. data/lib/action_dispatch/http/mime_types.rb +22 -7
  68. data/lib/action_dispatch/http/parameter_filter.rb +61 -49
  69. data/lib/action_dispatch/http/parameters.rb +94 -51
  70. data/lib/action_dispatch/http/rack_cache.rb +4 -3
  71. data/lib/action_dispatch/http/request.rb +262 -117
  72. data/lib/action_dispatch/http/response.rb +400 -86
  73. data/lib/action_dispatch/http/upload.rb +66 -29
  74. data/lib/action_dispatch/http/url.rb +232 -60
  75. data/lib/action_dispatch/journey/formatter.rb +189 -0
  76. data/lib/action_dispatch/journey/gtg/builder.rb +164 -0
  77. data/lib/action_dispatch/journey/gtg/simulator.rb +41 -0
  78. data/lib/action_dispatch/journey/gtg/transition_table.rb +158 -0
  79. data/lib/action_dispatch/journey/nfa/builder.rb +78 -0
  80. data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
  81. data/lib/action_dispatch/journey/nfa/simulator.rb +49 -0
  82. data/lib/action_dispatch/journey/nfa/transition_table.rb +120 -0
  83. data/lib/action_dispatch/journey/nodes/node.rb +140 -0
  84. data/lib/action_dispatch/journey/parser.rb +199 -0
  85. data/lib/action_dispatch/journey/parser.y +50 -0
  86. data/lib/action_dispatch/journey/parser_extras.rb +31 -0
  87. data/lib/action_dispatch/journey/path/pattern.rb +199 -0
  88. data/lib/action_dispatch/journey/route.rb +203 -0
  89. data/lib/action_dispatch/journey/router/utils.rb +102 -0
  90. data/lib/action_dispatch/journey/router.rb +156 -0
  91. data/lib/action_dispatch/journey/routes.rb +82 -0
  92. data/lib/action_dispatch/journey/scanner.rb +64 -0
  93. data/lib/action_dispatch/journey/visitors.rb +268 -0
  94. data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
  95. data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
  96. data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
  97. data/lib/action_dispatch/journey.rb +7 -0
  98. data/lib/action_dispatch/middleware/callbacks.rb +17 -13
  99. data/lib/action_dispatch/middleware/cookies.rb +494 -162
  100. data/lib/action_dispatch/middleware/debug_exceptions.rb +176 -53
  101. data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
  102. data/lib/action_dispatch/middleware/exception_wrapper.rb +103 -38
  103. data/lib/action_dispatch/middleware/executor.rb +21 -0
  104. data/lib/action_dispatch/middleware/flash.rb +128 -91
  105. data/lib/action_dispatch/middleware/public_exceptions.rb +43 -16
  106. data/lib/action_dispatch/middleware/reloader.rb +6 -83
  107. data/lib/action_dispatch/middleware/remote_ip.rb +151 -49
  108. data/lib/action_dispatch/middleware/request_id.rb +19 -15
  109. data/lib/action_dispatch/middleware/session/abstract_store.rb +38 -34
  110. data/lib/action_dispatch/middleware/session/cache_store.rb +14 -9
  111. data/lib/action_dispatch/middleware/session/cookie_store.rb +94 -44
  112. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +15 -4
  113. data/lib/action_dispatch/middleware/show_exceptions.rb +36 -61
  114. data/lib/action_dispatch/middleware/ssl.rb +150 -0
  115. data/lib/action_dispatch/middleware/stack.rb +33 -41
  116. data/lib/action_dispatch/middleware/static.rb +92 -48
  117. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +22 -0
  118. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  119. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +27 -0
  120. data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
  121. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
  122. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
  123. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +16 -0
  124. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  125. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +21 -0
  126. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +13 -0
  127. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +134 -5
  128. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
  129. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  130. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
  131. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  132. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
  133. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
  134. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
  135. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  136. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
  137. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
  138. data/lib/action_dispatch/railtie.rb +29 -8
  139. data/lib/action_dispatch/request/session.rb +234 -0
  140. data/lib/action_dispatch/request/utils.rb +78 -0
  141. data/lib/action_dispatch/routing/endpoint.rb +17 -0
  142. data/lib/action_dispatch/routing/inspector.rb +225 -0
  143. data/lib/action_dispatch/routing/mapper.rb +1329 -582
  144. data/lib/action_dispatch/routing/polymorphic_routes.rb +237 -94
  145. data/lib/action_dispatch/routing/redirection.rb +120 -50
  146. data/lib/action_dispatch/routing/route_set.rb +545 -322
  147. data/lib/action_dispatch/routing/routes_proxy.rb +37 -7
  148. data/lib/action_dispatch/routing/url_for.rb +103 -34
  149. data/lib/action_dispatch/routing.rb +66 -99
  150. data/lib/action_dispatch/system_test_case.rb +147 -0
  151. data/lib/action_dispatch/system_testing/browser.rb +49 -0
  152. data/lib/action_dispatch/system_testing/driver.rb +59 -0
  153. data/lib/action_dispatch/system_testing/server.rb +31 -0
  154. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +96 -0
  155. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +31 -0
  156. data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
  157. data/lib/action_dispatch/testing/assertion_response.rb +47 -0
  158. data/lib/action_dispatch/testing/assertions/response.rb +53 -42
  159. data/lib/action_dispatch/testing/assertions/routing.rb +79 -74
  160. data/lib/action_dispatch/testing/assertions.rb +15 -9
  161. data/lib/action_dispatch/testing/integration.rb +361 -207
  162. data/lib/action_dispatch/testing/request_encoder.rb +55 -0
  163. data/lib/action_dispatch/testing/test_process.rb +28 -19
  164. data/lib/action_dispatch/testing/test_request.rb +30 -33
  165. data/lib/action_dispatch/testing/test_response.rb +35 -11
  166. data/lib/action_dispatch.rb +42 -32
  167. data/lib/action_pack/gem_version.rb +17 -0
  168. data/lib/action_pack/version.rb +7 -7
  169. data/lib/action_pack.rb +4 -2
  170. metadata +116 -175
  171. data/lib/abstract_controller/layouts.rb +0 -423
  172. data/lib/abstract_controller/view_paths.rb +0 -96
  173. data/lib/action_controller/caching/actions.rb +0 -185
  174. data/lib/action_controller/caching/fragments.rb +0 -127
  175. data/lib/action_controller/caching/pages.rb +0 -187
  176. data/lib/action_controller/caching/sweeping.rb +0 -97
  177. data/lib/action_controller/deprecated/integration_test.rb +0 -2
  178. data/lib/action_controller/deprecated/performance_test.rb +0 -1
  179. data/lib/action_controller/deprecated.rb +0 -3
  180. data/lib/action_controller/metal/compatibility.rb +0 -65
  181. data/lib/action_controller/metal/hide_actions.rb +0 -41
  182. data/lib/action_controller/metal/rack_delegation.rb +0 -26
  183. data/lib/action_controller/metal/responder.rb +0 -286
  184. data/lib/action_controller/metal/session_management.rb +0 -14
  185. data/lib/action_controller/middleware.rb +0 -39
  186. data/lib/action_controller/railties/paths.rb +0 -25
  187. data/lib/action_controller/record_identifier.rb +0 -85
  188. data/lib/action_controller/vendor/html-scanner/html/document.rb +0 -68
  189. data/lib/action_controller/vendor/html-scanner/html/node.rb +0 -532
  190. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +0 -177
  191. data/lib/action_controller/vendor/html-scanner/html/selector.rb +0 -830
  192. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +0 -107
  193. data/lib/action_controller/vendor/html-scanner/html/version.rb +0 -11
  194. data/lib/action_controller/vendor/html-scanner.rb +0 -20
  195. data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
  196. data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
  197. data/lib/action_dispatch/middleware/head.rb +0 -18
  198. data/lib/action_dispatch/middleware/params_parser.rb +0 -75
  199. data/lib/action_dispatch/middleware/rescue.rb +0 -26
  200. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +0 -31
  201. data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -26
  202. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +0 -10
  203. data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -2
  204. data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +0 -15
  205. data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -17
  206. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +0 -2
  207. data/lib/action_dispatch/testing/assertions/dom.rb +0 -37
  208. data/lib/action_dispatch/testing/assertions/selector.rb +0 -435
  209. data/lib/action_dispatch/testing/assertions/tag.rb +0 -138
  210. data/lib/action_dispatch/testing/performance_test.rb +0 -10
  211. data/lib/action_view/asset_paths.rb +0 -142
  212. data/lib/action_view/base.rb +0 -220
  213. data/lib/action_view/buffers.rb +0 -43
  214. data/lib/action_view/context.rb +0 -36
  215. data/lib/action_view/flows.rb +0 -79
  216. data/lib/action_view/helpers/active_model_helper.rb +0 -50
  217. data/lib/action_view/helpers/asset_paths.rb +0 -7
  218. data/lib/action_view/helpers/asset_tag_helper.rb +0 -457
  219. data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
  220. data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
  221. data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
  222. data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
  223. data/lib/action_view/helpers/atom_feed_helper.rb +0 -200
  224. data/lib/action_view/helpers/cache_helper.rb +0 -64
  225. data/lib/action_view/helpers/capture_helper.rb +0 -203
  226. data/lib/action_view/helpers/controller_helper.rb +0 -25
  227. data/lib/action_view/helpers/csrf_helper.rb +0 -32
  228. data/lib/action_view/helpers/date_helper.rb +0 -1062
  229. data/lib/action_view/helpers/debug_helper.rb +0 -40
  230. data/lib/action_view/helpers/form_helper.rb +0 -1486
  231. data/lib/action_view/helpers/form_options_helper.rb +0 -658
  232. data/lib/action_view/helpers/form_tag_helper.rb +0 -685
  233. data/lib/action_view/helpers/javascript_helper.rb +0 -110
  234. data/lib/action_view/helpers/number_helper.rb +0 -622
  235. data/lib/action_view/helpers/output_safety_helper.rb +0 -38
  236. data/lib/action_view/helpers/record_tag_helper.rb +0 -111
  237. data/lib/action_view/helpers/rendering_helper.rb +0 -92
  238. data/lib/action_view/helpers/sanitize_helper.rb +0 -259
  239. data/lib/action_view/helpers/tag_helper.rb +0 -167
  240. data/lib/action_view/helpers/text_helper.rb +0 -426
  241. data/lib/action_view/helpers/translation_helper.rb +0 -91
  242. data/lib/action_view/helpers/url_helper.rb +0 -693
  243. data/lib/action_view/helpers.rb +0 -60
  244. data/lib/action_view/locale/en.yml +0 -160
  245. data/lib/action_view/log_subscriber.rb +0 -28
  246. data/lib/action_view/lookup_context.rb +0 -258
  247. data/lib/action_view/path_set.rb +0 -101
  248. data/lib/action_view/railtie.rb +0 -55
  249. data/lib/action_view/renderer/abstract_renderer.rb +0 -41
  250. data/lib/action_view/renderer/partial_renderer.rb +0 -415
  251. data/lib/action_view/renderer/renderer.rb +0 -61
  252. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
  253. data/lib/action_view/renderer/template_renderer.rb +0 -95
  254. data/lib/action_view/template/error.rb +0 -128
  255. data/lib/action_view/template/handlers/builder.rb +0 -26
  256. data/lib/action_view/template/handlers/erb.rb +0 -125
  257. data/lib/action_view/template/handlers.rb +0 -50
  258. data/lib/action_view/template/resolver.rb +0 -298
  259. data/lib/action_view/template/text.rb +0 -30
  260. data/lib/action_view/template.rb +0 -337
  261. data/lib/action_view/test_case.rb +0 -246
  262. data/lib/action_view/testing/resolvers.rb +0 -49
  263. data/lib/action_view.rb +0 -84
  264. data/lib/sprockets/assets.rake +0 -99
  265. data/lib/sprockets/bootstrap.rb +0 -37
  266. data/lib/sprockets/compressors.rb +0 -83
  267. data/lib/sprockets/helpers/isolated_helper.rb +0 -13
  268. data/lib/sprockets/helpers/rails_helper.rb +0 -182
  269. data/lib/sprockets/helpers.rb +0 -6
  270. data/lib/sprockets/railtie.rb +0 -62
  271. data/lib/sprockets/static_compiler.rb +0 -56
@@ -1,435 +0,0 @@
1
- require 'action_controller/vendor/html-scanner'
2
- require 'active_support/core_ext/object/inclusion'
3
-
4
- #--
5
- # Copyright (c) 2006 Assaf Arkin (http://labnotes.org)
6
- # Under MIT and/or CC By license.
7
- #++
8
-
9
- module ActionDispatch
10
- module Assertions
11
- NO_STRIP = %w{pre script style textarea}
12
-
13
- # Adds the +assert_select+ method for use in Rails functional
14
- # test cases, which can be used to make assertions on the response HTML of a controller
15
- # action. You can also call +assert_select+ within another +assert_select+ to
16
- # make assertions on elements selected by the enclosing assertion.
17
- #
18
- # Use +css_select+ to select elements without making an assertions, either
19
- # from the response HTML or elements selected by the enclosing assertion.
20
- #
21
- # In addition to HTML responses, you can make the following assertions:
22
- #
23
- # * +assert_select_encoded+ - Assertions on HTML encoded inside XML, for example for dealing with feed item descriptions.
24
- # * +assert_select_email+ - Assertions on the HTML body of an e-mail.
25
- #
26
- # Also see HTML::Selector to learn how to use selectors.
27
- module SelectorAssertions
28
- # Select and return all matching elements.
29
- #
30
- # If called with a single argument, uses that argument as a selector
31
- # to match all elements of the current page. Returns an empty array
32
- # if no match is found.
33
- #
34
- # If called with two arguments, uses the first argument as the base
35
- # element and the second argument as the selector. Attempts to match the
36
- # base element and any of its children. Returns an empty array if no
37
- # match is found.
38
- #
39
- # The selector may be a CSS selector expression (String), an expression
40
- # with substitution values (Array) or an HTML::Selector object.
41
- #
42
- # ==== Examples
43
- # # Selects all div tags
44
- # divs = css_select("div")
45
- #
46
- # # Selects all paragraph tags and does something interesting
47
- # pars = css_select("p")
48
- # pars.each do |par|
49
- # # Do something fun with paragraphs here...
50
- # end
51
- #
52
- # # Selects all list items in unordered lists
53
- # items = css_select("ul>li")
54
- #
55
- # # Selects all form tags and then all inputs inside the form
56
- # forms = css_select("form")
57
- # forms.each do |form|
58
- # inputs = css_select(form, "input")
59
- # ...
60
- # end
61
- #
62
- def css_select(*args)
63
- # See assert_select to understand what's going on here.
64
- arg = args.shift
65
-
66
- if arg.is_a?(HTML::Node)
67
- root = arg
68
- arg = args.shift
69
- elsif arg == nil
70
- raise ArgumentError, "First argument is either selector or element to select, but nil found. Perhaps you called assert_select with an element that does not exist?"
71
- elsif defined?(@selected) && @selected
72
- matches = []
73
-
74
- @selected.each do |selected|
75
- subset = css_select(selected, HTML::Selector.new(arg.dup, args.dup))
76
- subset.each do |match|
77
- matches << match unless matches.any? { |m| m.equal?(match) }
78
- end
79
- end
80
-
81
- return matches
82
- else
83
- root = response_from_page
84
- end
85
-
86
- case arg
87
- when String
88
- selector = HTML::Selector.new(arg, args)
89
- when Array
90
- selector = HTML::Selector.new(*arg)
91
- when HTML::Selector
92
- selector = arg
93
- else raise ArgumentError, "Expecting a selector as the first argument"
94
- end
95
-
96
- selector.select(root)
97
- end
98
-
99
- # An assertion that selects elements and makes one or more equality tests.
100
- #
101
- # If the first argument is an element, selects all matching elements
102
- # starting from (and including) that element and all its children in
103
- # depth-first order.
104
- #
105
- # If no element if specified, calling +assert_select+ selects from the
106
- # response HTML unless +assert_select+ is called from within an +assert_select+ block.
107
- #
108
- # When called with a block +assert_select+ passes an array of selected elements
109
- # to the block. Calling +assert_select+ from the block, with no element specified,
110
- # runs the assertion on the complete set of elements selected by the enclosing assertion.
111
- # Alternatively the array may be iterated through so that +assert_select+ can be called
112
- # separately for each element.
113
- #
114
- #
115
- # ==== Example
116
- # If the response contains two ordered lists, each with four list elements then:
117
- # assert_select "ol" do |elements|
118
- # elements.each do |element|
119
- # assert_select element, "li", 4
120
- # end
121
- # end
122
- #
123
- # will pass, as will:
124
- # assert_select "ol" do
125
- # assert_select "li", 8
126
- # end
127
- #
128
- # The selector may be a CSS selector expression (String), an expression
129
- # with substitution values, or an HTML::Selector object.
130
- #
131
- # === Equality Tests
132
- #
133
- # The equality test may be one of the following:
134
- # * <tt>true</tt> - Assertion is true if at least one element selected.
135
- # * <tt>false</tt> - Assertion is true if no element selected.
136
- # * <tt>String/Regexp</tt> - Assertion is true if the text value of at least
137
- # one element matches the string or regular expression.
138
- # * <tt>Integer</tt> - Assertion is true if exactly that number of
139
- # elements are selected.
140
- # * <tt>Range</tt> - Assertion is true if the number of selected
141
- # elements fit the range.
142
- # If no equality test specified, the assertion is true if at least one
143
- # element selected.
144
- #
145
- # To perform more than one equality tests, use a hash with the following keys:
146
- # * <tt>:text</tt> - Narrow the selection to elements that have this text
147
- # value (string or regexp).
148
- # * <tt>:html</tt> - Narrow the selection to elements that have this HTML
149
- # content (string or regexp).
150
- # * <tt>:count</tt> - Assertion is true if the number of selected elements
151
- # is equal to this value.
152
- # * <tt>:minimum</tt> - Assertion is true if the number of selected
153
- # elements is at least this value.
154
- # * <tt>:maximum</tt> - Assertion is true if the number of selected
155
- # elements is at most this value.
156
- #
157
- # If the method is called with a block, once all equality tests are
158
- # evaluated the block is called with an array of all matched elements.
159
- #
160
- # ==== Examples
161
- #
162
- # # At least one form element
163
- # assert_select "form"
164
- #
165
- # # Form element includes four input fields
166
- # assert_select "form input", 4
167
- #
168
- # # Page title is "Welcome"
169
- # assert_select "title", "Welcome"
170
- #
171
- # # Page title is "Welcome" and there is only one title element
172
- # assert_select "title", {:count => 1, :text => "Welcome"},
173
- # "Wrong title or more than one title element"
174
- #
175
- # # Page contains no forms
176
- # assert_select "form", false, "This page must contain no forms"
177
- #
178
- # # Test the content and style
179
- # assert_select "body div.header ul.menu"
180
- #
181
- # # Use substitution values
182
- # assert_select "ol>li#?", /item-\d+/
183
- #
184
- # # All input fields in the form have a name
185
- # assert_select "form input" do
186
- # assert_select "[name=?]", /.+/ # Not empty
187
- # end
188
- def assert_select(*args, &block)
189
- # Start with optional element followed by mandatory selector.
190
- arg = args.shift
191
- @selected ||= nil
192
-
193
- if arg.is_a?(HTML::Node)
194
- # First argument is a node (tag or text, but also HTML root),
195
- # so we know what we're selecting from.
196
- root = arg
197
- arg = args.shift
198
- elsif arg == nil
199
- # This usually happens when passing a node/element that
200
- # happens to be nil.
201
- raise ArgumentError, "First argument is either selector or element to select, but nil found. Perhaps you called assert_select with an element that does not exist?"
202
- elsif @selected
203
- root = HTML::Node.new(nil)
204
- root.children.concat @selected
205
- else
206
- # Otherwise just operate on the response document.
207
- root = response_from_page
208
- end
209
-
210
- # First or second argument is the selector: string and we pass
211
- # all remaining arguments. Array and we pass the argument. Also
212
- # accepts selector itself.
213
- case arg
214
- when String
215
- selector = HTML::Selector.new(arg, args)
216
- when Array
217
- selector = HTML::Selector.new(*arg)
218
- when HTML::Selector
219
- selector = arg
220
- else raise ArgumentError, "Expecting a selector as the first argument"
221
- end
222
-
223
- # Next argument is used for equality tests.
224
- equals = {}
225
- case arg = args.shift
226
- when Hash
227
- equals = arg
228
- when String, Regexp
229
- equals[:text] = arg
230
- when Integer
231
- equals[:count] = arg
232
- when Range
233
- equals[:minimum] = arg.begin
234
- equals[:maximum] = arg.end
235
- when FalseClass
236
- equals[:count] = 0
237
- when NilClass, TrueClass
238
- equals[:minimum] = 1
239
- else raise ArgumentError, "I don't understand what you're trying to match"
240
- end
241
-
242
- # By default we're looking for at least one match.
243
- if equals[:count]
244
- equals[:minimum] = equals[:maximum] = equals[:count]
245
- else
246
- equals[:minimum] = 1 unless equals[:minimum]
247
- end
248
-
249
- # Last argument is the message we use if the assertion fails.
250
- message = args.shift
251
- #- message = "No match made with selector #{selector.inspect}" unless message
252
- if args.shift
253
- raise ArgumentError, "Not expecting that last argument, you either have too many arguments, or they're the wrong type"
254
- end
255
-
256
- matches = selector.select(root)
257
- # If text/html, narrow down to those elements that match it.
258
- content_mismatch = nil
259
- if match_with = equals[:text]
260
- matches.delete_if do |match|
261
- text = ""
262
- stack = match.children.reverse
263
- while node = stack.pop
264
- if node.tag?
265
- stack.concat node.children.reverse
266
- else
267
- content = node.content
268
- text << content
269
- end
270
- end
271
- text.strip! unless NO_STRIP.include?(match.name)
272
- text.sub!(/\A\n/, '') if match.name == "textarea"
273
- unless match_with.is_a?(Regexp) ? (text =~ match_with) : (text == match_with.to_s)
274
- content_mismatch ||= build_message(message, "<?> expected but was\n<?>.", match_with, text)
275
- true
276
- end
277
- end
278
- elsif match_with = equals[:html]
279
- matches.delete_if do |match|
280
- html = match.children.map(&:to_s).join
281
- html.strip! unless NO_STRIP.include?(match.name)
282
- unless match_with.is_a?(Regexp) ? (html =~ match_with) : (html == match_with.to_s)
283
- content_mismatch ||= build_message(message, "<?> expected but was\n<?>.", match_with, html)
284
- true
285
- end
286
- end
287
- end
288
- # Expecting foo found bar element only if found zero, not if
289
- # found one but expecting two.
290
- message ||= content_mismatch if matches.empty?
291
- # Test minimum/maximum occurrence.
292
- min, max, count = equals[:minimum], equals[:maximum], equals[:count]
293
- message = message || %(Expected #{count_description(min, max, count)} matching "#{selector.to_s}", found #{matches.size}.)
294
- if count
295
- assert matches.size == count, message
296
- else
297
- assert matches.size >= min, message if min
298
- assert matches.size <= max, message if max
299
- end
300
-
301
- # If a block is given call that block. Set @selected to allow
302
- # nested assert_select, which can be nested several levels deep.
303
- if block_given? && !matches.empty?
304
- begin
305
- in_scope, @selected = @selected, matches
306
- yield matches
307
- ensure
308
- @selected = in_scope
309
- end
310
- end
311
-
312
- # Returns all matches elements.
313
- matches
314
- end
315
-
316
- def count_description(min, max, count) #:nodoc:
317
- pluralize = lambda {|word, quantity| word << (quantity == 1 ? '' : 's')}
318
-
319
- if min && max && (max != min)
320
- "between #{min} and #{max} elements"
321
- elsif min && max && max == min && count
322
- "exactly #{count} #{pluralize['element', min]}"
323
- elsif min && !(min == 1 && max == 1)
324
- "at least #{min} #{pluralize['element', min]}"
325
- elsif max
326
- "at most #{max} #{pluralize['element', max]}"
327
- end
328
- end
329
-
330
- # Extracts the content of an element, treats it as encoded HTML and runs
331
- # nested assertion on it.
332
- #
333
- # You typically call this method within another assertion to operate on
334
- # all currently selected elements. You can also pass an element or array
335
- # of elements.
336
- #
337
- # The content of each element is un-encoded, and wrapped in the root
338
- # element +encoded+. It then calls the block with all un-encoded elements.
339
- #
340
- # ==== Examples
341
- # # Selects all bold tags from within the title of an ATOM feed's entries (perhaps to nab a section name prefix)
342
- # assert_select_feed :atom, 1.0 do
343
- # # Select each entry item and then the title item
344
- # assert_select "entry>title" do
345
- # # Run assertions on the encoded title elements
346
- # assert_select_encoded do
347
- # assert_select "b"
348
- # end
349
- # end
350
- # end
351
- #
352
- #
353
- # # Selects all paragraph tags from within the description of an RSS feed
354
- # assert_select_feed :rss, 2.0 do
355
- # # Select description element of each feed item.
356
- # assert_select "channel>item>description" do
357
- # # Run assertions on the encoded elements.
358
- # assert_select_encoded do
359
- # assert_select "p"
360
- # end
361
- # end
362
- # end
363
- def assert_select_encoded(element = nil, &block)
364
- case element
365
- when Array
366
- elements = element
367
- when HTML::Node
368
- elements = [element]
369
- when nil
370
- unless elements = @selected
371
- raise ArgumentError, "First argument is optional, but must be called from a nested assert_select"
372
- end
373
- else
374
- raise ArgumentError, "Argument is optional, and may be node or array of nodes"
375
- end
376
-
377
- fix_content = lambda do |node|
378
- # Gets around a bug in the Rails 1.1 HTML parser.
379
- node.content.gsub(/<!\[CDATA\[(.*)(\]\]>)?/m) { Rack::Utils.escapeHTML($1) }
380
- end
381
-
382
- selected = elements.map do |_element|
383
- text = _element.children.select{ |c| not c.tag? }.map{ |c| fix_content[c] }.join
384
- root = HTML::Document.new(CGI.unescapeHTML("<encoded>#{text}</encoded>")).root
385
- css_select(root, "encoded:root", &block)[0]
386
- end
387
-
388
- begin
389
- old_selected, @selected = @selected, selected
390
- assert_select ":root", &block
391
- ensure
392
- @selected = old_selected
393
- end
394
- end
395
-
396
- # Extracts the body of an email and runs nested assertions on it.
397
- #
398
- # You must enable deliveries for this assertion to work, use:
399
- # ActionMailer::Base.perform_deliveries = true
400
- #
401
- # ==== Examples
402
- #
403
- # assert_select_email do
404
- # assert_select "h1", "Email alert"
405
- # end
406
- #
407
- # assert_select_email do
408
- # items = assert_select "ol>li"
409
- # items.each do
410
- # # Work with items here...
411
- # end
412
- # end
413
- #
414
- def assert_select_email(&block)
415
- deliveries = ActionMailer::Base.deliveries
416
- assert !deliveries.empty?, "No e-mail in delivery list"
417
-
418
- for delivery in deliveries
419
- for part in (delivery.parts.empty? ? [delivery] : delivery.parts)
420
- if part["Content-Type"].to_s =~ /^text\/html\W/
421
- root = HTML::Document.new(part.body.to_s).root
422
- assert_select root, ":root", &block
423
- end
424
- end
425
- end
426
- end
427
-
428
- protected
429
- # +assert_select+ and +css_select+ call this to obtain the content in the HTML page.
430
- def response_from_page
431
- html_document.root
432
- end
433
- end
434
- end
435
- end
@@ -1,138 +0,0 @@
1
- require 'action_controller/vendor/html-scanner'
2
-
3
- module ActionDispatch
4
- module Assertions
5
- # Pair of assertions to testing elements in the HTML output of the response.
6
- module TagAssertions
7
- # Asserts that there is a tag/node/element in the body of the response
8
- # that meets all of the given conditions. The +conditions+ parameter must
9
- # be a hash of any of the following keys (all are optional):
10
- #
11
- # * <tt>:tag</tt>: the node type must match the corresponding value
12
- # * <tt>:attributes</tt>: a hash. The node's attributes must match the
13
- # corresponding values in the hash.
14
- # * <tt>:parent</tt>: a hash. The node's parent must match the
15
- # corresponding hash.
16
- # * <tt>:child</tt>: a hash. At least one of the node's immediate children
17
- # must meet the criteria described by the hash.
18
- # * <tt>:ancestor</tt>: a hash. At least one of the node's ancestors must
19
- # meet the criteria described by the hash.
20
- # * <tt>:descendant</tt>: a hash. At least one of the node's descendants
21
- # must meet the criteria described by the hash.
22
- # * <tt>:sibling</tt>: a hash. At least one of the node's siblings must
23
- # meet the criteria described by the hash.
24
- # * <tt>:after</tt>: a hash. The node must be after any sibling meeting
25
- # the criteria described by the hash, and at least one sibling must match.
26
- # * <tt>:before</tt>: a hash. The node must be before any sibling meeting
27
- # the criteria described by the hash, and at least one sibling must match.
28
- # * <tt>:children</tt>: a hash, for counting children of a node. Accepts
29
- # the keys:
30
- # * <tt>:count</tt>: either a number or a range which must equal (or
31
- # include) the number of children that match.
32
- # * <tt>:less_than</tt>: the number of matching children must be less
33
- # than this number.
34
- # * <tt>:greater_than</tt>: the number of matching children must be
35
- # greater than this number.
36
- # * <tt>:only</tt>: another hash consisting of the keys to use
37
- # to match on the children, and only matching children will be
38
- # counted.
39
- # * <tt>:content</tt>: the textual content of the node must match the
40
- # given value. This will not match HTML tags in the body of a
41
- # tag--only text.
42
- #
43
- # Conditions are matched using the following algorithm:
44
- #
45
- # * if the condition is a string, it must be a substring of the value.
46
- # * if the condition is a regexp, it must match the value.
47
- # * if the condition is a number, the value must match number.to_s.
48
- # * if the condition is +true+, the value must not be +nil+.
49
- # * if the condition is +false+ or +nil+, the value must be +nil+.
50
- #
51
- # === Examples
52
- #
53
- # # Assert that there is a "span" tag
54
- # assert_tag :tag => "span"
55
- #
56
- # # Assert that there is a "span" tag with id="x"
57
- # assert_tag :tag => "span", :attributes => { :id => "x" }
58
- #
59
- # # Assert that there is a "span" tag using the short-hand
60
- # assert_tag :span
61
- #
62
- # # Assert that there is a "span" tag with id="x" using the short-hand
63
- # assert_tag :span, :attributes => { :id => "x" }
64
- #
65
- # # Assert that there is a "span" inside of a "div"
66
- # assert_tag :tag => "span", :parent => { :tag => "div" }
67
- #
68
- # # Assert that there is a "span" somewhere inside a table
69
- # assert_tag :tag => "span", :ancestor => { :tag => "table" }
70
- #
71
- # # Assert that there is a "span" with at least one "em" child
72
- # assert_tag :tag => "span", :child => { :tag => "em" }
73
- #
74
- # # Assert that there is a "span" containing a (possibly nested)
75
- # # "strong" tag.
76
- # assert_tag :tag => "span", :descendant => { :tag => "strong" }
77
- #
78
- # # Assert that there is a "span" containing between 2 and 4 "em" tags
79
- # # as immediate children
80
- # assert_tag :tag => "span",
81
- # :children => { :count => 2..4, :only => { :tag => "em" } }
82
- #
83
- # # Get funky: assert that there is a "div", with an "ul" ancestor
84
- # # and an "li" parent (with "class" = "enum"), and containing a
85
- # # "span" descendant that contains text matching /hello world/
86
- # assert_tag :tag => "div",
87
- # :ancestor => { :tag => "ul" },
88
- # :parent => { :tag => "li",
89
- # :attributes => { :class => "enum" } },
90
- # :descendant => { :tag => "span",
91
- # :child => /hello world/ }
92
- #
93
- # <b>Please note</b>: +assert_tag+ and +assert_no_tag+ only work
94
- # with well-formed XHTML. They recognize a few tags as implicitly self-closing
95
- # (like br and hr and such) but will not work correctly with tags
96
- # that allow optional closing tags (p, li, td). <em>You must explicitly
97
- # close all of your tags to use these assertions.</em>
98
- def assert_tag(*opts)
99
- opts = opts.size > 1 ? opts.last.merge({ :tag => opts.first.to_s }) : opts.first
100
- tag = find_tag(opts)
101
- assert tag, "expected tag, but no tag found matching #{opts.inspect} in:\n#{@response.body.inspect}"
102
- end
103
-
104
- # Identical to +assert_tag+, but asserts that a matching tag does _not_
105
- # exist. (See +assert_tag+ for a full discussion of the syntax.)
106
- #
107
- # === Examples
108
- # # Assert that there is not a "div" containing a "p"
109
- # assert_no_tag :tag => "div", :descendant => { :tag => "p" }
110
- #
111
- # # Assert that an unordered list is empty
112
- # assert_no_tag :tag => "ul", :descendant => { :tag => "li" }
113
- #
114
- # # Assert that there is not a "p" tag with between 1 to 3 "img" tags
115
- # # as immediate children
116
- # assert_no_tag :tag => "p",
117
- # :children => { :count => 1..3, :only => { :tag => "img" } }
118
- def assert_no_tag(*opts)
119
- opts = opts.size > 1 ? opts.last.merge({ :tag => opts.first.to_s }) : opts.first
120
- tag = find_tag(opts)
121
- assert !tag, "expected no tag, but found tag matching #{opts.inspect} in:\n#{@response.body.inspect}"
122
- end
123
-
124
- def find_tag(conditions)
125
- html_document.find(conditions)
126
- end
127
-
128
- def find_all_tag(conditions)
129
- html_document.find_all(conditions)
130
- end
131
-
132
- def html_document
133
- xml = @response.content_type =~ /xml$/
134
- @html_document ||= HTML::Document.new(@response.body, false, xml)
135
- end
136
- end
137
- end
138
- end
@@ -1,10 +0,0 @@
1
- require 'active_support/testing/performance'
2
-
3
- module ActionDispatch
4
- # An integration test that runs a code profiler on your test methods.
5
- # Profiling output for combinations of each test method, measurement, and
6
- # output format are written to your tmp/performance directory.
7
- class PerformanceTest < ActionDispatch::IntegrationTest
8
- include ActiveSupport::Testing::Performance
9
- end
10
- end