Module: ActionDispatch::Integration::RequestHelpers
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | actionpack/lib/action_dispatch/testing/integration.rb |
Instance Method Summary
-
#delete(path, parameters = nil, headers_or_env = nil)
Performs a DELETE request with the given parameters.
-
#delete_via_redirect(path, parameters = nil, headers_or_env = nil)
Performs a DELETE request, following any subsequent redirect.
-
#follow_redirect!
Follow a single redirect response.
-
#get(path, parameters = nil, headers_or_env = nil)
Performs a GET request with the given parameters.
-
#get_via_redirect(path, parameters = nil, headers_or_env = nil)
Performs a GET request, following any subsequent redirect.
-
#head(path, parameters = nil, headers_or_env = nil)
Performs a HEAD request with the given parameters.
-
#patch(path, parameters = nil, headers_or_env = nil)
Performs a PATCH request with the given parameters.
-
#patch_via_redirect(path, parameters = nil, headers_or_env = nil)
Performs a PATCH request, following any subsequent redirect.
-
#post(path, parameters = nil, headers_or_env = nil)
Performs a POST request with the given parameters.
-
#post_via_redirect(path, parameters = nil, headers_or_env = nil)
Performs a POST request, following any subsequent redirect.
-
#put(path, parameters = nil, headers_or_env = nil)
Performs a PUT request with the given parameters.
-
#put_via_redirect(path, parameters = nil, headers_or_env = nil)
Performs a PUT request, following any subsequent redirect.
-
#request_via_redirect(http_method, path, parameters = nil, headers_or_env = nil)
Performs a request using the specified method, following any subsequent redirect.
-
#xhr(request_method, path, parameters = nil, headers_or_env = nil)
Alias for #xml_http_request.
-
#xml_http_request(request_method, path, parameters = nil, headers_or_env = nil)
(also: #xhr)
Performs an XMLHttpRequest request with the given parameters, mirroring a request from the Prototype library.
Instance Method Details
#delete(path, parameters = nil, headers_or_env = nil)
Performs a DELETE request with the given parameters. See #get for more details.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 55
def delete(path, parameters = nil, headers_or_env = nil) process :delete, path, parameters, headers_or_env end
#delete_via_redirect(path, parameters = nil, headers_or_env = nil)
Performs a DELETE request, following any subsequent redirect. See #request_via_redirect for more information.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 124
def delete_via_redirect(path, parameters = nil, headers_or_env = nil) request_via_redirect(:delete, path, parameters, headers_or_env) end
#follow_redirect!
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.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 82
def follow_redirect! raise "not a redirect! #{status} #{}" unless redirect? get(response.location) status end
#get(path, parameters = nil, headers_or_env = nil)
Performs a GET request with the given parameters.
-
path
: The URI (as a ::String) on which you want to perform a GET request. -
parameters
: The HTTP parameters that you want to pass. This may benil
, a Hash, or a String that is appropriately encoded (application/x-www-form-urlencoded
ormultipart/form-data
). -
headers_or_env
: Additional headers to pass, as a ::Hash. The headers will be merged into the Rack env hash.
This method returns a ::ActionDispatch::Response object, which one can use to inspect the details of the response. Furthermore, if this method was called from an ::ActionDispatch::IntegrationTest object, then that object's @response
instance variable will point to the same response object.
You can also perform POST, PATCH, PUT, DELETE, and HEAD requests with #post, #patch, #put, #delete, and #head.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 31
def get(path, parameters = nil, headers_or_env = nil) process :get, path, parameters, headers_or_env end
#get_via_redirect(path, parameters = nil, headers_or_env = nil)
Performs a GET request, following any subsequent redirect. See #request_via_redirect for more information.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 100
def get_via_redirect(path, parameters = nil, headers_or_env = nil) request_via_redirect(:get, path, parameters, headers_or_env) end
#head(path, parameters = nil, headers_or_env = nil)
Performs a HEAD request with the given parameters. See #get for more details.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 61
def head(path, parameters = nil, headers_or_env = nil) process :head, path, parameters, headers_or_env end
#patch(path, parameters = nil, headers_or_env = nil)
Performs a PATCH request with the given parameters. See #get for more details.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 43
def patch(path, parameters = nil, headers_or_env = nil) process :patch, path, parameters, headers_or_env end
#patch_via_redirect(path, parameters = nil, headers_or_env = nil)
Performs a PATCH request, following any subsequent redirect. See #request_via_redirect for more information.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 112
def patch_via_redirect(path, parameters = nil, headers_or_env = nil) request_via_redirect(:patch, path, parameters, headers_or_env) end
#post(path, parameters = nil, headers_or_env = nil)
Performs a POST request with the given parameters. See #get for more details.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 37
def post(path, parameters = nil, headers_or_env = nil) process :post, path, parameters, headers_or_env end
#post_via_redirect(path, parameters = nil, headers_or_env = nil)
Performs a POST request, following any subsequent redirect. See #request_via_redirect for more information.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 106
def post_via_redirect(path, parameters = nil, headers_or_env = nil) request_via_redirect(:post, path, parameters, headers_or_env) end
#put(path, parameters = nil, headers_or_env = nil)
Performs a PUT request with the given parameters. See #get for more details.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 49
def put(path, parameters = nil, headers_or_env = nil) process :put, path, parameters, headers_or_env end
#put_via_redirect(path, parameters = nil, headers_or_env = nil)
Performs a PUT request, following any subsequent redirect. See #request_via_redirect for more information.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 118
def put_via_redirect(path, parameters = nil, headers_or_env = nil) request_via_redirect(:put, path, parameters, headers_or_env) end
#request_via_redirect(http_method, path, parameters = nil, headers_or_env = nil)
Performs a request using the specified method, following any subsequent redirect. Note that the redirects are followed until the response is not a redirect–this means you may run into an infinite loop if your redirect loops back to itself.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 92
def request_via_redirect(http_method, path, parameters = nil, headers_or_env = nil) process(http_method, path, parameters, headers_or_env) follow_redirect! while redirect? status end
#xhr(request_method, path, parameters = nil, headers_or_env = nil)
Alias for #xml_http_request.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 77
alias xhr :xml_http_request
#xml_http_request(request_method, path, parameters = nil, headers_or_env = nil) Also known as: #xhr
Performs an XMLHttpRequest request with the given parameters, mirroring a request from the Prototype library.
The request_method is :get
, :post
, :patch
, :put
, :delete
or :head
; the parameters are nil
, a hash, or a url-encoded or multipart string; the headers are a hash.
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 71
def xml_http_request(request_method, path, parameters = nil, headers_or_env = nil) headers_or_env ||= {} headers_or_env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' headers_or_env['HTTP_ACCEPT'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ') process(request_method, path, parameters, headers_or_env) end