actionpack 3.2.19 → 4.2.11.3
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +412 -503
- data/MIT-LICENSE +1 -1
- data/README.rdoc +11 -294
- data/lib/abstract_controller/asset_paths.rb +2 -2
- data/lib/abstract_controller/base.rb +52 -18
- data/lib/abstract_controller/callbacks.rb +87 -89
- data/lib/abstract_controller/collector.rb +17 -3
- data/lib/abstract_controller/helpers.rb +41 -14
- data/lib/abstract_controller/logger.rb +1 -2
- data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
- data/lib/abstract_controller/rendering.rb +65 -118
- data/lib/abstract_controller/translation.rb +16 -1
- data/lib/abstract_controller/url_for.rb +7 -7
- data/lib/abstract_controller.rb +2 -10
- data/lib/action_controller/base.rb +61 -28
- data/lib/action_controller/caching/fragments.rb +30 -54
- data/lib/action_controller/caching.rb +38 -35
- data/lib/action_controller/log_subscriber.rb +35 -18
- data/lib/action_controller/metal/conditional_get.rb +103 -34
- data/lib/action_controller/metal/data_streaming.rb +20 -26
- data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
- data/lib/action_controller/metal/exceptions.rb +19 -6
- data/lib/action_controller/metal/flash.rb +41 -9
- data/lib/action_controller/metal/force_ssl.rb +70 -12
- data/lib/action_controller/metal/head.rb +30 -7
- data/lib/action_controller/metal/helpers.rb +11 -11
- data/lib/action_controller/metal/hide_actions.rb +0 -1
- data/lib/action_controller/metal/http_authentication.rb +140 -94
- data/lib/action_controller/metal/implicit_render.rb +1 -1
- data/lib/action_controller/metal/instrumentation.rb +11 -7
- data/lib/action_controller/metal/live.rb +328 -0
- data/lib/action_controller/metal/mime_responds.rb +161 -152
- data/lib/action_controller/metal/params_wrapper.rb +126 -81
- data/lib/action_controller/metal/rack_delegation.rb +10 -4
- data/lib/action_controller/metal/redirecting.rb +44 -41
- data/lib/action_controller/metal/renderers.rb +48 -19
- data/lib/action_controller/metal/rendering.rb +46 -11
- data/lib/action_controller/metal/request_forgery_protection.rb +250 -29
- data/lib/action_controller/metal/streaming.rb +30 -38
- data/lib/action_controller/metal/strong_parameters.rb +669 -0
- data/lib/action_controller/metal/testing.rb +12 -18
- data/lib/action_controller/metal/url_for.rb +31 -29
- data/lib/action_controller/metal.rb +31 -40
- data/lib/action_controller/model_naming.rb +12 -0
- data/lib/action_controller/railtie.rb +38 -18
- data/lib/action_controller/railties/helpers.rb +22 -0
- data/lib/action_controller/test_case.rb +359 -173
- data/lib/action_controller.rb +9 -16
- data/lib/action_dispatch/http/cache.rb +64 -11
- data/lib/action_dispatch/http/filter_parameters.rb +20 -10
- data/lib/action_dispatch/http/filter_redirect.rb +38 -0
- data/lib/action_dispatch/http/headers.rb +85 -17
- data/lib/action_dispatch/http/mime_negotiation.rb +55 -5
- data/lib/action_dispatch/http/mime_type.rb +167 -114
- data/lib/action_dispatch/http/mime_types.rb +2 -1
- data/lib/action_dispatch/http/parameter_filter.rb +44 -46
- data/lib/action_dispatch/http/parameters.rb +30 -46
- data/lib/action_dispatch/http/rack_cache.rb +2 -3
- data/lib/action_dispatch/http/request.rb +108 -45
- data/lib/action_dispatch/http/response.rb +247 -48
- data/lib/action_dispatch/http/upload.rb +60 -29
- data/lib/action_dispatch/http/url.rb +135 -45
- data/lib/action_dispatch/journey/backwards.rb +5 -0
- data/lib/action_dispatch/journey/formatter.rb +166 -0
- data/lib/action_dispatch/journey/gtg/builder.rb +162 -0
- data/lib/action_dispatch/journey/gtg/simulator.rb +47 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +157 -0
- data/lib/action_dispatch/journey/nfa/builder.rb +76 -0
- data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
- data/lib/action_dispatch/journey/nfa/simulator.rb +47 -0
- data/lib/action_dispatch/journey/nfa/transition_table.rb +163 -0
- data/lib/action_dispatch/journey/nodes/node.rb +128 -0
- data/lib/action_dispatch/journey/parser.rb +198 -0
- data/lib/action_dispatch/journey/parser.y +49 -0
- data/lib/action_dispatch/journey/parser_extras.rb +23 -0
- data/lib/action_dispatch/journey/path/pattern.rb +193 -0
- data/lib/action_dispatch/journey/route.rb +125 -0
- data/lib/action_dispatch/journey/router/strexp.rb +27 -0
- data/lib/action_dispatch/journey/router/utils.rb +93 -0
- data/lib/action_dispatch/journey/router.rb +144 -0
- data/lib/action_dispatch/journey/routes.rb +80 -0
- data/lib/action_dispatch/journey/scanner.rb +61 -0
- data/lib/action_dispatch/journey/visitors.rb +221 -0
- data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
- data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
- data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
- data/lib/action_dispatch/journey.rb +5 -0
- data/lib/action_dispatch/middleware/callbacks.rb +16 -11
- data/lib/action_dispatch/middleware/cookies.rb +346 -125
- data/lib/action_dispatch/middleware/debug_exceptions.rb +52 -24
- data/lib/action_dispatch/middleware/exception_wrapper.rb +75 -9
- data/lib/action_dispatch/middleware/flash.rb +85 -72
- data/lib/action_dispatch/middleware/params_parser.rb +16 -31
- data/lib/action_dispatch/middleware/public_exceptions.rb +39 -14
- data/lib/action_dispatch/middleware/reloader.rb +16 -7
- data/lib/action_dispatch/middleware/remote_ip.rb +132 -40
- data/lib/action_dispatch/middleware/request_id.rb +3 -7
- data/lib/action_dispatch/middleware/session/abstract_store.rb +22 -20
- data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
- data/lib/action_dispatch/middleware/session/cookie_store.rb +84 -29
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +15 -44
- data/lib/action_dispatch/middleware/ssl.rb +72 -0
- data/lib/action_dispatch/middleware/stack.rb +6 -1
- data/lib/action_dispatch/middleware/static.rb +80 -23
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +34 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.erb +27 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +133 -5
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
- data/lib/action_dispatch/railtie.rb +19 -6
- data/lib/action_dispatch/request/session.rb +193 -0
- data/lib/action_dispatch/request/utils.rb +35 -0
- data/lib/action_dispatch/routing/endpoint.rb +10 -0
- data/lib/action_dispatch/routing/inspector.rb +234 -0
- data/lib/action_dispatch/routing/mapper.rb +897 -436
- data/lib/action_dispatch/routing/polymorphic_routes.rb +213 -92
- data/lib/action_dispatch/routing/redirection.rb +97 -37
- data/lib/action_dispatch/routing/route_set.rb +432 -239
- data/lib/action_dispatch/routing/routes_proxy.rb +7 -4
- data/lib/action_dispatch/routing/url_for.rb +63 -34
- data/lib/action_dispatch/routing.rb +57 -89
- data/lib/action_dispatch/testing/assertions/dom.rb +2 -36
- data/lib/action_dispatch/testing/assertions/response.rb +24 -38
- data/lib/action_dispatch/testing/assertions/routing.rb +55 -54
- data/lib/action_dispatch/testing/assertions/selector.rb +2 -434
- data/lib/action_dispatch/testing/assertions/tag.rb +2 -137
- data/lib/action_dispatch/testing/assertions.rb +11 -7
- data/lib/action_dispatch/testing/integration.rb +88 -72
- data/lib/action_dispatch/testing/test_process.rb +9 -6
- data/lib/action_dispatch/testing/test_request.rb +13 -9
- data/lib/action_dispatch/testing/test_response.rb +1 -5
- data/lib/action_dispatch.rb +24 -21
- data/lib/action_pack/gem_version.rb +15 -0
- data/lib/action_pack/version.rb +5 -7
- data/lib/action_pack.rb +1 -1
- metadata +181 -292
- data/lib/abstract_controller/layouts.rb +0 -423
- data/lib/abstract_controller/view_paths.rb +0 -96
- data/lib/action_controller/caching/actions.rb +0 -185
- data/lib/action_controller/caching/pages.rb +0 -187
- data/lib/action_controller/caching/sweeping.rb +0 -97
- data/lib/action_controller/deprecated/integration_test.rb +0 -2
- data/lib/action_controller/deprecated/performance_test.rb +0 -1
- data/lib/action_controller/deprecated.rb +0 -3
- data/lib/action_controller/metal/compatibility.rb +0 -65
- data/lib/action_controller/metal/responder.rb +0 -286
- data/lib/action_controller/metal/session_management.rb +0 -14
- data/lib/action_controller/railties/paths.rb +0 -25
- data/lib/action_controller/record_identifier.rb +0 -85
- data/lib/action_controller/vendor/html-scanner/html/document.rb +0 -68
- data/lib/action_controller/vendor/html-scanner/html/node.rb +0 -532
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +0 -177
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +0 -830
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +0 -107
- data/lib/action_controller/vendor/html-scanner/html/version.rb +0 -11
- data/lib/action_controller/vendor/html-scanner.rb +0 -20
- data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
- data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
- data/lib/action_dispatch/middleware/head.rb +0 -18
- data/lib/action_dispatch/middleware/rescue.rb +0 -26
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +0 -31
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -26
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +0 -10
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -2
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +0 -15
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -17
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +0 -2
- data/lib/action_dispatch/testing/performance_test.rb +0 -10
- data/lib/action_view/asset_paths.rb +0 -142
- data/lib/action_view/base.rb +0 -220
- data/lib/action_view/buffers.rb +0 -43
- data/lib/action_view/context.rb +0 -36
- data/lib/action_view/flows.rb +0 -79
- data/lib/action_view/helpers/active_model_helper.rb +0 -50
- data/lib/action_view/helpers/asset_paths.rb +0 -7
- data/lib/action_view/helpers/asset_tag_helper.rb +0 -457
- data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
- data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
- data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
- data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
- data/lib/action_view/helpers/atom_feed_helper.rb +0 -200
- data/lib/action_view/helpers/cache_helper.rb +0 -64
- data/lib/action_view/helpers/capture_helper.rb +0 -203
- data/lib/action_view/helpers/controller_helper.rb +0 -25
- data/lib/action_view/helpers/csrf_helper.rb +0 -32
- data/lib/action_view/helpers/date_helper.rb +0 -1062
- data/lib/action_view/helpers/debug_helper.rb +0 -40
- data/lib/action_view/helpers/form_helper.rb +0 -1486
- data/lib/action_view/helpers/form_options_helper.rb +0 -658
- data/lib/action_view/helpers/form_tag_helper.rb +0 -685
- data/lib/action_view/helpers/javascript_helper.rb +0 -110
- data/lib/action_view/helpers/number_helper.rb +0 -622
- data/lib/action_view/helpers/output_safety_helper.rb +0 -38
- data/lib/action_view/helpers/record_tag_helper.rb +0 -111
- data/lib/action_view/helpers/rendering_helper.rb +0 -90
- data/lib/action_view/helpers/sanitize_helper.rb +0 -259
- data/lib/action_view/helpers/tag_helper.rb +0 -160
- data/lib/action_view/helpers/text_helper.rb +0 -426
- data/lib/action_view/helpers/translation_helper.rb +0 -91
- data/lib/action_view/helpers/url_helper.rb +0 -693
- data/lib/action_view/helpers.rb +0 -60
- data/lib/action_view/locale/en.yml +0 -160
- data/lib/action_view/log_subscriber.rb +0 -28
- data/lib/action_view/lookup_context.rb +0 -254
- data/lib/action_view/path_set.rb +0 -89
- data/lib/action_view/railtie.rb +0 -55
- data/lib/action_view/renderer/abstract_renderer.rb +0 -41
- data/lib/action_view/renderer/partial_renderer.rb +0 -415
- data/lib/action_view/renderer/renderer.rb +0 -54
- data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
- data/lib/action_view/renderer/template_renderer.rb +0 -94
- data/lib/action_view/template/error.rb +0 -128
- data/lib/action_view/template/handlers/builder.rb +0 -26
- data/lib/action_view/template/handlers/erb.rb +0 -125
- data/lib/action_view/template/handlers.rb +0 -50
- data/lib/action_view/template/resolver.rb +0 -272
- data/lib/action_view/template/text.rb +0 -30
- data/lib/action_view/template.rb +0 -337
- data/lib/action_view/test_case.rb +0 -245
- data/lib/action_view/testing/resolvers.rb +0 -50
- data/lib/action_view.rb +0 -84
- data/lib/sprockets/assets.rake +0 -99
- data/lib/sprockets/bootstrap.rb +0 -37
- data/lib/sprockets/compressors.rb +0 -83
- data/lib/sprockets/helpers/isolated_helper.rb +0 -13
- data/lib/sprockets/helpers/rails_helper.rb +0 -182
- data/lib/sprockets/helpers.rb +0 -6
- data/lib/sprockets/railtie.rb +0 -62
- data/lib/sprockets/static_compiler.rb +0 -56
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'uri'
|
2
|
-
require 'active_support/core_ext/hash/diff'
|
3
2
|
require 'active_support/core_ext/hash/indifferent_access'
|
3
|
+
require 'active_support/core_ext/string/access'
|
4
4
|
require 'action_controller/metal/exceptions'
|
5
5
|
|
6
6
|
module ActionDispatch
|
@@ -15,39 +15,47 @@ module ActionDispatch
|
|
15
15
|
# and a :method containing the required HTTP verb.
|
16
16
|
#
|
17
17
|
# # assert that POSTing to /items will call the create action on ItemsController
|
18
|
-
# assert_recognizes({:
|
18
|
+
# assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})
|
19
19
|
#
|
20
20
|
# You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
|
21
21
|
# to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the
|
22
22
|
# extras argument, appending the query string on the path directly will not work. For example:
|
23
23
|
#
|
24
24
|
# # assert that a path of '/items/list/1?view=print' returns the correct options
|
25
|
-
# assert_recognizes({:
|
25
|
+
# assert_recognizes({controller: 'items', action: 'list', id: '1', view: 'print'}, 'items/list/1', { view: "print" })
|
26
26
|
#
|
27
27
|
# The +message+ parameter allows you to pass in an error message that is displayed upon failure.
|
28
28
|
#
|
29
|
-
# ==== Examples
|
30
29
|
# # Check the default route (i.e., the index action)
|
31
|
-
# assert_recognizes({:
|
30
|
+
# assert_recognizes({controller: 'items', action: 'index'}, 'items')
|
32
31
|
#
|
33
32
|
# # Test a specific action
|
34
|
-
# assert_recognizes({:
|
33
|
+
# assert_recognizes({controller: 'items', action: 'list'}, 'items/list')
|
35
34
|
#
|
36
35
|
# # Test an action with a parameter
|
37
|
-
# assert_recognizes({:
|
36
|
+
# assert_recognizes({controller: 'items', action: 'destroy', id: '1'}, 'items/destroy/1')
|
38
37
|
#
|
39
38
|
# # Test a custom route
|
40
|
-
# assert_recognizes({:
|
41
|
-
def assert_recognizes(expected_options, path, extras={},
|
42
|
-
|
39
|
+
# assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1')
|
40
|
+
def assert_recognizes(expected_options, path, extras={}, msg=nil)
|
41
|
+
if path.is_a?(Hash) && path[:method].to_s == "all"
|
42
|
+
[:get, :post, :put, :delete].each do |method|
|
43
|
+
assert_recognizes(expected_options, path.merge(method: method), extras, msg)
|
44
|
+
end
|
45
|
+
else
|
46
|
+
request = recognized_request_for(path, extras, msg)
|
47
|
+
|
48
|
+
expected_options = expected_options.clone
|
49
|
+
|
50
|
+
expected_options.stringify_keys!
|
43
51
|
|
44
|
-
|
45
|
-
|
52
|
+
msg = message(msg, "") {
|
53
|
+
sprintf("The recognized options <%s> did not match <%s>, difference:",
|
54
|
+
request.path_parameters, expected_options)
|
55
|
+
}
|
46
56
|
|
47
|
-
|
48
|
-
|
49
|
-
request.path_parameters, expected_options, expected_options.diff(request.path_parameters))
|
50
|
-
assert_equal(expected_options, request.path_parameters, msg)
|
57
|
+
assert_equal(expected_options, request.path_parameters, msg)
|
58
|
+
end
|
51
59
|
end
|
52
60
|
|
53
61
|
# Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
|
@@ -56,25 +64,22 @@ module ActionDispatch
|
|
56
64
|
#
|
57
65
|
# The +defaults+ parameter is unused.
|
58
66
|
#
|
59
|
-
# ==== Examples
|
60
67
|
# # Asserts that the default action is generated for a route with no action
|
61
|
-
# assert_generates "/items", :
|
68
|
+
# assert_generates "/items", controller: "items", action: "index"
|
62
69
|
#
|
63
70
|
# # Tests that the list action is properly routed
|
64
|
-
# assert_generates "/items/list", :
|
71
|
+
# assert_generates "/items/list", controller: "items", action: "list"
|
65
72
|
#
|
66
73
|
# # Tests the generation of a route with a parameter
|
67
|
-
# assert_generates "/items/list/1", { :
|
74
|
+
# assert_generates "/items/list/1", { controller: "items", action: "list", id: "1" }
|
68
75
|
#
|
69
76
|
# # Asserts that the generated route gives us our custom route
|
70
|
-
# assert_generates "changesets/12", { :
|
71
|
-
def assert_generates(expected_path, options, defaults={}, extras
|
77
|
+
# assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" }
|
78
|
+
def assert_generates(expected_path, options, defaults={}, extras={}, message=nil)
|
72
79
|
if expected_path =~ %r{://}
|
73
|
-
|
80
|
+
fail_on(URI::InvalidURIError, message) do
|
74
81
|
uri = URI.parse(expected_path)
|
75
82
|
expected_path = uri.path.to_s.empty? ? "/" : uri.path
|
76
|
-
rescue URI::InvalidURIError => e
|
77
|
-
raise ActionController::RoutingError, e.message
|
78
83
|
end
|
79
84
|
else
|
80
85
|
expected_path = "/#{expected_path}" unless expected_path.first == '/'
|
@@ -82,12 +87,12 @@ module ActionDispatch
|
|
82
87
|
# Load routes.rb if it hasn't been loaded.
|
83
88
|
|
84
89
|
generated_path, extra_keys = @routes.generate_extras(options, defaults)
|
85
|
-
found_extras = options.reject {|k,
|
90
|
+
found_extras = options.reject { |k, _| ! extra_keys.include? k }
|
86
91
|
|
87
|
-
msg =
|
92
|
+
msg = message || sprintf("found extras <%s>, not <%s>", found_extras, extras)
|
88
93
|
assert_equal(extras, found_extras, msg)
|
89
94
|
|
90
|
-
msg =
|
95
|
+
msg = message || sprintf("The generated path <%s> did not match <%s>", generated_path,
|
91
96
|
expected_path)
|
92
97
|
assert_equal(expected_path, generated_path, msg)
|
93
98
|
end
|
@@ -99,21 +104,20 @@ module ActionDispatch
|
|
99
104
|
# The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
|
100
105
|
# +message+ parameter allows you to specify a custom error message to display upon failure.
|
101
106
|
#
|
102
|
-
# ==== Examples
|
103
107
|
# # Assert a basic route: a controller with the default action (index)
|
104
|
-
# assert_routing '/home', :
|
108
|
+
# assert_routing '/home', controller: 'home', action: 'index'
|
105
109
|
#
|
106
110
|
# # Test a route generated with a specific controller, action, and parameter (id)
|
107
|
-
# assert_routing '/entries/show/23', :
|
111
|
+
# assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23
|
108
112
|
#
|
109
113
|
# # Assert a basic route (controller + default action), with an error message if it fails
|
110
|
-
# assert_routing '/store', { :
|
114
|
+
# assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly'
|
111
115
|
#
|
112
116
|
# # Tests a route, providing a defaults hash
|
113
|
-
# assert_routing 'controller/action/9', {:
|
117
|
+
# assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"}
|
114
118
|
#
|
115
119
|
# # Tests a route with a HTTP method
|
116
|
-
# assert_routing({ :
|
120
|
+
# assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" })
|
117
121
|
def assert_routing(path, options, defaults={}, extras={}, message=nil)
|
118
122
|
assert_recognizes(options, path, extras, message)
|
119
123
|
|
@@ -122,7 +126,7 @@ module ActionDispatch
|
|
122
126
|
options[:controller] = "/#{controller}"
|
123
127
|
end
|
124
128
|
|
125
|
-
generate_options = options.dup.delete_if{ |k,
|
129
|
+
generate_options = options.dup.delete_if{ |k, _| defaults.key?(k) }
|
126
130
|
assert_generates(path.is_a?(Hash) ? path[:path] : path, generate_options, defaults, extras, message)
|
127
131
|
end
|
128
132
|
|
@@ -131,16 +135,13 @@ module ActionDispatch
|
|
131
135
|
# with a new RouteSet instance.
|
132
136
|
#
|
133
137
|
# The new instance is yielded to the passed block. Typically the block
|
134
|
-
# will create some routes using <tt>
|
138
|
+
# will create some routes using <tt>set.draw { match ... }</tt>:
|
135
139
|
#
|
136
140
|
# with_routing do |set|
|
137
|
-
# set.draw do
|
138
|
-
#
|
139
|
-
# assert_equal(
|
140
|
-
# ['/content/10/show', {}],
|
141
|
-
# map.generate(:controller => 'content', :id => 10, :action => 'show')
|
142
|
-
# end
|
141
|
+
# set.draw do
|
142
|
+
# resources :users
|
143
143
|
# end
|
144
|
+
# assert_equal "/users", users_path
|
144
145
|
# end
|
145
146
|
#
|
146
147
|
def with_routing
|
@@ -149,12 +150,6 @@ module ActionDispatch
|
|
149
150
|
old_controller, @controller = @controller, @controller.clone
|
150
151
|
_routes = @routes
|
151
152
|
|
152
|
-
# Unfortunately, there is currently an abstraction leak between AC::Base
|
153
|
-
# and AV::Base which requires having the URL helpers in both AC and AV.
|
154
|
-
# To do this safely at runtime for tests, we need to bump up the helper serial
|
155
|
-
# to that the old AV subclass isn't cached.
|
156
|
-
#
|
157
|
-
# TODO: Make this unnecessary
|
158
153
|
@controller.singleton_class.send(:include, _routes.url_helpers)
|
159
154
|
@controller.view_context_class = Class.new(@controller.view_context_class) do
|
160
155
|
include _routes.url_helpers
|
@@ -170,7 +165,7 @@ module ActionDispatch
|
|
170
165
|
|
171
166
|
# ROUTES TODO: These assertions should really work in an integration context
|
172
167
|
def method_missing(selector, *args, &block)
|
173
|
-
if defined?(@controller) && @controller && @routes && @routes.named_routes.
|
168
|
+
if defined?(@controller) && @controller && defined?(@routes) && @routes && @routes.named_routes.route_defined?(selector)
|
174
169
|
@controller.send(selector, *args, &block)
|
175
170
|
else
|
176
171
|
super
|
@@ -179,7 +174,7 @@ module ActionDispatch
|
|
179
174
|
|
180
175
|
private
|
181
176
|
# Recognizes the route for a given path.
|
182
|
-
def recognized_request_for(path, extras = {})
|
177
|
+
def recognized_request_for(path, extras = {}, msg)
|
183
178
|
if path.is_a?(Hash)
|
184
179
|
method = path[:method]
|
185
180
|
path = path[:path]
|
@@ -191,14 +186,12 @@ module ActionDispatch
|
|
191
186
|
request = ActionController::TestRequest.new
|
192
187
|
|
193
188
|
if path =~ %r{://}
|
194
|
-
|
189
|
+
fail_on(URI::InvalidURIError, msg) do
|
195
190
|
uri = URI.parse(path)
|
196
191
|
request.env["rack.url_scheme"] = uri.scheme || "http"
|
197
192
|
request.host = uri.host if uri.host
|
198
193
|
request.port = uri.port if uri.port
|
199
194
|
request.path = uri.path.to_s.empty? ? "/" : uri.path
|
200
|
-
rescue URI::InvalidURIError => e
|
201
|
-
raise ActionController::RoutingError, e.message
|
202
195
|
end
|
203
196
|
else
|
204
197
|
path = "/#{path}" unless path.first == "/"
|
@@ -207,11 +200,19 @@ module ActionDispatch
|
|
207
200
|
|
208
201
|
request.request_method = method if method
|
209
202
|
|
210
|
-
params =
|
203
|
+
params = fail_on(ActionController::RoutingError, msg) do
|
204
|
+
@routes.recognize_path(path, { :method => method, :extras => extras })
|
205
|
+
end
|
211
206
|
request.path_parameters = params.with_indifferent_access
|
212
207
|
|
213
208
|
request
|
214
209
|
end
|
210
|
+
|
211
|
+
def fail_on(exception_class, message)
|
212
|
+
yield
|
213
|
+
rescue exception_class => e
|
214
|
+
raise Minitest::Assertion, message || e.message
|
215
|
+
end
|
215
216
|
end
|
216
217
|
end
|
217
218
|
end
|
@@ -1,435 +1,3 @@
|
|
1
|
-
require '
|
2
|
-
require 'active_support/core_ext/object/inclusion'
|
1
|
+
require 'active_support/deprecation'
|
3
2
|
|
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
|
3
|
+
ActiveSupport::Deprecation.warn("ActionDispatch::Assertions::SelectorAssertions has been extracted to the rails-dom-testing gem.")
|