Module: ActionDispatch::Integration::RequestHelpers
- Defined in:
- actionpack/lib/action_dispatch/testing/integration.rb
Instance Method Summary (collapse)
-
- (Object) delete(path, parameters = nil, headers = nil)
Performs a DELETE request with the given parameters.
-
- (Object) delete_via_redirect(path, parameters = nil, headers = nil)
Performs a DELETE request, following any subsequent redirect.
-
- (Object) follow_redirect!
Follow a single redirect response.
-
- (Object) get(path, parameters = nil, headers = nil)
Performs a GET request with the given parameters.
-
- (Object) get_via_redirect(path, parameters = nil, headers = nil)
Performs a GET request, following any subsequent redirect.
-
- (Object) head(path, parameters = nil, headers = nil)
Performs a HEAD request with the given parameters.
-
- (Object) post(path, parameters = nil, headers = nil)
Performs a POST request with the given parameters.
-
- (Object) post_via_redirect(path, parameters = nil, headers = nil)
Performs a POST request, following any subsequent redirect.
-
- (Object) put(path, parameters = nil, headers = nil)
Performs a PUT request with the given parameters.
-
- (Object) put_via_redirect(path, parameters = nil, headers = nil)
Performs a PUT request, following any subsequent redirect.
-
- (Object) request_via_redirect(http_method, path, parameters = nil, headers = nil)
Performs a request using the specified method, following any subsequent redirect.
-
- (Object) xml_http_request(request_method, path, parameters = nil, headers = nil)
(also: #xhr)
Performs an XMLHttpRequest request with the given parameters, mirroring a request from the Prototype library.
Instance Method Details
- (Object) delete(path, parameters = nil, headers = nil)
Performs a DELETE request with the given parameters. See get() for more details.
49 50 51 |
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 49 def delete(path, parameters = nil, headers = nil) process :delete, path, parameters, headers end |
- (Object) delete_via_redirect(path, parameters = nil, headers = nil)
Performs a DELETE request, following any subsequent redirect. See request_via_redirect for more information.
113 114 115 |
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 113 def delete_via_redirect(path, parameters = nil, headers = nil) request_via_redirect(:delete, path, parameters, headers) end |
- (Object) 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.
77 78 79 80 81 |
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 77 def follow_redirect! raise "not a redirect! #{status} #{}" unless redirect? get(response.location) status end |
- (Object) get(path, parameters = nil, headers = 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 be nil, a Hash, or a String that is appropriately encoded (application/x-www-form-urlencoded or multipart/form-data).
-
headers: Additional HTTP headers to pass, as a Hash. The keys will automatically be upcased, with the prefix 'HTTP_' added if needed.
This method returns an 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, PUT, DELETE, and HEAD requests with post, put, delete, and head.
31 32 33 |
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 31 def get(path, parameters = nil, headers = nil) process :get, path, parameters, headers end |
- (Object) get_via_redirect(path, parameters = nil, headers = nil)
Performs a GET request, following any subsequent redirect. See request_via_redirect for more information.
95 96 97 |
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 95 def get_via_redirect(path, parameters = nil, headers = nil) request_via_redirect(:get, path, parameters, headers) end |
- (Object) head(path, parameters = nil, headers = nil)
Performs a HEAD request with the given parameters. See get() for more details.
55 56 57 |
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 55 def head(path, parameters = nil, headers = nil) process :head, path, parameters, headers end |
- (Object) post(path, parameters = nil, headers = nil)
Performs a POST request with the given parameters. See get() for more details.
37 38 39 |
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 37 def post(path, parameters = nil, headers = nil) process :post, path, parameters, headers end |
- (Object) post_via_redirect(path, parameters = nil, headers = nil)
Performs a POST request, following any subsequent redirect. See request_via_redirect for more information.
101 102 103 |
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 101 def post_via_redirect(path, parameters = nil, headers = nil) request_via_redirect(:post, path, parameters, headers) end |
- (Object) put(path, parameters = nil, headers = nil)
Performs a PUT request with the given parameters. See get() for more details.
43 44 45 |
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 43 def put(path, parameters = nil, headers = nil) process :put, path, parameters, headers end |
- (Object) put_via_redirect(path, parameters = nil, headers = nil)
Performs a PUT request, following any subsequent redirect. See request_via_redirect for more information.
107 108 109 |
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 107 def put_via_redirect(path, parameters = nil, headers = nil) request_via_redirect(:put, path, parameters, headers) end |
- (Object) request_via_redirect(http_method, path, parameters = nil, headers = 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.
87 88 89 90 91 |
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 87 def request_via_redirect(http_method, path, parameters = nil, headers = nil) process(http_method, path, parameters, headers) follow_redirect! while redirect? status end |
- (Object) xml_http_request(request_method, path, parameters = nil, headers = 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, :put, :delete or :head; the parameters are nil, a hash, or a url-encoded or multipart string; the headers are a hash. Keys are automatically upcased and prefixed with 'HTTP_' if not already.
66 67 68 69 70 71 |
# File 'actionpack/lib/action_dispatch/testing/integration.rb', line 66 def xml_http_request(request_method, path, parameters = nil, headers = nil) headers ||= {} headers['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' headers['HTTP_ACCEPT'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ') process(request_method, path, parameters, headers) end |