aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorRemo Fritzsche <dev@remofritzsche.com>2018-07-05 22:51:52 +0200
committerRafael França <rafaelmfranca@gmail.com>2018-07-05 16:51:52 -0400
commita0061d2389a178b093f0d3f64f58236ffbe088e0 (patch)
treec13832bbb96ba827310e042e91987e2790384770 /actionpack
parent9ecbd64cd93af0c7efe3141e93f85e5c263e00d0 (diff)
downloadrails-a0061d2389a178b093f0d3f64f58236ffbe088e0.tar.gz
rails-a0061d2389a178b093f0d3f64f58236ffbe088e0.tar.bz2
rails-a0061d2389a178b093f0d3f64f58236ffbe088e0.zip
Pass along arguments to underlying `get` method in `follow_redirect!` (#33299)
* Allow get arguments for follow_redirect Now all arguments passed to `follow_redirect!` are passed to the underlying `get` method. This for example allows to set custom headers for the redirection request to the server. This is especially useful for setting headers that may, outside of the testing environment, be set automatically on every request, i.e. by a web application firewall. * Allow get arguments for follow_redirect [Remo Fritzsche + Rafael Mendonça França]
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md10
-rw-r--r--actionpack/lib/action_dispatch/testing/integration.rb7
-rw-r--r--actionpack/test/controller/integration_test.rb10
3 files changed, 24 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 3bbc9a9cfd..7645b2b0e7 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,3 +1,13 @@
+* Pass along arguments to underlying `get` method in `follow_redirect!`
+
+ Now all arguments passed to `follow_redirect!` are passed to the underlying
+ `get` method. This for example allows to set custom headers for the
+ redirection request to the server.
+
+ follow_redirect!(params: { foo: :bar })
+
+ *Remo Fritzsche*
+
* Introduce a new error page to when the implicit render page is accessed in the browser.
Now instead of showing an error page that with exception and backtraces we now show only
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb
index f0398dc7b1..7637febd1c 100644
--- a/actionpack/lib/action_dispatch/testing/integration.rb
+++ b/actionpack/lib/action_dispatch/testing/integration.rb
@@ -50,10 +50,11 @@ module ActionDispatch
# Follow a single redirect response. If the last response was not a
# redirect, an exception will be raised. Otherwise, the redirect is
- # performed on the location header.
- def follow_redirect!
+ # performed on the location header. Any arguments are passed to the
+ # underlying call to `get`.
+ def follow_redirect!(**args)
raise "not a redirect! #{status} #{status_message}" unless redirect?
- get(response.location)
+ get(response.location, **args)
status
end
end
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index 9cdf04b886..41812a82e1 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -349,6 +349,16 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest
end
end
+ def test_redirect_with_arguments
+ with_test_route_set do
+ get "/redirect"
+ follow_redirect! params: { foo: :bar }
+
+ assert_response :ok
+ assert_equal "bar", request.parameters["foo"]
+ end
+ end
+
def test_xml_http_request_get
with_test_route_set do
get "/get", xhr: true