Skip to content

Commit

Permalink
Merge pull request bblimke#184 from jonleighton/dont_mutate_uri
Browse files Browse the repository at this point in the history
Clone the URI before mutating it.
  • Loading branch information
bblimke committed May 21, 2012
2 parents d083e68 + 6927943 commit 887bf32
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def build_request_signature
end end


method = @req.method method = @req.method
uri = @req.uri uri = @req.uri.clone
auth = @req.proxy[:authorization] if @req.proxy auth = @req.proxy[:authorization] if @req.proxy
query = @req.query query = @req.query


Expand Down
25 changes: 20 additions & 5 deletions spec/acceptance/em_http_request/em_http_request_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -141,26 +141,41 @@ def response(resp)
end end


describe "mocking EM::HttpClient API" do describe "mocking EM::HttpClient API" do
let(:uri) { "http://www.example.com/" }

before do before do
stub_request(:get, "www.example.com/") stub_request(:get, uri)
WebMock::HttpLibAdapters::EmHttpRequestAdapter.enable! WebMock::HttpLibAdapters::EmHttpRequestAdapter.enable!
end end
subject do
def client(uri, options = {})
client = nil client = nil
EM.run do EM.run do
client = EventMachine::HttpRequest.new('http://www.example.com/').get client = EventMachine::HttpRequest.new(uri).get(options)
client.callback { EM.stop } client.callback { EM.stop }
client.errback { failed } client.errback { failed }
end end
client client
end end


subject { client(uri) }

it 'should support #uri' do it 'should support #uri' do
subject.uri.should == Addressable::URI.parse('http://www.example.com/') subject.uri.should == Addressable::URI.parse(uri)
end end


it 'should support #last_effective_url' do 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
end end


Expand Down

0 comments on commit 887bf32

Please sign in to comment.