From c077648aee114c3e65f0c20a8c60f5f05e38a202 Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Fri, 18 Nov 2016 01:04:13 -0800 Subject: [PATCH] Allowing http_adaptor key as either string or symbol --- lib/neo4j-server/cypher_session.rb | 3 +- .../core/cypher_session/adaptors/http.rb | 2 +- spec/neo4j-server/e2e/cypher_session_spec.rb | 12 +++++++ .../core/cypher_session/adaptors/http_spec.rb | 35 +++++++++++-------- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/lib/neo4j-server/cypher_session.rb b/lib/neo4j-server/cypher_session.rb index 8d33b3e0..e009c5b0 100644 --- a/lib/neo4j-server/cypher_session.rb +++ b/lib/neo4j-server/cypher_session.rb @@ -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 diff --git a/lib/neo4j/core/cypher_session/adaptors/http.rb b/lib/neo4j/core/cypher_session/adaptors/http.rb index abbae126..aad9b9f6 100644 --- a/lib/neo4j/core/cypher_session/adaptors/http.rb +++ b/lib/neo4j/core/cypher_session/adaptors/http.rb @@ -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 diff --git a/spec/neo4j-server/e2e/cypher_session_spec.rb b/spec/neo4j-server/e2e/cypher_session_spec.rb index b1a6222d..71b411ae 100644 --- a/spec/neo4j-server/e2e/cypher_session_spec.rb +++ b/spec/neo4j-server/e2e/cypher_session_spec.rb @@ -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 diff --git a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb index 632dd6d9..84a4d8c3 100644 --- a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb +++ b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb @@ -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