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,138 +1,3 @@
|
|
1
|
-
require '
|
1
|
+
require 'active_support/deprecation'
|
2
2
|
|
3
|
-
|
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
|
3
|
+
ActiveSupport::Deprecation.warn('`ActionDispatch::Assertions::TagAssertions` has been extracted to the rails-dom-testing gem.')
|
@@ -1,18 +1,22 @@
|
|
1
|
+
require 'rails-dom-testing'
|
2
|
+
|
1
3
|
module ActionDispatch
|
2
4
|
module Assertions
|
3
|
-
autoload :DomAssertions, 'action_dispatch/testing/assertions/dom'
|
4
5
|
autoload :ResponseAssertions, 'action_dispatch/testing/assertions/response'
|
5
6
|
autoload :RoutingAssertions, 'action_dispatch/testing/assertions/routing'
|
6
|
-
autoload :SelectorAssertions, 'action_dispatch/testing/assertions/selector'
|
7
|
-
autoload :TagAssertions, 'action_dispatch/testing/assertions/tag'
|
8
7
|
|
9
8
|
extend ActiveSupport::Concern
|
10
9
|
|
11
|
-
include DomAssertions
|
12
10
|
include ResponseAssertions
|
13
11
|
include RoutingAssertions
|
14
|
-
include
|
15
|
-
|
12
|
+
include Rails::Dom::Testing::Assertions
|
13
|
+
|
14
|
+
def html_document
|
15
|
+
@html_document ||= if @response.content_type.to_s =~ /xml$/
|
16
|
+
Nokogiri::XML::Document.parse(@response.body)
|
17
|
+
else
|
18
|
+
Nokogiri::HTML::Document.parse(@response.body)
|
19
|
+
end
|
20
|
+
end
|
16
21
|
end
|
17
22
|
end
|
18
|
-
|
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'stringio'
|
2
2
|
require 'uri'
|
3
3
|
require 'active_support/core_ext/kernel/singleton_class'
|
4
|
-
require 'active_support/core_ext/object/inclusion'
|
5
4
|
require 'active_support/core_ext/object/try'
|
6
5
|
require 'rack/test'
|
7
|
-
require '
|
6
|
+
require 'minitest'
|
8
7
|
|
9
8
|
module ActionDispatch
|
10
9
|
module Integration #:nodoc:
|
@@ -18,56 +17,62 @@ module ActionDispatch
|
|
18
17
|
# a Hash, or a String that is appropriately encoded
|
19
18
|
# (<tt>application/x-www-form-urlencoded</tt> or
|
20
19
|
# <tt>multipart/form-data</tt>).
|
21
|
-
# - +
|
20
|
+
# - +headers_or_env+: Additional headers to pass, as a Hash. The headers will be
|
22
21
|
# merged into the Rack env hash.
|
23
22
|
#
|
24
|
-
# This method returns
|
23
|
+
# This method returns a Response object, which one can use to
|
25
24
|
# inspect the details of the response. Furthermore, if this method was
|
26
25
|
# called from an ActionDispatch::IntegrationTest object, then that
|
27
26
|
# object's <tt>@response</tt> instance variable will point to the same
|
28
27
|
# response object.
|
29
28
|
#
|
30
|
-
# You can also perform POST, PUT, DELETE, and HEAD requests with
|
31
|
-
# +#put+, +#delete+, and +#head+.
|
32
|
-
def get(path, parameters = nil,
|
33
|
-
process :get, path, parameters,
|
29
|
+
# You can also perform POST, PATCH, PUT, DELETE, and HEAD requests with
|
30
|
+
# +#post+, +#patch+, +#put+, +#delete+, and +#head+.
|
31
|
+
def get(path, parameters = nil, headers_or_env = nil)
|
32
|
+
process :get, path, parameters, headers_or_env
|
34
33
|
end
|
35
34
|
|
36
35
|
# Performs a POST request with the given parameters. See +#get+ for more
|
37
36
|
# details.
|
38
|
-
def post(path, parameters = nil,
|
39
|
-
process :post, path, parameters,
|
37
|
+
def post(path, parameters = nil, headers_or_env = nil)
|
38
|
+
process :post, path, parameters, headers_or_env
|
39
|
+
end
|
40
|
+
|
41
|
+
# Performs a PATCH request with the given parameters. See +#get+ for more
|
42
|
+
# details.
|
43
|
+
def patch(path, parameters = nil, headers_or_env = nil)
|
44
|
+
process :patch, path, parameters, headers_or_env
|
40
45
|
end
|
41
46
|
|
42
47
|
# Performs a PUT request with the given parameters. See +#get+ for more
|
43
48
|
# details.
|
44
|
-
def put(path, parameters = nil,
|
45
|
-
process :put, path, parameters,
|
49
|
+
def put(path, parameters = nil, headers_or_env = nil)
|
50
|
+
process :put, path, parameters, headers_or_env
|
46
51
|
end
|
47
52
|
|
48
53
|
# Performs a DELETE request with the given parameters. See +#get+ for
|
49
54
|
# more details.
|
50
|
-
def delete(path, parameters = nil,
|
51
|
-
process :delete, path, parameters,
|
55
|
+
def delete(path, parameters = nil, headers_or_env = nil)
|
56
|
+
process :delete, path, parameters, headers_or_env
|
52
57
|
end
|
53
58
|
|
54
59
|
# Performs a HEAD request with the given parameters. See +#get+ for more
|
55
60
|
# details.
|
56
|
-
def head(path, parameters = nil,
|
57
|
-
process :head, path, parameters,
|
61
|
+
def head(path, parameters = nil, headers_or_env = nil)
|
62
|
+
process :head, path, parameters, headers_or_env
|
58
63
|
end
|
59
64
|
|
60
65
|
# Performs an XMLHttpRequest request with the given parameters, mirroring
|
61
66
|
# a request from the Prototype library.
|
62
67
|
#
|
63
|
-
# The request_method is +:get+, +:post+, +:put+, +:delete+ or
|
64
|
-
# parameters are +nil+, a hash, or a url-encoded or multipart
|
65
|
-
# the headers are a hash.
|
66
|
-
def xml_http_request(request_method, path, parameters = nil,
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
process(request_method, path, parameters,
|
68
|
+
# The request_method is +:get+, +:post+, +:patch+, +:put+, +:delete+ or
|
69
|
+
# +:head+; the parameters are +nil+, a hash, or a url-encoded or multipart
|
70
|
+
# string; the headers are a hash.
|
71
|
+
def xml_http_request(request_method, path, parameters = nil, headers_or_env = nil)
|
72
|
+
headers_or_env ||= {}
|
73
|
+
headers_or_env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
74
|
+
headers_or_env['HTTP_ACCEPT'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
|
75
|
+
process(request_method, path, parameters, headers_or_env)
|
71
76
|
end
|
72
77
|
alias xhr :xml_http_request
|
73
78
|
|
@@ -84,34 +89,40 @@ module ActionDispatch
|
|
84
89
|
# redirect. Note that the redirects are followed until the response is
|
85
90
|
# not a redirect--this means you may run into an infinite loop if your
|
86
91
|
# redirect loops back to itself.
|
87
|
-
def request_via_redirect(http_method, path, parameters = nil,
|
88
|
-
process(http_method, path, parameters,
|
92
|
+
def request_via_redirect(http_method, path, parameters = nil, headers_or_env = nil)
|
93
|
+
process(http_method, path, parameters, headers_or_env)
|
89
94
|
follow_redirect! while redirect?
|
90
95
|
status
|
91
96
|
end
|
92
97
|
|
93
98
|
# Performs a GET request, following any subsequent redirect.
|
94
99
|
# See +request_via_redirect+ for more information.
|
95
|
-
def get_via_redirect(path, parameters = nil,
|
96
|
-
request_via_redirect(:get, path, parameters,
|
100
|
+
def get_via_redirect(path, parameters = nil, headers_or_env = nil)
|
101
|
+
request_via_redirect(:get, path, parameters, headers_or_env)
|
97
102
|
end
|
98
103
|
|
99
104
|
# Performs a POST request, following any subsequent redirect.
|
100
105
|
# See +request_via_redirect+ for more information.
|
101
|
-
def post_via_redirect(path, parameters = nil,
|
102
|
-
request_via_redirect(:post, path, parameters,
|
106
|
+
def post_via_redirect(path, parameters = nil, headers_or_env = nil)
|
107
|
+
request_via_redirect(:post, path, parameters, headers_or_env)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Performs a PATCH request, following any subsequent redirect.
|
111
|
+
# See +request_via_redirect+ for more information.
|
112
|
+
def patch_via_redirect(path, parameters = nil, headers_or_env = nil)
|
113
|
+
request_via_redirect(:patch, path, parameters, headers_or_env)
|
103
114
|
end
|
104
115
|
|
105
116
|
# Performs a PUT request, following any subsequent redirect.
|
106
117
|
# See +request_via_redirect+ for more information.
|
107
|
-
def put_via_redirect(path, parameters = nil,
|
108
|
-
request_via_redirect(:put, path, parameters,
|
118
|
+
def put_via_redirect(path, parameters = nil, headers_or_env = nil)
|
119
|
+
request_via_redirect(:put, path, parameters, headers_or_env)
|
109
120
|
end
|
110
121
|
|
111
122
|
# Performs a DELETE request, following any subsequent redirect.
|
112
123
|
# See +request_via_redirect+ for more information.
|
113
|
-
def delete_via_redirect(path, parameters = nil,
|
114
|
-
request_via_redirect(:delete, path, parameters,
|
124
|
+
def delete_via_redirect(path, parameters = nil, headers_or_env = nil)
|
125
|
+
request_via_redirect(:delete, path, parameters, headers_or_env)
|
115
126
|
end
|
116
127
|
end
|
117
128
|
|
@@ -126,7 +137,7 @@ module ActionDispatch
|
|
126
137
|
class Session
|
127
138
|
DEFAULT_HOST = "www.example.com"
|
128
139
|
|
129
|
-
include
|
140
|
+
include Minitest::Assertions
|
130
141
|
include TestProcess, RequestHelpers, Assertions
|
131
142
|
|
132
143
|
%w( status status_message headers body redirect? ).each do |method|
|
@@ -178,8 +189,8 @@ module ActionDispatch
|
|
178
189
|
# This makes app.url_for and app.foo_path available in the console
|
179
190
|
if app.respond_to?(:routes)
|
180
191
|
singleton_class.class_eval do
|
181
|
-
include app.routes.url_helpers
|
182
|
-
include app.routes.mounted_helpers
|
192
|
+
include app.routes.url_helpers
|
193
|
+
include app.routes.mounted_helpers
|
183
194
|
end
|
184
195
|
end
|
185
196
|
|
@@ -190,7 +201,7 @@ module ActionDispatch
|
|
190
201
|
@url_options ||= default_url_options.dup.tap do |url_options|
|
191
202
|
url_options.reverse_merge!(controller.url_options) if controller
|
192
203
|
|
193
|
-
if @app.respond_to?(:routes)
|
204
|
+
if @app.respond_to?(:routes)
|
194
205
|
url_options.reverse_merge!(@app.routes.default_url_options)
|
195
206
|
end
|
196
207
|
|
@@ -231,7 +242,7 @@ module ActionDispatch
|
|
231
242
|
@https = flag
|
232
243
|
end
|
233
244
|
|
234
|
-
#
|
245
|
+
# Returns +true+ if the session is mimicking a secure HTTPS request.
|
235
246
|
#
|
236
247
|
# if session.https?
|
237
248
|
# ...
|
@@ -251,21 +262,14 @@ module ActionDispatch
|
|
251
262
|
end
|
252
263
|
|
253
264
|
# Performs the actual request.
|
254
|
-
def process(method, path, parameters = nil,
|
255
|
-
rack_env ||= {}
|
265
|
+
def process(method, path, parameters = nil, headers_or_env = nil)
|
256
266
|
if path =~ %r{://}
|
257
267
|
location = URI.parse(path)
|
258
268
|
https! URI::HTTPS === location if location.scheme
|
259
|
-
host! location.host if location.host
|
269
|
+
host! "#{location.host}:#{location.port}" if location.host
|
260
270
|
path = location.query ? "#{location.path}?#{location.query}" : location.path
|
261
271
|
end
|
262
272
|
|
263
|
-
unless ActionController::Base < ActionController::Testing
|
264
|
-
ActionController::Base.class_eval do
|
265
|
-
include ActionController::Testing
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
273
|
hostname, port = host.split(':')
|
270
274
|
|
271
275
|
env = {
|
@@ -283,32 +287,31 @@ module ActionDispatch
|
|
283
287
|
"CONTENT_TYPE" => "application/x-www-form-urlencoded",
|
284
288
|
"HTTP_ACCEPT" => accept
|
285
289
|
}
|
290
|
+
# this modifies the passed env directly
|
291
|
+
Http::Headers.new(env).merge!(headers_or_env || {})
|
286
292
|
|
287
293
|
session = Rack::Test::Session.new(_mock_session)
|
288
294
|
|
289
|
-
env.merge!(rack_env)
|
290
|
-
|
291
295
|
# NOTE: rack-test v0.5 doesn't build a default uri correctly
|
292
296
|
# Make sure requested path is always a full uri
|
293
|
-
|
294
|
-
uri.scheme ||= env['rack.url_scheme']
|
295
|
-
uri.host ||= env['SERVER_NAME']
|
296
|
-
uri.port ||= env['SERVER_PORT'].try(:to_i)
|
297
|
-
uri += path
|
298
|
-
|
299
|
-
session.request(uri.to_s, env)
|
297
|
+
session.request(build_full_uri(path, env), env)
|
300
298
|
|
301
299
|
@request_count += 1
|
302
300
|
@request = ActionDispatch::Request.new(session.last_request.env)
|
303
301
|
response = _mock_session.last_response
|
304
|
-
@response = ActionDispatch::TestResponse.
|
302
|
+
@response = ActionDispatch::TestResponse.from_response(response)
|
305
303
|
@html_document = nil
|
304
|
+
@html_scanner_document = nil
|
306
305
|
@url_options = nil
|
307
306
|
|
308
307
|
@controller = session.last_request.env['action_controller.instance']
|
309
308
|
|
310
309
|
return response.status
|
311
310
|
end
|
311
|
+
|
312
|
+
def build_full_uri(path, env)
|
313
|
+
"#{env['rack.url_scheme']}://#{env['SERVER_NAME']}:#{env['SERVER_PORT']}#{path}"
|
314
|
+
end
|
312
315
|
end
|
313
316
|
|
314
317
|
module Runner
|
@@ -324,12 +327,22 @@ module ActionDispatch
|
|
324
327
|
@integration_session = Integration::Session.new(app)
|
325
328
|
end
|
326
329
|
|
327
|
-
|
330
|
+
def remove! # :nodoc:
|
331
|
+
@integration_session = nil
|
332
|
+
end
|
333
|
+
|
334
|
+
%w(get post patch put head delete cookies assigns
|
328
335
|
xml_http_request xhr get_via_redirect post_via_redirect).each do |method|
|
329
336
|
define_method(method) do |*args|
|
330
337
|
reset! unless integration_session
|
331
|
-
|
332
|
-
|
338
|
+
|
339
|
+
# reset the html_document variable, except for cookies/assigns calls
|
340
|
+
unless method == 'cookies' || method == 'assigns'
|
341
|
+
@html_document = nil
|
342
|
+
@html_scanner_document = nil
|
343
|
+
reset_template_assertion
|
344
|
+
end
|
345
|
+
|
333
346
|
integration_session.__send__(method, *args).tap do
|
334
347
|
copy_session_variables!
|
335
348
|
end
|
@@ -346,8 +359,9 @@ module ActionDispatch
|
|
346
359
|
# By default, a single session is automatically created for you, but you
|
347
360
|
# can use this method to open multiple sessions that ought to be tested
|
348
361
|
# simultaneously.
|
349
|
-
def open_session
|
362
|
+
def open_session
|
350
363
|
dup.tap do |session|
|
364
|
+
session.reset!
|
351
365
|
yield session if block_given?
|
352
366
|
end
|
353
367
|
end
|
@@ -367,7 +381,7 @@ module ActionDispatch
|
|
367
381
|
end
|
368
382
|
|
369
383
|
def default_url_options=(options)
|
370
|
-
integration_session
|
384
|
+
reset! unless integration_session
|
371
385
|
integration_session.default_url_options = options
|
372
386
|
end
|
373
387
|
|
@@ -413,8 +427,8 @@ module ActionDispatch
|
|
413
427
|
# assert_equal 200, status
|
414
428
|
#
|
415
429
|
# # post the login and follow through to the home page
|
416
|
-
# post "/login", :
|
417
|
-
# :
|
430
|
+
# post "/login", username: people(:jamis).username,
|
431
|
+
# password: people(:jamis).password
|
418
432
|
# follow_redirect!
|
419
433
|
# assert_equal 200, status
|
420
434
|
# assert_equal "/home", path
|
@@ -447,13 +461,13 @@ module ActionDispatch
|
|
447
461
|
# module CustomAssertions
|
448
462
|
# def enter(room)
|
449
463
|
# # reference a named route, for maximum internal consistency!
|
450
|
-
# get(room_url(:
|
464
|
+
# get(room_url(id: room.id))
|
451
465
|
# assert(...)
|
452
466
|
# ...
|
453
467
|
# end
|
454
468
|
#
|
455
469
|
# def speak(room, message)
|
456
|
-
# xml_http_request "/say/#{room.id}", :
|
470
|
+
# xml_http_request "/say/#{room.id}", message: message
|
457
471
|
# assert(...)
|
458
472
|
# ...
|
459
473
|
# end
|
@@ -463,8 +477,8 @@ module ActionDispatch
|
|
463
477
|
# open_session do |sess|
|
464
478
|
# sess.extend(CustomAssertions)
|
465
479
|
# who = people(who)
|
466
|
-
# sess.post "/login", :
|
467
|
-
# :
|
480
|
+
# sess.post "/login", username: who.username,
|
481
|
+
# password: who.password
|
468
482
|
# assert(...)
|
469
483
|
# end
|
470
484
|
# end
|
@@ -477,9 +491,7 @@ module ActionDispatch
|
|
477
491
|
@@app = nil
|
478
492
|
|
479
493
|
def self.app
|
480
|
-
|
481
|
-
# This should be set by the initializer
|
482
|
-
@@app || (defined?(Rails.application) && Rails.application) || nil
|
494
|
+
@@app || ActionDispatch.test_app
|
483
495
|
end
|
484
496
|
|
485
497
|
def self.app=(app)
|
@@ -494,5 +506,9 @@ module ActionDispatch
|
|
494
506
|
reset! unless integration_session
|
495
507
|
integration_session.url_options
|
496
508
|
end
|
509
|
+
|
510
|
+
def document_root_element
|
511
|
+
html_document.root
|
512
|
+
end
|
497
513
|
end
|
498
514
|
end
|
@@ -5,7 +5,8 @@ require 'active_support/core_ext/hash/indifferent_access'
|
|
5
5
|
module ActionDispatch
|
6
6
|
module TestProcess
|
7
7
|
def assigns(key = nil)
|
8
|
-
assigns =
|
8
|
+
assigns = {}.with_indifferent_access
|
9
|
+
@controller.view_assigns.each { |k, v| assigns.regular_writer(k, v) }
|
9
10
|
key.nil? ? assigns : assigns[key]
|
10
11
|
end
|
11
12
|
|
@@ -25,17 +26,19 @@ module ActionDispatch
|
|
25
26
|
@response.redirect_url
|
26
27
|
end
|
27
28
|
|
28
|
-
# Shortcut for <tt>Rack::Test::UploadedFile.new(ActionController::TestCase.fixture_path
|
29
|
+
# Shortcut for <tt>Rack::Test::UploadedFile.new(File.join(ActionController::TestCase.fixture_path, path), type)</tt>:
|
29
30
|
#
|
30
|
-
# post :change_avatar, :
|
31
|
+
# post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png')
|
31
32
|
#
|
32
33
|
# To upload binary files on Windows, pass <tt>:binary</tt> as the last parameter.
|
33
34
|
# This will not affect other platforms:
|
34
35
|
#
|
35
|
-
# post :change_avatar, :
|
36
|
+
# post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png', :binary)
|
36
37
|
def fixture_file_upload(path, mime_type = nil, binary = false)
|
37
|
-
|
38
|
-
|
38
|
+
if self.class.respond_to?(:fixture_path) && self.class.fixture_path
|
39
|
+
path = File.join(self.class.fixture_path, path)
|
40
|
+
end
|
41
|
+
Rack::Test::UploadedFile.new(path, mime_type, binary)
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
@@ -1,11 +1,13 @@
|
|
1
|
-
require 'active_support/core_ext/object/blank'
|
2
1
|
require 'active_support/core_ext/hash/indifferent_access'
|
3
|
-
require 'active_support/core_ext/hash/reverse_merge'
|
4
2
|
require 'rack/utils'
|
5
3
|
|
6
4
|
module ActionDispatch
|
7
5
|
class TestRequest < Request
|
8
|
-
DEFAULT_ENV = Rack::MockRequest.env_for('/'
|
6
|
+
DEFAULT_ENV = Rack::MockRequest.env_for('/',
|
7
|
+
'HTTP_HOST' => 'test.host',
|
8
|
+
'REMOTE_ADDR' => '0.0.0.0',
|
9
|
+
'HTTP_USER_AGENT' => 'Rails Testing'
|
10
|
+
)
|
9
11
|
|
10
12
|
def self.new(env = {})
|
11
13
|
super
|
@@ -13,11 +15,7 @@ module ActionDispatch
|
|
13
15
|
|
14
16
|
def initialize(env = {})
|
15
17
|
env = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application
|
16
|
-
super(
|
17
|
-
|
18
|
-
self.host = 'test.host'
|
19
|
-
self.remote_addr = '0.0.0.0'
|
20
|
-
self.user_agent = 'Rails Testing'
|
18
|
+
super(default_env.merge(env))
|
21
19
|
end
|
22
20
|
|
23
21
|
def request_method=(method)
|
@@ -41,7 +39,7 @@ module ActionDispatch
|
|
41
39
|
end
|
42
40
|
|
43
41
|
def action=(action_name)
|
44
|
-
path_parameters[
|
42
|
+
path_parameters[:action] = action_name.to_s
|
45
43
|
end
|
46
44
|
|
47
45
|
def if_modified_since=(last_modified)
|
@@ -70,5 +68,11 @@ module ActionDispatch
|
|
70
68
|
def cookies
|
71
69
|
@cookies ||= {}.with_indifferent_access
|
72
70
|
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def default_env
|
75
|
+
DEFAULT_ENV
|
76
|
+
end
|
73
77
|
end
|
74
78
|
end
|
@@ -7,11 +7,7 @@ module ActionDispatch
|
|
7
7
|
# See Response for more information on controller response objects.
|
8
8
|
class TestResponse < Response
|
9
9
|
def self.from_response(response)
|
10
|
-
new.
|
11
|
-
resp.status = response.status
|
12
|
-
resp.headers = response.headers
|
13
|
-
resp.body = response.body
|
14
|
-
end
|
10
|
+
new response.status, response.headers, response.body, default_headers: nil
|
15
11
|
end
|
16
12
|
|
17
13
|
# Was the response successful?
|