method
recognized_request_for
rails latest stable - Class:
ActionDispatch::Assertions::RoutingAssertions
recognized_request_for(path, extras = {}, msg)private
Recognizes the route for a given path.
# File actionpack/lib/action_dispatch/testing/assertions/routing.rb, line 233
def recognized_request_for(path, extras = {}, msg)
if path.is_a?(Hash)
method = path[:method]
path = path[:path]
else
method = :get
end
controller = @controller if defined?(@controller)
request = ActionController::TestRequest.create controller&.class
if path.include?("://")
fail_on(URI::InvalidURIError, msg) do
uri = URI.parse(path)
request.env["rack.url_scheme"] = uri.scheme || "http"
request.host = uri.host if uri.host
request.port = uri.port if uri.port
request.path = uri.path.to_s.empty? ? "/" : uri.path
end
else
path = "/#{path}" unless path.start_with?("/")
request.path = path
end
request.request_method = method if method
params = fail_on(ActionController::RoutingError, msg) do
@routes.recognize_path(path, method: method, extras: extras)
end
request.path_parameters = params.with_indifferent_access
request
end Related methods
- Instance methods
- assert_generates
- assert_recognizes
- assert_routing
- method_missing
- setup
- with_routing
- Private methods
-
create_routes -
fail_on -
recognized_request_for -
reset_routes