Permalink
Browse files

Fix HTTP Gem replayed Response object's init

0.6.x version introduced optional last argument of Response object:
request's uri. That allows for example to figure out a real URI after
following redirects. This patch brinsg this ability to HTTP Gem adapter.
  • Loading branch information...
ixti committed May 28, 2014
1 parent 0cd6a12 commit 321bd54c17c7c1fa6b26ff6dea2eed0d6b2c33f9
@@ -10,12 +10,13 @@ def to_webmock
webmock_response
end
- def self.from_webmock(webmock_response)
+ def self.from_webmock(webmock_response, request_signature = nil)
status = webmock_response.status.first
headers = webmock_response.headers || {}
body = Body.new Streamer.new webmock_response.body
+ uri = URI request_signature.uri.to_s if request_signature
- new(status, "1.1", headers, body)
+ new(status, "1.1", headers, body, uri)
end
end
end
@@ -37,7 +37,7 @@ def replay
webmock_response.raise_error_if_any
invoke_callbacks(webmock_response, :real_request => false)
- ::HTTP::Response.from_webmock webmock_response
+ ::HTTP::Response.from_webmock webmock_response, request_signature
end
def perform
@@ -47,4 +47,13 @@
expect(headers).to include "Host" => "www.example.com"
end
end
+
+ it "restores request uri on replayed response object" do
+ uri = URI "http://example.com/foo"
+
+ stub_request :get, "example.com/foo"
+ response = HTTP.get uri
+
+ expect(response.uri).to eq uri
+ end
end

0 comments on commit 321bd54

Please sign in to comment.