Skip to content

Commit

Permalink
Connection.new yields self after everything has been set up
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Dec 30, 2011
1 parent 9830fdb commit 125c50f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/faraday/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ def initialize(url = nil, options = {})
block = block_given?? Proc.new {|b| } : nil
Builder.new(&block)
end
yield self if block_given?

self.url_prefix = url if url
proxy(options[:proxy])

@params.update options[:params] if options[:params]
@headers.update options[:headers] if options[:headers]

yield self if block_given?
end

extend Forwardable
Expand Down
3 changes: 2 additions & 1 deletion test/connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@ def test_init_with_block
end

def test_init_with_block_yields_connection
conn = Faraday::Connection.new { |faraday|
conn = Faraday::Connection.new(:params => {'a'=>'1'}) { |faraday|
faraday.adapter :net_http
faraday.url_prefix = 'http://sushi.com/omnom'
assert_equal '1', faraday.params['a']
}
assert_equal 1, conn.builder.handlers.size
assert_equal '/omnom', conn.path_prefix
Expand Down

0 comments on commit 125c50f

Please sign in to comment.