lostisland/faraday — pull request #265 by vijaykramesh (2013-05-06 21:49:41+00:00)
Title: Reset Faraday.default_connection when setting Faraday.default_adapter

Currently Faraday.default_connection is memoized - this is fine and wonderful, unless you change Faraday.default_adapter after have already initialized Faraday.default_connection. In this case, your Faraday::Connection instance has already been setup (which magically happens via method_missing if you call, e.g., Faraday.get "http://foobar.com/") and your changes to .default_adapter won't do anything.

```ruby
irb(main):001:0> require 'faraday'
=> true
irb(main):002:0> Faraday.get("http://change.org/")
=> #:get, :body=>"

\n", :url=>#, :request_headers=>{}, :parallel_manager=>nil, :request=>{:proxy=>nil}, :ssl=>{}, :status=>200, :response_headers=>{"server"=>"nginx/1.2.6", "date"=>"Mon, 06 May 2013 21:46:16 GMT", "content-type"=>"text/html", "transfer-encoding"=>"chunked", "connection"=>"close", "p3p"=>"CP=\"NON DSP COR ADMa OUR IND UNI COM NAV INT\"", "cache-control"=>"no-cache, no-store, must-revalidate", "pragma"=>"no-cache"}, :response=>#}, @on_complete_callbacks=[]>
irb(main):003:0> Faraday.default_adapter = :typhoeus
=> :typhoeus
irb(main):004:0> Faraday.get("http://change.org/")
=> #:get, :body=>"

\n", :url=>#, :request_headers=>{}, :parallel_manager=>nil, :request=>{:proxy=>nil}, :ssl=>{}, :status=>200, :response_headers=>{"server"=>"nginx/1.2.6", "date"=>"Mon, 06 May 2013 21:47:30 GMT", "content-type"=>"text/html", "transfer-encoding"=>"chunked", "connection"=>"close", "p3p"=>"CP=\"NON DSP COR ADMa OUR IND UNI COM NAV INT\"", "cache-control"=>"no-cache, no-store, must-revalidate", "pragma"=>"no-cache"}, :response=>#}, @on_complete_callbacks=[]>
irb(main):005:0> Faraday.default_connection
=> #, @url_prefix=#, @proxy=nil, @app=#>>>
```

This pull request explicitly defines a Faraday.default_adapter= setter that clears Faraday.default_connection to handle this bug.

```ruby
1.9.3-p0 :001 > require './lib/faraday'
=> true
1.9.3-p0 :002 > Faraday.default_connection
=> #"Faraday v0.9.0.pre"}, @params={}, @options=#, @ssl=#, @default_parallel_manager=nil, @builder=#, @url_prefix=#>
1.9.3-p0 :003 > Faraday.default_adapter = :typhoeus
=> :typhoeus
1.9.3-p0 :004 > Faraday.default_connection
=> #"Faraday v0.9.0.pre"}, @params={}, @options=#, @ssl=#, @default_parallel_manager=nil, @builder=#, @url_prefix=#>
```