From cbceb78f38a1e51d02c19cd33f7299f3d0a79e95 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sat, 25 Jun 2016 11:13:42 +0200 Subject: Extract method to share path expansion logic. Then just yield the location for the place where we need some extra processing. --- .../lib/action_dispatch/testing/integration.rb | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'actionpack/lib/action_dispatch/testing') diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 7ebce95b29..5627e79bb7 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -327,19 +327,17 @@ module ActionDispatch request_encoder = RequestEncoder.encoder(as) if path =~ %r{://} - location = URI.parse(path) - https! URI::HTTPS === location if location.scheme - if url_host = location.host - default = Rack::Request::DEFAULT_PORTS[location.scheme] - url_host += ":#{location.port}" if default != location.port - host! url_host + path = build_expanded_path(path, request_encoder) do |location| + https! URI::HTTPS === location if location.scheme + + if url_host = location.host + default = Rack::Request::DEFAULT_PORTS[location.scheme] + url_host += ":#{location.port}" if default != location.port + host! url_host + end end - path = request_encoder.append_format_to location.path - path = location.query ? "#{path}?#{location.query}" : path elsif as - location = URI.parse(path) - path = request_encoder.append_format_to location.path - path = location.query ? "#{path}?#{location.query}" : path + path = build_expanded_path(path, request_encoder) end hostname, port = host.split(':') @@ -398,6 +396,13 @@ module ActionDispatch "#{env['rack.url_scheme']}://#{env['SERVER_NAME']}:#{env['SERVER_PORT']}#{path}" end + def build_expanded_path(path, request_encoder) + location = URI.parse(path) + yield location if block_given? + path = request_encoder.append_format_to location.path + location.query ? "#{path}?#{location.query}" : path + end + class RequestEncoder # :nodoc: @encoders = {} -- cgit v1.2.3