Browse files

Merge pull request #184 from jonleighton/dont_mutate_uri

Clone the URI before mutating it.
  • Loading branch information...
2 parents d083e68 + 6927943 commit 887bf32ec8a57fc8a457a25afdc398ce3988b8b3 @bblimke bblimke committed May 21, 2012
View
2 lib/webmock/http_lib_adapters/em_http_request/em_http_request_1_x.rb
@@ -153,7 +153,7 @@ def build_request_signature
end
method = @req.method
- uri = @req.uri
+ uri = @req.uri.clone
auth = @req.proxy[:authorization] if @req.proxy
query = @req.query
View
25 spec/acceptance/em_http_request/em_http_request_spec.rb
@@ -141,26 +141,41 @@ def response(resp)
end
describe "mocking EM::HttpClient API" do
+ let(:uri) { "http://www.example.com/" }
+
before do
- stub_request(:get, "www.example.com/")
+ stub_request(:get, uri)
WebMock::HttpLibAdapters::EmHttpRequestAdapter.enable!
end
- subject do
+
+ def client(uri, options = {})
client = nil
EM.run do
- client = EventMachine::HttpRequest.new('http://www.example.com/').get
+ client = EventMachine::HttpRequest.new(uri).get(options)
client.callback { EM.stop }
client.errback { failed }
end
client
end
+ subject { client(uri) }
+
it 'should support #uri' do
- subject.uri.should == Addressable::URI.parse('http://www.example.com/')
+ subject.uri.should == Addressable::URI.parse(uri)
end
it 'should support #last_effective_url' do
- subject.last_effective_url.should == Addressable::URI.parse('http://www.example.com/')
+ subject.last_effective_url.should == Addressable::URI.parse(uri)
+ end
+
+ context "with a query" do
+ let(:uri) { "http://www.example.com/?a=1&b=2" }
+ subject { client("http://www.example.com/?a=1", :query => { 'b' => 2 }) }
+
+ it "#request_signature doesn't mutate the original uri" do
+ subject.uri.should == Addressable::URI.parse("http://www.example.com/?a=1")
+ subject.request_signature.uri.should == Addressable::URI.parse(uri)
+ end
end
end

0 comments on commit 887bf32

Please sign in to comment.