Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/twilio-ruby/http/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def _request(request) # rubocop:disable Metrics/MethodLength
f.options.timeout = request.timeout || @timeout
f.params = request.params.nil? ? {} : request.params

@configure_connection_blocks.each { |block| block.call(f) }
f.adapter @adapter
@configure_connection_blocks.each { |block| block.call(f) }
end

@last_request = request
Expand Down
23 changes: 21 additions & 2 deletions spec/http/http_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,34 @@
blocks_spy.second_block_called(f)
end

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

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

expect(blocks_spy).to have_received(:first_block_called).with(@connection)
expect(blocks_spy).to have_received(:second_block_called).with(@connection)
end

it 'should allow the configuration block to set the connection adapter' do
@client = Twilio::HTTP::Client.new
@connection = Faraday::Connection.new

stub_const('TestAdapter', Class.new(Faraday::Adapter))
Faraday::Adapter.register_middleware test_adapter: TestAdapter

@client.configure_connection do |f|
f.adapter :test_adapter
end

allow(Faraday).to receive(:new).and_yield(@connection).and_return(@connection)
allow(@connection).to receive(:send).and_return(double('response', status: 301, body: {}, headers: {}))

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

expect(@connection.adapter).to eq TestAdapter
end

it 'should allow setting a global timeout' do
@client = Twilio::HTTP::Client.new(timeout: 10)
@connection = Faraday::Connection.new
Expand Down