Skip to content

Commit

Permalink
Update client spec to check for adapter instead of handlers (Faraday …
Browse files Browse the repository at this point in the history
…1.0)
  • Loading branch information
picandocodigo committed Mar 25, 2020
1 parent 13bf87b commit 293cbfc
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions elasticsearch-transport/spec/elasticsearch/transport/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,41 +220,41 @@
describe 'adapter' do
context 'when no adapter is specified' do
let(:adapter) do
client.transport.connections.all.first.connection.builder.handlers
client.transport.connections.all.first.connection.builder.adapter
end

it 'uses Faraday NetHttp' do
expect(adapter).to include(Faraday::Adapter::NetHttp)
expect(adapter).to eq Faraday::Adapter::NetHttp
end
end

context 'when the adapter is specified' do

let(:adapter) do
client.transport.connections.all.first.connection.builder.handlers
client.transport.connections.all.first.connection.builder.adapter
end

let(:client) do
described_class.new(adapter: :typhoeus)
described_class.new(adapter: :patron)
end

it 'uses Faraday with the adapter' do
expect(adapter).to include(Faraday::Adapter::Typhoeus)
expect(adapter).to eq Faraday::Adapter::Patron
end
end

context 'when the adapter is specified as a string key' do

let(:adapter) do
client.transport.connections.all.first.connection.builder.handlers
client.transport.connections.all.first.connection.builder.adapter
end

let(:client) do
described_class.new('adapter' => :typhoeus)
described_class.new('adapter' => :patron)
end

it 'uses Faraday with the adapter' do
expect(adapter).to include(Faraday::Adapter::Typhoeus)
expect(adapter).to eq Faraday::Adapter::Patron
end
end

Expand All @@ -266,29 +266,33 @@
end

let(:adapter) do
client.transport.connections.all.first.connection.builder.handlers
client.transport.connections.all.first.connection.builder.adapter
end

it 'uses the detected adapter' do
expect(adapter).to include(Faraday::Adapter::Patron)
expect(adapter).to eq Faraday::Adapter::Patron
end
end

context 'when the Faraday adapter is configured' do

let(:client) do
described_class.new do |faraday|
faraday.adapter :typhoeus
faraday.adapter :patron
faraday.response :logger
end
end

let(:adapter) do
client.transport.connections.all.first.connection.builder.adapter
end

let(:handlers) do
client.transport.connections.all.first.connection.builder.handlers
end

it 'sets the adapter' do
expect(handlers).to include(Faraday::Adapter::Typhoeus)
expect(adapter).to eq Faraday::Adapter::Patron
end

it 'sets the logger' do
Expand Down Expand Up @@ -1209,23 +1213,22 @@
end

context 'when the Faraday adapter is set in the block' do

let(:client) do
Elasticsearch::Client.new(host: ELASTICSEARCH_HOSTS.first, logger: logger) do |client|
client.adapter(:net_http_persistent)
end
end

let(:connection_handler) do
client.transport.connections.first.connection.builder.handlers.first
let(:handler_name) do
client.transport.connections.first.connection.builder.adapter.name
end

let(:response) do
client.perform_request('GET', '_cluster/health')
end

it 'sets the adapter' do
expect(connection_handler.name).to eq('Faraday::Adapter::NetHttpPersistent')
expect(handler_name).to eq('Faraday::Adapter::NetHttpPersistent')
end

it 'uses the adapter to connect' do
Expand Down Expand Up @@ -1559,12 +1562,12 @@
{ adapter: :patron }
end

let(:connection_handler) do
client.transport.connections.first.connection.builder.handlers.first
let(:adapter) do
client.transport.connections.first.connection.builder.adapter
end

it 'uses the patron connection handler' do
expect(connection_handler).to eq('Faraday::Adapter::Patron')
expect(adapter).to eq('Faraday::Adapter::Patron')
end

it 'keeps connections open' do
Expand Down

0 comments on commit 293cbfc

Please # to comment.