Skip to content

Commit

Permalink
Allowing http_adaptor key as either string or symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
brucek committed Nov 18, 2016
1 parent 4a2e878 commit c077648
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
3 changes: 1 addition & 2 deletions lib/neo4j-server/cypher_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def self.create_connection(params, url = nil)

b.response :multi_json, symbolize_keys: true, content_type: 'application/json'
# b.use Faraday::Response::RaiseError
b.adapter :net_http_persistent
# b.adapter Faraday.default_adapter
b.adapter (params.delete(:http_adaptor) || params.delete('http_adaptor') || :net_http_persistent).to_sym
end
conn.headers = {'Content-Type' => 'application/json', 'User-Agent' => ::Neo4j::Session.user_agent_string}
conn
Expand Down
2 changes: 1 addition & 1 deletion lib/neo4j/core/cypher_session/adaptors/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(url, options = {})
@url = url
@url_components = url_components!(url)
@transaction_state = nil
@http_adaptor = options[:http_adaptor] || :net_http_persistent
@http_adaptor = (options[:http_adaptor] || options['http_adaptor'] || :net_http_persistent).to_sym
end

def connect
Expand Down
12 changes: 12 additions & 0 deletions spec/neo4j-server/e2e/cypher_session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ def open_session
expect(connection.port).to eq 7474
expect(connection.host).to eq 'localhost'
end

describe 'a faraday connection type http_adaptor param' do
it 'will pass through a symbol key' do
expect(Neo4j::Server::CypherSession).to receive(:open).with(anything, hash_including(http_adaptor: :something))
create_server_session(http_adaptor: :something)
end

it "will pass through a string key" do
expect(Neo4j::Server::CypherSession).to receive(:open).with(anything, hash_including('http_adaptor' => :something))
create_server_session('http_adaptor' => :something)
end
end
end


Expand Down
35 changes: 21 additions & 14 deletions spec/neo4j/core/cypher_session/adaptors/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,29 @@
expect { adaptor_class.new('https://foo:bar@localhost:7474') }.not_to raise_error
end

it 'uses net_http_persistent by default' do
expect_any_instance_of(Faraday::Connection).to receive(:adapter).with(:net_http_persistent)
adaptor_class.new(server_url).connect
end
describe 'the http_adaptor option' do
it 'uses net_http_persistent by default' do
expect_any_instance_of(Faraday::Connection).to receive(:adapter).with(:net_http_persistent)
adaptor_class.new(server_url).connect
end

it 'passes the :http_adaptor option to Faraday' do
expect_any_instance_of(Faraday::Connection).to receive(:adapter).with(:something)
adaptor_class.new(server_url, http_adaptor: :something).connect
end
it 'will pass through a symbol key' do
expect_any_instance_of(Faraday::Connection).to receive(:adapter).with(:something)
adaptor_class.new(server_url, http_adaptor: :something).connect
end

adaptors = Faraday::Adapter.instance_variable_get(:@registered_middleware).keys - [:test, :rack]
adaptors -= [:patron, :em_synchrony, :em_http] if RUBY_PLATFORM == 'java'
adaptors.each do |adaptor_name|
describe "the :#{adaptor_name} adaptor" do
let(:http_adaptor) { adaptor_name }
it_behaves_like 'Neo4j::Core::CypherSession::Adaptors::Http'
it 'will pass through a string key' do
expect_any_instance_of(Faraday::Connection).to receive(:adapter).with(:something)
adaptor_class.new(server_url, 'http_adaptor' => :something).connect
end

adaptors = Faraday::Adapter.instance_variable_get(:@registered_middleware).keys - [:test, :rack]
adaptors -= [:patron, :em_synchrony, :em_http] if RUBY_PLATFORM == 'java'
adaptors.each do |adaptor_name|
describe "the :#{adaptor_name} adaptor" do
let(:http_adaptor) { adaptor_name }
it_behaves_like 'Neo4j::Core::CypherSession::Adaptors::Http'
end
end
end
end
Expand Down

0 comments on commit c077648

Please sign in to comment.