actionpack 5.1.7 → 5.2.0.beta1
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 +5 -5
- data/CHANGELOG.md +132 -490
- data/README.rdoc +1 -1
- data/lib/abstract_controller.rb +2 -0
- data/lib/abstract_controller/asset_paths.rb +2 -0
- data/lib/abstract_controller/base.rb +10 -2
- data/lib/abstract_controller/caching.rb +3 -2
- data/lib/abstract_controller/caching/fragments.rb +30 -7
- data/lib/abstract_controller/callbacks.rb +25 -3
- data/lib/abstract_controller/collector.rb +2 -0
- data/lib/abstract_controller/error.rb +2 -0
- data/lib/abstract_controller/helpers.rb +4 -5
- data/lib/abstract_controller/logger.rb +2 -0
- data/lib/abstract_controller/railties/routes_helpers.rb +2 -0
- data/lib/abstract_controller/rendering.rb +9 -16
- data/lib/abstract_controller/translation.rb +2 -0
- data/lib/abstract_controller/url_for.rb +2 -0
- data/lib/action_controller.rb +3 -0
- data/lib/action_controller/api.rb +2 -0
- data/lib/action_controller/api/api_rendering.rb +2 -0
- data/lib/action_controller/base.rb +3 -0
- data/lib/action_controller/caching.rb +2 -0
- data/lib/action_controller/form_builder.rb +2 -0
- data/lib/action_controller/log_subscriber.rb +5 -3
- data/lib/action_controller/metal.rb +3 -2
- data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
- data/lib/action_controller/metal/conditional_get.rb +4 -3
- data/lib/action_controller/metal/content_security_policy.rb +26 -0
- data/lib/action_controller/metal/cookies.rb +2 -0
- data/lib/action_controller/metal/data_streaming.rb +7 -5
- data/lib/action_controller/metal/etag_with_flash.rb +2 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +3 -2
- data/lib/action_controller/metal/exceptions.rb +2 -3
- data/lib/action_controller/metal/flash.rb +3 -2
- data/lib/action_controller/metal/force_ssl.rb +2 -0
- data/lib/action_controller/metal/head.rb +2 -0
- data/lib/action_controller/metal/helpers.rb +4 -3
- data/lib/action_controller/metal/http_authentication.rb +8 -9
- data/lib/action_controller/metal/implicit_render.rb +2 -0
- data/lib/action_controller/metal/instrumentation.rb +4 -6
- data/lib/action_controller/metal/live.rb +3 -1
- data/lib/action_controller/metal/mime_responds.rb +3 -1
- data/lib/action_controller/metal/parameter_encoding.rb +2 -0
- data/lib/action_controller/metal/params_wrapper.rb +13 -9
- data/lib/action_controller/metal/redirecting.rb +21 -10
- data/lib/action_controller/metal/renderers.rb +4 -3
- data/lib/action_controller/metal/rendering.rb +2 -2
- data/lib/action_controller/metal/request_forgery_protection.rb +22 -6
- data/lib/action_controller/metal/rescue.rb +5 -3
- data/lib/action_controller/metal/streaming.rb +2 -0
- data/lib/action_controller/metal/strong_parameters.rb +19 -11
- data/lib/action_controller/metal/testing.rb +2 -6
- data/lib/action_controller/metal/url_for.rb +2 -0
- data/lib/action_controller/railtie.rb +16 -4
- data/lib/action_controller/railties/helpers.rb +2 -0
- data/lib/action_controller/renderer.rb +2 -0
- data/lib/action_controller/template_assertions.rb +2 -0
- data/lib/action_controller/test_case.rb +4 -1
- data/lib/action_dispatch.rb +3 -0
- data/lib/action_dispatch/http/cache.rb +15 -9
- data/lib/action_dispatch/http/content_security_policy.rb +233 -0
- data/lib/action_dispatch/http/filter_parameters.rb +4 -2
- data/lib/action_dispatch/http/filter_redirect.rb +2 -0
- data/lib/action_dispatch/http/headers.rb +2 -0
- data/lib/action_dispatch/http/mime_negotiation.rb +4 -13
- data/lib/action_dispatch/http/mime_type.rb +15 -13
- data/lib/action_dispatch/http/mime_types.rb +4 -2
- data/lib/action_dispatch/http/parameter_filter.rb +2 -0
- data/lib/action_dispatch/http/parameters.rb +6 -9
- data/lib/action_dispatch/http/rack_cache.rb +2 -0
- data/lib/action_dispatch/http/request.rb +36 -16
- data/lib/action_dispatch/http/response.rb +11 -9
- data/lib/action_dispatch/http/upload.rb +2 -0
- data/lib/action_dispatch/http/url.rb +4 -5
- data/lib/action_dispatch/journey.rb +2 -0
- data/lib/action_dispatch/journey/formatter.rb +4 -2
- data/lib/action_dispatch/journey/gtg/builder.rb +2 -0
- data/lib/action_dispatch/journey/gtg/simulator.rb +2 -8
- data/lib/action_dispatch/journey/gtg/transition_table.rb +3 -2
- data/lib/action_dispatch/journey/nfa/builder.rb +2 -0
- data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
- data/lib/action_dispatch/journey/nfa/simulator.rb +2 -0
- data/lib/action_dispatch/journey/nfa/transition_table.rb +2 -0
- data/lib/action_dispatch/journey/nodes/node.rb +2 -0
- data/lib/action_dispatch/journey/parser_extras.rb +2 -0
- data/lib/action_dispatch/journey/path/pattern.rb +2 -0
- data/lib/action_dispatch/journey/route.rb +15 -6
- data/lib/action_dispatch/journey/router.rb +3 -1
- data/lib/action_dispatch/journey/router/utils.rb +14 -7
- data/lib/action_dispatch/journey/routes.rb +2 -1
- data/lib/action_dispatch/journey/scanner.rb +1 -0
- data/lib/action_dispatch/journey/visitors.rb +5 -3
- data/lib/action_dispatch/middleware/callbacks.rb +2 -0
- data/lib/action_dispatch/middleware/cookies.rb +141 -91
- data/lib/action_dispatch/middleware/debug_exceptions.rb +4 -2
- data/lib/action_dispatch/middleware/debug_locks.rb +9 -7
- data/lib/action_dispatch/middleware/exception_wrapper.rb +4 -6
- data/lib/action_dispatch/middleware/executor.rb +2 -0
- data/lib/action_dispatch/middleware/flash.rb +3 -1
- data/lib/action_dispatch/middleware/public_exceptions.rb +6 -4
- data/lib/action_dispatch/middleware/reloader.rb +2 -0
- data/lib/action_dispatch/middleware/remote_ip.rb +7 -5
- data/lib/action_dispatch/middleware/request_id.rb +2 -0
- data/lib/action_dispatch/middleware/session/abstract_store.rb +3 -1
- data/lib/action_dispatch/middleware/session/cache_store.rb +2 -0
- data/lib/action_dispatch/middleware/session/cookie_store.rb +13 -25
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +2 -0
- data/lib/action_dispatch/middleware/show_exceptions.rb +3 -1
- data/lib/action_dispatch/middleware/ssl.rb +42 -37
- data/lib/action_dispatch/middleware/stack.rb +2 -0
- data/lib/action_dispatch/middleware/static.rb +10 -8
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +1 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +6 -2
- data/lib/action_dispatch/railtie.rb +7 -0
- data/lib/action_dispatch/request/session.rb +8 -4
- data/lib/action_dispatch/request/utils.rb +4 -4
- data/lib/action_dispatch/routing.rb +3 -1
- data/lib/action_dispatch/routing/endpoint.rb +8 -4
- data/lib/action_dispatch/routing/inspector.rb +5 -3
- data/lib/action_dispatch/routing/mapper.rb +62 -51
- data/lib/action_dispatch/routing/polymorphic_routes.rb +2 -0
- data/lib/action_dispatch/routing/redirection.rb +7 -5
- data/lib/action_dispatch/routing/route_set.rb +26 -33
- data/lib/action_dispatch/routing/routes_proxy.rb +5 -2
- data/lib/action_dispatch/routing/url_for.rb +6 -4
- data/lib/action_dispatch/system_test_case.rb +14 -6
- data/lib/action_dispatch/system_testing/driver.rb +20 -2
- data/lib/action_dispatch/system_testing/server.rb +2 -16
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +6 -4
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
- data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
- data/lib/action_dispatch/testing/assertion_response.rb +2 -0
- data/lib/action_dispatch/testing/assertions.rb +2 -0
- data/lib/action_dispatch/testing/assertions/response.rb +4 -2
- data/lib/action_dispatch/testing/assertions/routing.rb +5 -5
- data/lib/action_dispatch/testing/integration.rb +24 -21
- data/lib/action_dispatch/testing/request_encoder.rb +2 -0
- data/lib/action_dispatch/testing/test_process.rb +2 -0
- data/lib/action_dispatch/testing/test_request.rb +3 -1
- data/lib/action_dispatch/testing/test_response.rb +23 -3
- data/lib/action_pack.rb +2 -0
- data/lib/action_pack/gem_version.rb +5 -3
- data/lib/action_pack/version.rb +2 -0
- metadata +17 -13
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "action_dispatch/http/request"
|
2
4
|
require "active_support/core_ext/uri"
|
3
5
|
require "active_support/core_ext/array/extract_options"
|
@@ -140,13 +142,13 @@ module ActionDispatch
|
|
140
142
|
# get "/stories" => redirect("/posts")
|
141
143
|
#
|
142
144
|
# This will redirect the user, while ignoring certain parts of the request, including query string, etc.
|
143
|
-
#
|
145
|
+
# <tt>/stories</tt>, <tt>/stories?foo=bar</tt>, etc all redirect to <tt>/posts</tt>.
|
144
146
|
#
|
145
147
|
# You can also use interpolation in the supplied redirect argument:
|
146
148
|
#
|
147
149
|
# get 'docs/:article', to: redirect('/wiki/%{article}')
|
148
150
|
#
|
149
|
-
# Note that if you return a path without a leading slash then the
|
151
|
+
# Note that if you return a path without a leading slash then the URL is prefixed with the
|
150
152
|
# current SCRIPT_NAME environment variable. This is typically '/' but may be different in
|
151
153
|
# a mounted engine or where the application is deployed to a subdirectory of a website.
|
152
154
|
#
|
@@ -165,7 +167,7 @@ module ActionDispatch
|
|
165
167
|
# Note that the +do end+ syntax for the redirect block wouldn't work, as Ruby would pass
|
166
168
|
# the block to +get+ instead of +redirect+. Use <tt>{ ... }</tt> instead.
|
167
169
|
#
|
168
|
-
# The options version of redirect allows you to supply only the parts of the
|
170
|
+
# The options version of redirect allows you to supply only the parts of the URL which need
|
169
171
|
# to change, it also supports interpolation of the path similar to the first example.
|
170
172
|
#
|
171
173
|
# get 'stores/:name', to: redirect(subdomain: 'stores', path: '/%{name}')
|
@@ -173,8 +175,8 @@ module ActionDispatch
|
|
173
175
|
# get '/stories', to: redirect(path: '/posts')
|
174
176
|
#
|
175
177
|
# This will redirect the user, while changing only the specified parts of the request,
|
176
|
-
# for example the
|
177
|
-
#
|
178
|
+
# for example the +path+ option in the last example.
|
179
|
+
# <tt>/stories</tt>, <tt>/stories?foo=bar</tt>, redirect to <tt>/posts</tt> and <tt>/posts?foo=bar</tt> respectively.
|
178
180
|
#
|
179
181
|
# Finally, an object which responds to call can be supplied to redirect, allowing you to reuse
|
180
182
|
# common redirect routes. The call method must accept two arguments, params and request, and return
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "action_dispatch/journey"
|
2
4
|
require "active_support/core_ext/object/to_query"
|
3
5
|
require "active_support/core_ext/hash/slice"
|
6
|
+
require "active_support/core_ext/module/redefine_method"
|
4
7
|
require "active_support/core_ext/module/remove_method"
|
5
8
|
require "active_support/core_ext/array/extract_options"
|
6
9
|
require "action_controller/metal/exceptions"
|
@@ -73,7 +76,6 @@ module ActionDispatch
|
|
73
76
|
@routes = {}
|
74
77
|
@path_helpers = Set.new
|
75
78
|
@url_helpers = Set.new
|
76
|
-
@custom_helpers = Set.new
|
77
79
|
@url_helpers_module = Module.new
|
78
80
|
@path_helpers_module = Module.new
|
79
81
|
end
|
@@ -96,23 +98,9 @@ module ActionDispatch
|
|
96
98
|
@url_helpers_module.send :remove_method, helper
|
97
99
|
end
|
98
100
|
|
99
|
-
@custom_helpers.each do |helper|
|
100
|
-
path_name = :"#{helper}_path"
|
101
|
-
url_name = :"#{helper}_url"
|
102
|
-
|
103
|
-
if @path_helpers_module.method_defined?(path_name)
|
104
|
-
@path_helpers_module.send :remove_method, path_name
|
105
|
-
end
|
106
|
-
|
107
|
-
if @url_helpers_module.method_defined?(url_name)
|
108
|
-
@url_helpers_module.send :remove_method, url_name
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
101
|
@routes.clear
|
113
102
|
@path_helpers.clear
|
114
103
|
@url_helpers.clear
|
115
|
-
@custom_helpers.clear
|
116
104
|
end
|
117
105
|
|
118
106
|
def add(name, route)
|
@@ -158,21 +146,29 @@ module ActionDispatch
|
|
158
146
|
routes.length
|
159
147
|
end
|
160
148
|
|
149
|
+
# Given a +name+, defines name_path and name_url helpers.
|
150
|
+
# Used by 'direct', 'resolve', and 'polymorphic' route helpers.
|
161
151
|
def add_url_helper(name, defaults, &block)
|
162
|
-
@custom_helpers << name
|
163
152
|
helper = CustomUrlHelper.new(name, defaults, &block)
|
153
|
+
path_name = :"#{name}_path"
|
154
|
+
url_name = :"#{name}_url"
|
164
155
|
|
165
156
|
@path_helpers_module.module_eval do
|
166
|
-
define_method(
|
157
|
+
define_method(path_name) do |*args|
|
167
158
|
helper.call(self, args, true)
|
168
159
|
end
|
169
160
|
end
|
170
161
|
|
171
162
|
@url_helpers_module.module_eval do
|
172
|
-
define_method(
|
163
|
+
define_method(url_name) do |*args|
|
173
164
|
helper.call(self, args, false)
|
174
165
|
end
|
175
166
|
end
|
167
|
+
|
168
|
+
@path_helpers << path_name
|
169
|
+
@url_helpers << url_name
|
170
|
+
|
171
|
+
self
|
176
172
|
end
|
177
173
|
|
178
174
|
class UrlHelper
|
@@ -203,16 +199,6 @@ module ActionDispatch
|
|
203
199
|
if args.size == arg_size && !inner_options && optimize_routes_generation?(t)
|
204
200
|
options = t.url_options.merge @options
|
205
201
|
options[:path] = optimized_helper(args)
|
206
|
-
|
207
|
-
original_script_name = options.delete(:original_script_name)
|
208
|
-
script_name = t._routes.find_script_name(options)
|
209
|
-
|
210
|
-
if original_script_name
|
211
|
-
script_name = original_script_name + script_name
|
212
|
-
end
|
213
|
-
|
214
|
-
options[:script_name] = script_name
|
215
|
-
|
216
202
|
url_strategy.call options
|
217
203
|
else
|
218
204
|
super
|
@@ -250,7 +236,7 @@ module ActionDispatch
|
|
250
236
|
missing_keys << missing_key
|
251
237
|
}
|
252
238
|
constraints = Hash[@route.requirements.merge(params).sort_by { |k, v| k.to_s }]
|
253
|
-
message = "No route matches #{constraints.inspect}"
|
239
|
+
message = "No route matches #{constraints.inspect}".dup
|
254
240
|
message << ", missing required keys: #{missing_keys.sort.inspect}"
|
255
241
|
|
256
242
|
raise ActionController::UrlGenerationError, message
|
@@ -307,7 +293,7 @@ module ActionDispatch
|
|
307
293
|
end
|
308
294
|
|
309
295
|
private
|
310
|
-
# Create a
|
296
|
+
# Create a URL helper allowing ordered parameters to be associated
|
311
297
|
# with corresponding dynamic segments, so you can do:
|
312
298
|
#
|
313
299
|
# foo_url(bar, baz, bang)
|
@@ -561,7 +547,7 @@ module ActionDispatch
|
|
561
547
|
|
562
548
|
# plus a singleton class method called _routes ...
|
563
549
|
included do
|
564
|
-
|
550
|
+
redefine_singleton_method(:_routes) { routes }
|
565
551
|
end
|
566
552
|
|
567
553
|
# And an instance method _routes. Note that
|
@@ -598,14 +584,14 @@ module ActionDispatch
|
|
598
584
|
if route.segment_keys.include?(:controller)
|
599
585
|
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
600
586
|
Using a dynamic :controller segment in a route is deprecated and
|
601
|
-
will be removed in Rails
|
587
|
+
will be removed in Rails 6.0.
|
602
588
|
MSG
|
603
589
|
end
|
604
590
|
|
605
591
|
if route.segment_keys.include?(:action)
|
606
592
|
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
607
593
|
Using a dynamic :action segment in a route is deprecated and
|
608
|
-
will be removed in Rails
|
594
|
+
will be removed in Rails 6.0.
|
609
595
|
MSG
|
610
596
|
end
|
611
597
|
|
@@ -856,6 +842,10 @@ module ActionDispatch
|
|
856
842
|
end
|
857
843
|
|
858
844
|
req = make_request(env)
|
845
|
+
recognize_path_with_request(req, path, extras)
|
846
|
+
end
|
847
|
+
|
848
|
+
def recognize_path_with_request(req, path, extras)
|
859
849
|
@router.recognize(req) do |route, params|
|
860
850
|
params.merge!(extras)
|
861
851
|
params.each do |key, value|
|
@@ -874,6 +864,9 @@ module ActionDispatch
|
|
874
864
|
end
|
875
865
|
|
876
866
|
return req.path_parameters
|
867
|
+
elsif app.matches?(req) && app.engine?
|
868
|
+
path_parameters = app.rack_app.routes.recognize_path_with_request(req, path, extras)
|
869
|
+
return path_parameters
|
877
870
|
end
|
878
871
|
end
|
879
872
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/array/extract_options"
|
2
4
|
|
3
5
|
module ActionDispatch
|
@@ -20,7 +22,8 @@ module ActionDispatch
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
|
25
|
+
private
|
26
|
+
def respond_to_missing?(method, _)
|
24
27
|
super || @helpers.respond_to?(method)
|
25
28
|
end
|
26
29
|
|
@@ -42,7 +45,7 @@ module ActionDispatch
|
|
42
45
|
@helpers.#{method}(*args)
|
43
46
|
end
|
44
47
|
RUBY
|
45
|
-
|
48
|
+
public_send(method, *args)
|
46
49
|
else
|
47
50
|
super
|
48
51
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionDispatch
|
2
4
|
module Routing
|
3
5
|
# In <tt>config/routes.rb</tt> you define URL-to-controller mappings, but the reverse
|
@@ -107,16 +109,16 @@ module ActionDispatch
|
|
107
109
|
end
|
108
110
|
|
109
111
|
# Hook overridden in controller to add request information
|
110
|
-
# with
|
112
|
+
# with +default_url_options+. Application logic should not
|
111
113
|
# go into url_options.
|
112
114
|
def url_options
|
113
115
|
default_url_options
|
114
116
|
end
|
115
117
|
|
116
|
-
# Generate a
|
118
|
+
# Generate a URL based on the options provided, default_url_options and the
|
117
119
|
# routes defined in routes.rb. The following options are supported:
|
118
120
|
#
|
119
|
-
# * <tt>:only_path</tt> - If true, the relative
|
121
|
+
# * <tt>:only_path</tt> - If true, the relative URL is returned. Defaults to +false+.
|
120
122
|
# * <tt>:protocol</tt> - The protocol to connect to. Defaults to 'http'.
|
121
123
|
# * <tt>:host</tt> - Specifies the host the link should be targeted at.
|
122
124
|
# If <tt>:only_path</tt> is false, this option must be
|
@@ -153,7 +155,7 @@ module ActionDispatch
|
|
153
155
|
# Missing routes keys may be filled in from the current request's parameters
|
154
156
|
# (e.g. +:controller+, +:action+, +:id+ and any other parameters that are
|
155
157
|
# placed in the path). Given that the current action has been reached
|
156
|
-
# through
|
158
|
+
# through <tt>GET /users/1</tt>:
|
157
159
|
#
|
158
160
|
# url_for(only_path: true) # => '/users/1'
|
159
161
|
# url_for(only_path: true, action: 'edit') # => '/users/1/edit'
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
gem "capybara", "~> 2.15"
|
2
4
|
|
3
5
|
require "capybara/dsl"
|
4
6
|
require "capybara/minitest"
|
@@ -7,6 +9,7 @@ require "action_dispatch/system_testing/driver"
|
|
7
9
|
require "action_dispatch/system_testing/server"
|
8
10
|
require "action_dispatch/system_testing/test_helpers/screenshot_helper"
|
9
11
|
require "action_dispatch/system_testing/test_helpers/setup_and_teardown"
|
12
|
+
require "action_dispatch/system_testing/test_helpers/undef_methods"
|
10
13
|
|
11
14
|
module ActionDispatch
|
12
15
|
# = System Testing
|
@@ -51,7 +54,7 @@ module ActionDispatch
|
|
51
54
|
# By default, <tt>ActionDispatch::SystemTestCase</tt> is driven by the
|
52
55
|
# Selenium driver, with the Chrome browser, and a browser size of 1400x1400.
|
53
56
|
#
|
54
|
-
# Changing the driver configuration options
|
57
|
+
# Changing the driver configuration options is easy. Let's say you want to use
|
55
58
|
# the Firefox browser instead of Chrome. In your +application_system_test_case.rb+
|
56
59
|
# file add the following:
|
57
60
|
#
|
@@ -68,10 +71,10 @@ module ActionDispatch
|
|
68
71
|
#
|
69
72
|
# To use a headless driver, like Poltergeist, update your Gemfile to use
|
70
73
|
# Poltergeist instead of Selenium and then declare the driver name in the
|
71
|
-
# +application_system_test_case.rb+ file. In this case you would leave out
|
72
|
-
# option because the driver is headless, but you can still use
|
74
|
+
# +application_system_test_case.rb+ file. In this case, you would leave out
|
75
|
+
# the +:using+ option because the driver is headless, but you can still use
|
73
76
|
# +:screen_size+ to change the size of the browser screen, also you can use
|
74
|
-
# +:options+ to pass options supported by the driver. Please
|
77
|
+
# +:options+ to pass options supported by the driver. Please refer to your
|
75
78
|
# driver documentation to learn about supported options.
|
76
79
|
#
|
77
80
|
# require "test_helper"
|
@@ -79,7 +82,7 @@ module ActionDispatch
|
|
79
82
|
#
|
80
83
|
# class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
81
84
|
# driven_by :poltergeist, screen_size: [1400, 1400], options:
|
82
|
-
#
|
85
|
+
# { js_errors: true }
|
83
86
|
# end
|
84
87
|
#
|
85
88
|
# Because <tt>ActionDispatch::SystemTestCase</tt> is a shim between Capybara
|
@@ -90,6 +93,7 @@ module ActionDispatch
|
|
90
93
|
include Capybara::Minitest::Assertions
|
91
94
|
include SystemTesting::TestHelpers::SetupAndTeardown
|
92
95
|
include SystemTesting::TestHelpers::ScreenshotHelper
|
96
|
+
include SystemTesting::TestHelpers::UndefMethods
|
93
97
|
|
94
98
|
def initialize(*) # :nodoc:
|
95
99
|
super
|
@@ -119,12 +123,16 @@ module ActionDispatch
|
|
119
123
|
#
|
120
124
|
# driven_by :selenium, using: :firefox
|
121
125
|
#
|
126
|
+
# driven_by :selenium, using: :headless_chrome
|
127
|
+
#
|
122
128
|
# driven_by :selenium, screen_size: [800, 800]
|
123
129
|
def self.driven_by(driver, using: :chrome, screen_size: [1400, 1400], options: {})
|
124
130
|
self.driver = SystemTesting::Driver.new(driver, using: using, screen_size: screen_size, options: options)
|
125
131
|
end
|
126
132
|
|
127
133
|
driven_by :selenium
|
134
|
+
|
135
|
+
ActiveSupport.run_load_hooks(:action_dispatch_system_test_case, self)
|
128
136
|
end
|
129
137
|
|
130
138
|
SystemTestCase.start_application
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionDispatch
|
2
4
|
module SystemTesting
|
3
5
|
class Driver # :nodoc:
|
@@ -29,8 +31,24 @@ module ActionDispatch
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
34
|
+
def browser_options
|
35
|
+
if @browser == :headless_chrome
|
36
|
+
browser_options = Selenium::WebDriver::Chrome::Options.new
|
37
|
+
browser_options.args << "--headless"
|
38
|
+
browser_options.args << "--disable-gpu"
|
39
|
+
|
40
|
+
@options.merge(options: browser_options)
|
41
|
+
else
|
42
|
+
@options
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def browser
|
47
|
+
@browser == :headless_chrome ? :chrome : @browser
|
48
|
+
end
|
49
|
+
|
32
50
|
def register_selenium(app)
|
33
|
-
Capybara::Selenium::Driver.new(app, { browser:
|
51
|
+
Capybara::Selenium::Driver.new(app, { browser: browser }.merge(browser_options)).tap do |driver|
|
34
52
|
driver.browser.manage.window.size = Selenium::WebDriver::Dimension.new(*@screen_size)
|
35
53
|
end
|
36
54
|
end
|
@@ -41,7 +59,7 @@ module ActionDispatch
|
|
41
59
|
|
42
60
|
def register_webkit(app)
|
43
61
|
Capybara::Webkit::Driver.new(app, Capybara::Webkit::Configuration.to_hash.merge(@options)).tap do |driver|
|
44
|
-
driver.
|
62
|
+
driver.resize_window_to(driver.current_window_handle, *@screen_size)
|
45
63
|
end
|
46
64
|
end
|
47
65
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActionDispatch
|
4
4
|
module SystemTesting
|
@@ -10,31 +10,17 @@ module ActionDispatch
|
|
10
10
|
self.silence_puma = false
|
11
11
|
|
12
12
|
def run
|
13
|
-
register
|
14
13
|
setup
|
15
14
|
end
|
16
15
|
|
17
16
|
private
|
18
|
-
def register
|
19
|
-
Capybara.register_server :rails_puma do |app, port, host|
|
20
|
-
Rack::Handler::Puma.run(
|
21
|
-
app,
|
22
|
-
Port: port,
|
23
|
-
Threads: "0:1",
|
24
|
-
workers: 0,
|
25
|
-
daemon: false,
|
26
|
-
Silent: self.class.silence_puma
|
27
|
-
)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
17
|
def setup
|
32
18
|
set_server
|
33
19
|
set_port
|
34
20
|
end
|
35
21
|
|
36
22
|
def set_server
|
37
|
-
Capybara.server = :
|
23
|
+
Capybara.server = :puma, { Silent: self.class.silence_puma }
|
38
24
|
end
|
39
25
|
|
40
26
|
def set_port
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionDispatch
|
2
4
|
module SystemTesting
|
3
5
|
module TestHelpers
|
4
|
-
# Screenshot helper for system testing
|
6
|
+
# Screenshot helper for system testing.
|
5
7
|
module ScreenshotHelper
|
6
8
|
# Takes a screenshot of the current page in the browser.
|
7
9
|
#
|
@@ -14,12 +16,12 @@ module ActionDispatch
|
|
14
16
|
# You can set the +RAILS_SYSTEM_TESTING_SCREENSHOT+ environment variable to
|
15
17
|
# control the output. Possible values are:
|
16
18
|
# * [+inline+ (default)] display the screenshot in the terminal using the
|
17
|
-
# iTerm image protocol (
|
19
|
+
# iTerm image protocol (https://iterm2.com/documentation-images.html).
|
18
20
|
# * [+simple+] only display the screenshot path.
|
19
21
|
# This is the default value if the +CI+ environment variables
|
20
22
|
# is defined.
|
21
23
|
# * [+artifact+] display the screenshot in the terminal, using the terminal
|
22
|
-
# artifact format (
|
24
|
+
# artifact format (https://buildkite.github.io/terminal/inline-images/).
|
23
25
|
def take_screenshot
|
24
26
|
save_image
|
25
27
|
puts display_image
|
@@ -67,7 +69,7 @@ module ActionDispatch
|
|
67
69
|
end
|
68
70
|
|
69
71
|
def display_image
|
70
|
-
message = "[Screenshot]: #{image_path}\n"
|
72
|
+
message = "[Screenshot]: #{image_path}\n".dup
|
71
73
|
|
72
74
|
case output_type
|
73
75
|
when "artifact"
|