Skip to content

Commit a821e31

Browse files
committed
Configure connection after setting adapter
Setting the adapter after calling the configure_connection blocks makes it impossible to configure the adapter with options.
1 parent ff04478 commit a821e31

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lib/twilio-ruby/http/http_client.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def _request(request) # rubocop:disable Metrics/MethodLength
4040
f.options.open_timeout = request.timeout || @timeout
4141
f.options.timeout = request.timeout || @timeout
4242

43-
@configure_connection_blocks.each { |block| block.call(f) }
4443
f.adapter @adapter
44+
@configure_connection_blocks.each { |block| block.call(f) }
4545
end
4646

4747
@last_request = request

spec/http/http_client_spec.rb

+21-2
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,34 @@
2020
blocks_spy.second_block_called(f)
2121
end
2222

23-
expect(Faraday).to receive(:new).and_yield(@connection).and_return(@connection)
24-
allow_any_instance_of(Faraday::Connection).to receive(:send).and_return(double('response', status: 301, body: {}, headers: {}))
23+
allow(Faraday).to receive(:new).and_yield(@connection).and_return(@connection)
24+
allow(@connection).to receive(:send).and_return(double('response', status: 301, body: {}, headers: {}))
2525

2626
@client.request('host', 'port', 'GET', 'url', nil, nil, {}, ['a', 'b'])
2727

2828
expect(blocks_spy).to have_received(:first_block_called).with(@connection)
2929
expect(blocks_spy).to have_received(:second_block_called).with(@connection)
3030
end
3131

32+
it 'should allow the configuration block to set the connection adapter' do
33+
@client = Twilio::HTTP::Client.new
34+
@connection = Faraday::Connection.new
35+
36+
stub_const('TestAdapter', Class.new(Faraday::Adapter))
37+
Faraday::Adapter.register_middleware test_adapter: TestAdapter
38+
39+
@client.configure_connection do |f|
40+
f.adapter :test_adapter
41+
end
42+
43+
allow(Faraday).to receive(:new).and_yield(@connection).and_return(@connection)
44+
allow(@connection).to receive(:send).and_return(double('response', status: 301, body: {}, headers: {}))
45+
46+
@client.request('host', 'port', 'GET', 'url', nil, nil, {}, ['a', 'b'])
47+
48+
expect(@connection.adapter).to eq TestAdapter
49+
end
50+
3251
it 'should allow setting a global timeout' do
3352
@client = Twilio::HTTP::Client.new(timeout: 10)
3453
@connection = Faraday::Connection.new

0 commit comments

Comments
 (0)