From 635099ad87efe242c16df46860eed4827c4f75bc Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Thu, 17 Nov 2016 17:34:35 -0800 Subject: [PATCH 01/13] Allow :http_adapter creation option for http CypherSession --- Gemfile | 6 +++++ README.md | 25 +++++++++++++++++++ lib/neo4j-server/cypher_session.rb | 2 +- .../core/cypher_session/adaptors/http.rb | 7 ++++-- .../core/cypher_session/adaptors/http_spec.rb | 19 ++++++++++++++ spec/neo4j/core/shared_examples/http.rb | 6 +++++ 6 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 spec/neo4j/core/shared_examples/http.rb diff --git a/Gemfile b/Gemfile index 9eb142b3..e2719766 100644 --- a/Gemfile +++ b/Gemfile @@ -24,4 +24,10 @@ group 'test' do gem 'rspec', '~> 3.0' gem 'rspec-its' gem 'dotenv' + gem 'em-http-request', '>= 1.1', require: 'em-http' + gem 'em-synchrony', '>= 1.0.3', require: ['em-synchrony', 'em-synchrony/em-http'] + gem 'excon', '>= 0.27.4' + gem 'patron', '>= 0.4.2', platforms: :ruby + gem 'rack-test', '>= 0.6', require: 'rack/test' + gem 'typhoeus', '>= 0.3.3', platforms: [:ruby_18, :ruby_19, :ruby_20, :ruby_21, :ruby_22, :ruby_23] end diff --git a/README.md b/README.md index 8e603c90..448ee451 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,31 @@ A simple Ruby wrapper around the Neo4j graph database that works with the server and embedded Neo4j API. This gem can be used both from JRuby and normal MRI. It can be used standalone without the neo4j gem. +## Basic usage + +### Executing Cypher queries + +To make a basic connection to Neo4j to execute Cypher queries, first choose an adaptor. Adaptors for HTTP and Embedded mode (jRuby only) are available. You can create an adaptor like: + + http_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new('http://neo4j:pass@localhost:7474') + + # or + + neo4j_adaptor = Neo4j::Core::CypherSession::Adaptors::Embedded.new('/file/path/to/graph.db') + +The HTTP Adaptor can also take an `:http_adapter` option for `Faraday` (defaulting to `:net_http_persistent`): + + http_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new('http://neo4j:pass@localhost:7474', http_adapter: :typhoeus) + +Note you **must** install any required http adapter gems yourself as per [Faraday](https://github.com/lostisland/faraday). Ex for `:typhoeus`, add to your Gemfile: + + gem 'typhoeus' + +Once you have an adaptor you can create a session like so: + + neo4j_session = Neo4j::Core::CypherSession.new(http_adaptor) + + ## Documentation ### 3.0+ Documentation: diff --git a/lib/neo4j-server/cypher_session.rb b/lib/neo4j-server/cypher_session.rb index 9b3bc834..8d33b3e0 100644 --- a/lib/neo4j-server/cypher_session.rb +++ b/lib/neo4j-server/cypher_session.rb @@ -31,7 +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.use Faraday::Adapter::NetHttpPersistent + b.adapter :net_http_persistent # b.adapter Faraday.default_adapter end conn.headers = {'Content-Type' => 'application/json', 'User-Agent' => ::Neo4j::Session.user_agent_string} diff --git a/lib/neo4j/core/cypher_session/adaptors/http.rb b/lib/neo4j/core/cypher_session/adaptors/http.rb index 31b1d454..c6ef3e19 100644 --- a/lib/neo4j/core/cypher_session/adaptors/http.rb +++ b/lib/neo4j/core/cypher_session/adaptors/http.rb @@ -14,6 +14,7 @@ def initialize(url, _options = {}) @url = url @url_components = url_components!(url) @transaction_state = nil + @http_adapter = _options[:http_adapter] || :net_http_persistent end def connect @@ -136,12 +137,14 @@ def url_base end def connection + require 'typhoeus/adapters/faraday' if @http_adapter == :typhoeus + Faraday.new(@url) do |c| c.request :basic_auth, user, password c.request :multi_json c.response :multi_json, symbolize_keys: true, content_type: 'application/json' - c.use Faraday::Adapter::NetHttpPersistent + c.adapter @http_adapter c.headers['Content-Type'] = 'application/json' c.headers['User-Agent'] = user_agent_string @@ -184,4 +187,4 @@ def user_agent_string end end end -end +end \ No newline at end of file diff --git a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb index b81cd161..897ddcf9 100644 --- a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb +++ b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' require 'neo4j/core/cypher_session/adaptors/http' require './spec/neo4j/core/shared_examples/adaptor' +require './spec/neo4j/core/shared_examples/http' describe Neo4j::Core::CypherSession::Adaptors::HTTP, new_cypher_session: true do before(:all) { setup_http_request_subscription } @@ -16,6 +17,24 @@ expect { adaptor_class.new('https://localhost:7474/') }.not_to raise_error 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) + conn = adaptor_class.new(url).connect + end + + it 'passes the :http_adapter option to Faraday' do + expect_any_instance_of(Faraday::Connection).to receive(:adapter).with(:something) + conn = adaptor_class.new(url, http_adapter: :something).connect + end + + (Faraday::Adapter.instance_variable_get(:@registered_middleware).keys - [:test, :rack]).each do |adaptor_name| + describe "the :#{adaptor_name} adapter" do + let(:http_adaptor) { adaptor_name } + it_behaves_like 'Neo4j::Core::CypherSession::Adaptors::Http' + end + end + end let(:url) { ENV['NEO4J_URL'] } diff --git a/spec/neo4j/core/shared_examples/http.rb b/spec/neo4j/core/shared_examples/http.rb new file mode 100644 index 00000000..17bd76db --- /dev/null +++ b/spec/neo4j/core/shared_examples/http.rb @@ -0,0 +1,6 @@ +# Requires that an `http_adaptor` let variable exist with the Faraday adaptor name +RSpec.shared_examples 'Neo4j::Core::CypherSession::Adaptors::Http' do + it "should connect properly" do + Neo4j::Core::CypherSession::Adaptors::HTTP.new(url, http_adapter: http_adaptor).connect.get('/') + end +end \ No newline at end of file From 0586a5681751bb576299ea8320c3deaf14e06beb Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Thu, 17 Nov 2016 18:41:21 -0800 Subject: [PATCH 02/13] Harmonizing adaptor spelling --- README.md | 6 +++--- lib/neo4j/core/cypher_session/adaptors/http.rb | 6 +++--- spec/neo4j/core/cypher_session/adaptors/http_spec.rb | 6 +++--- spec/neo4j/core/shared_examples/http.rb | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 448ee451..915eb75f 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,11 @@ To make a basic connection to Neo4j to execute Cypher queries, first choose an a neo4j_adaptor = Neo4j::Core::CypherSession::Adaptors::Embedded.new('/file/path/to/graph.db') -The HTTP Adaptor can also take an `:http_adapter` option for `Faraday` (defaulting to `:net_http_persistent`): +The HTTP Adaptor can also take an `:http_adaptor` option for `Faraday` (defaulting to `:net_http_persistent`): - http_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new('http://neo4j:pass@localhost:7474', http_adapter: :typhoeus) + http_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new('http://neo4j:pass@localhost:7474', http_adaptor: :typhoeus) -Note you **must** install any required http adapter gems yourself as per [Faraday](https://github.com/lostisland/faraday). Ex for `:typhoeus`, add to your Gemfile: +Note you **must** install any required http adaptor gems yourself as per [Faraday](https://github.com/lostisland/faraday). Ex for `:typhoeus`, add to your Gemfile: gem 'typhoeus' diff --git a/lib/neo4j/core/cypher_session/adaptors/http.rb b/lib/neo4j/core/cypher_session/adaptors/http.rb index c6ef3e19..a765e454 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_adapter = _options[:http_adapter] || :net_http_persistent + @http_adaptor = _options[:http_adaptor] || :net_http_persistent end def connect @@ -137,14 +137,14 @@ def url_base end def connection - require 'typhoeus/adapters/faraday' if @http_adapter == :typhoeus + require 'typhoeus/adapters/faraday' if @http_adaptor == :typhoeus Faraday.new(@url) do |c| c.request :basic_auth, user, password c.request :multi_json c.response :multi_json, symbolize_keys: true, content_type: 'application/json' - c.adapter @http_adapter + c.adapter @http_adaptor c.headers['Content-Type'] = 'application/json' c.headers['User-Agent'] = user_agent_string diff --git a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb index 897ddcf9..8dd2fb75 100644 --- a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb +++ b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb @@ -23,13 +23,13 @@ conn = adaptor_class.new(url).connect end - it 'passes the :http_adapter option to Faraday' do + it 'passes the :http_adaptor option to Faraday' do expect_any_instance_of(Faraday::Connection).to receive(:adapter).with(:something) - conn = adaptor_class.new(url, http_adapter: :something).connect + conn = adaptor_class.new(url, http_adaptor: :something).connect end (Faraday::Adapter.instance_variable_get(:@registered_middleware).keys - [:test, :rack]).each do |adaptor_name| - describe "the :#{adaptor_name} adapter" do + describe "the :#{adaptor_name} adaptor" do let(:http_adaptor) { adaptor_name } it_behaves_like 'Neo4j::Core::CypherSession::Adaptors::Http' end diff --git a/spec/neo4j/core/shared_examples/http.rb b/spec/neo4j/core/shared_examples/http.rb index 17bd76db..0287ec25 100644 --- a/spec/neo4j/core/shared_examples/http.rb +++ b/spec/neo4j/core/shared_examples/http.rb @@ -1,6 +1,6 @@ # Requires that an `http_adaptor` let variable exist with the Faraday adaptor name RSpec.shared_examples 'Neo4j::Core::CypherSession::Adaptors::Http' do it "should connect properly" do - Neo4j::Core::CypherSession::Adaptors::HTTP.new(url, http_adapter: http_adaptor).connect.get('/') + Neo4j::Core::CypherSession::Adaptors::HTTP.new(url, http_adaptor: http_adaptor).connect.get('/') end end \ No newline at end of file From a5d63ffc521c6ae32a6232ae4c35a0ff504e3800 Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Thu, 17 Nov 2016 19:13:52 -0800 Subject: [PATCH 03/13] Fixing rubocop --- spec/neo4j/core/cypher_session/adaptors/http_spec.rb | 4 ++-- spec/neo4j/core/shared_examples/http.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb index 8dd2fb75..03d1ed52 100644 --- a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb +++ b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb @@ -20,12 +20,12 @@ it 'uses net_http_persistent by default' do expect_any_instance_of(Faraday::Connection).to receive(:adapter).with(:net_http_persistent) - conn = adaptor_class.new(url).connect + adaptor_class.new(url).connect end it 'passes the :http_adaptor option to Faraday' do expect_any_instance_of(Faraday::Connection).to receive(:adapter).with(:something) - conn = adaptor_class.new(url, http_adaptor: :something).connect + adaptor_class.new(url, http_adaptor: :something).connect end (Faraday::Adapter.instance_variable_get(:@registered_middleware).keys - [:test, :rack]).each do |adaptor_name| diff --git a/spec/neo4j/core/shared_examples/http.rb b/spec/neo4j/core/shared_examples/http.rb index 0287ec25..b11a3178 100644 --- a/spec/neo4j/core/shared_examples/http.rb +++ b/spec/neo4j/core/shared_examples/http.rb @@ -1,6 +1,6 @@ # Requires that an `http_adaptor` let variable exist with the Faraday adaptor name RSpec.shared_examples 'Neo4j::Core::CypherSession::Adaptors::Http' do - it "should connect properly" do + it 'should connect properly' do Neo4j::Core::CypherSession::Adaptors::HTTP.new(url, http_adaptor: http_adaptor).connect.get('/') end -end \ No newline at end of file +end From 62ea2566030d25f401ce057015df58940936f8bd Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Thu, 17 Nov 2016 19:30:22 -0800 Subject: [PATCH 04/13] Fixing rubocop --- lib/neo4j/core/cypher_session/adaptors/http.rb | 6 +++--- spec/neo4j/core/cypher_session/adaptors/http_spec.rb | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/neo4j/core/cypher_session/adaptors/http.rb b/lib/neo4j/core/cypher_session/adaptors/http.rb index a765e454..abbae126 100644 --- a/lib/neo4j/core/cypher_session/adaptors/http.rb +++ b/lib/neo4j/core/cypher_session/adaptors/http.rb @@ -10,11 +10,11 @@ class HTTP < Base # @transaction_state valid states # nil, :open_requested, :open, :close_requested - def initialize(url, _options = {}) + 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] || :net_http_persistent end def connect @@ -187,4 +187,4 @@ def user_agent_string end end end -end \ No newline at end of file +end diff --git a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb index 03d1ed52..d490501f 100644 --- a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb +++ b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb @@ -34,7 +34,6 @@ it_behaves_like 'Neo4j::Core::CypherSession::Adaptors::Http' end end - end let(:url) { ENV['NEO4J_URL'] } From 75ff92ebc7c6f87dc836794dc507e661c9ccb3ef Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Thu, 17 Nov 2016 20:43:38 -0800 Subject: [PATCH 05/13] Trying to fix JRuby --- Gemfile | 9 +++++---- spec/neo4j/core/cypher_session/adaptors/http_spec.rb | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index e2719766..6e6221eb 100644 --- a/Gemfile +++ b/Gemfile @@ -24,10 +24,11 @@ group 'test' do gem 'rspec', '~> 3.0' gem 'rspec-its' gem 'dotenv' - gem 'em-http-request', '>= 1.1', require: 'em-http' - gem 'em-synchrony', '>= 1.0.3', require: ['em-synchrony', 'em-synchrony/em-http'] + gem 'activesupport', '~> 4.0' + + gem 'em-http-request', '>= 1.1', require: 'em-http', platforms: :ruby + gem 'em-synchrony', '>= 1.0.3', require: ['em-synchrony', 'em-synchrony/em-http'], platforms: :ruby gem 'excon', '>= 0.27.4' gem 'patron', '>= 0.4.2', platforms: :ruby - gem 'rack-test', '>= 0.6', require: 'rack/test' - gem 'typhoeus', '>= 0.3.3', platforms: [:ruby_18, :ruby_19, :ruby_20, :ruby_21, :ruby_22, :ruby_23] + gem 'typhoeus', '>= 0.3.3' end diff --git a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb index d490501f..e9ff4c2b 100644 --- a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb +++ b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb @@ -28,7 +28,9 @@ adaptor_class.new(url, http_adaptor: :something).connect end - (Faraday::Adapter.instance_variable_get(:@registered_middleware).keys - [:test, :rack]).each do |adaptor_name| + 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' From c5e49533d824c9428cab5d05a530564fc69c14fa Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Thu, 17 Nov 2016 21:57:19 -0800 Subject: [PATCH 06/13] Fixing specs --- spec/neo4j/core/cypher_session/adaptors/http_spec.rb | 7 +++---- spec/neo4j/core/shared_examples/http.rb | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb index e9ff4c2b..632dd6d9 100644 --- a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb +++ b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb @@ -20,12 +20,12 @@ it 'uses net_http_persistent by default' do expect_any_instance_of(Faraday::Connection).to receive(:adapter).with(:net_http_persistent) - adaptor_class.new(url).connect + 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(url, http_adaptor: :something).connect + adaptor_class.new(server_url, http_adaptor: :something).connect end adaptors = Faraday::Adapter.instance_variable_get(:@registered_middleware).keys - [:test, :rack] @@ -38,8 +38,7 @@ end end - let(:url) { ENV['NEO4J_URL'] } - let(:adaptor) { adaptor_class.new(url) } + let(:adaptor) { adaptor_class.new(server_url) } before { adaptor.connect } diff --git a/spec/neo4j/core/shared_examples/http.rb b/spec/neo4j/core/shared_examples/http.rb index b11a3178..67656530 100644 --- a/spec/neo4j/core/shared_examples/http.rb +++ b/spec/neo4j/core/shared_examples/http.rb @@ -1,6 +1,6 @@ # Requires that an `http_adaptor` let variable exist with the Faraday adaptor name RSpec.shared_examples 'Neo4j::Core::CypherSession::Adaptors::Http' do it 'should connect properly' do - Neo4j::Core::CypherSession::Adaptors::HTTP.new(url, http_adaptor: http_adaptor).connect.get('/') + Neo4j::Core::CypherSession::Adaptors::HTTP.new(server_url, http_adaptor: http_adaptor).connect.get('/') end end From 16815fc144c250168e16ccba2fa5d93b1370c913 Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Thu, 17 Nov 2016 22:34:22 -0800 Subject: [PATCH 07/13] Fixing gem dependency --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 6e6221eb..1c664bac 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,7 @@ group 'test' do gem 'rspec', '~> 3.0' gem 'rspec-its' gem 'dotenv' - gem 'activesupport', '~> 4.0' + gem 'activesupport', '>= 4.0' gem 'em-http-request', '>= 1.1', require: 'em-http', platforms: :ruby gem 'em-synchrony', '>= 1.0.3', require: ['em-synchrony', 'em-synchrony/em-http'], platforms: :ruby From 4a2e8784a630275d35397833d184580e657013f7 Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Thu, 17 Nov 2016 22:42:20 -0800 Subject: [PATCH 08/13] Hopefully actually fixing the Gemfile dependency issue --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 1c664bac..7bac0bdb 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,7 @@ group 'test' do gem 'rspec', '~> 3.0' gem 'rspec-its' gem 'dotenv' - gem 'activesupport', '>= 4.0' + gem 'activesupport', '>= 4.0' unless RUBY_VERSION.to_f < 2.2 gem 'em-http-request', '>= 1.1', require: 'em-http', platforms: :ruby gem 'em-synchrony', '>= 1.0.3', require: ['em-synchrony', 'em-synchrony/em-http'], platforms: :ruby From c077648aee114c3e65f0c20a8c60f5f05e38a202 Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Fri, 18 Nov 2016 01:04:13 -0800 Subject: [PATCH 09/13] 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 From 92e2816c5aa4880d4aa1f05d2559d1029d908fc3 Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Fri, 18 Nov 2016 01:52:30 -0800 Subject: [PATCH 10/13] Fully test the CypherSession connections --- lib/neo4j-server/cypher_session.rb | 5 ++++- spec/neo4j-server/e2e/cypher_session_spec.rb | 8 ++++++++ spec/neo4j-server/shared_examples/cypher_session.rb | 6 ++++++ spec/neo4j/core/cypher_session/adaptors/http_spec.rb | 6 ++---- spec/neo4j/core/shared_examples/http.rb | 2 +- spec/spec_helper.rb | 8 ++++++++ 6 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 spec/neo4j-server/shared_examples/cypher_session.rb diff --git a/lib/neo4j-server/cypher_session.rb b/lib/neo4j-server/cypher_session.rb index e009c5b0..0a1cccab 100644 --- a/lib/neo4j-server/cypher_session.rb +++ b/lib/neo4j-server/cypher_session.rb @@ -23,6 +23,9 @@ def initialize(data_url, connection) # @return [Faraday] # @see https://github.com/lostisland/faraday def self.create_connection(params, url = nil) + http_adaptor = (params.delete(:http_adaptor) || params.delete('http_adaptor') || :net_http_persistent).to_sym + require 'typhoeus/adapters/faraday' if http_adaptor == :typhoeus + init_params = params[:initialize] && params.delete(:initialize) conn = Faraday.new(url, init_params) do |b| b.request :basic_auth, params[:basic_auth][:username], params[:basic_auth][:password] if params[:basic_auth] @@ -31,7 +34,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 (params.delete(:http_adaptor) || params.delete('http_adaptor') || :net_http_persistent).to_sym + b.adapter http_adaptor end conn.headers = {'Content-Type' => 'application/json', 'User-Agent' => ::Neo4j::Session.user_agent_string} conn diff --git a/spec/neo4j-server/e2e/cypher_session_spec.rb b/spec/neo4j-server/e2e/cypher_session_spec.rb index 71b411ae..a3a56a36 100644 --- a/spec/neo4j-server/e2e/cypher_session_spec.rb +++ b/spec/neo4j-server/e2e/cypher_session_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require './spec/neo4j-server/shared_examples/cypher_session' module Neo4j module Server @@ -48,6 +49,13 @@ def open_session expect(Neo4j::Server::CypherSession).to receive(:open).with(anything, hash_including('http_adaptor' => :something)) create_server_session('http_adaptor' => :something) end + + with_each_faraday_adaptor do |adaptor_name| + describe "when set to :#{adaptor_name}" do + let(:http_adaptor) { adaptor_name } + it_behaves_like 'Neo4j::Server::CypherSession' + end + end end end diff --git a/spec/neo4j-server/shared_examples/cypher_session.rb b/spec/neo4j-server/shared_examples/cypher_session.rb new file mode 100644 index 00000000..2f62c2ea --- /dev/null +++ b/spec/neo4j-server/shared_examples/cypher_session.rb @@ -0,0 +1,6 @@ +# Requires that an `http_adaptor` let variable exist with the Faraday adaptor name +RSpec.shared_examples 'Neo4j::Server::CypherSession' do + it 'should be able to connect and query' do + create_server_session(http_adaptor: http_adaptor).query.create('(n)').return('ID(n) AS id').first[:id] + 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 84a4d8c3..8e1a7a32 100644 --- a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb +++ b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb @@ -34,12 +34,10 @@ 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| + with_each_faraday_adaptor do |adaptor_name| describe "the :#{adaptor_name} adaptor" do let(:http_adaptor) { adaptor_name } - it_behaves_like 'Neo4j::Core::CypherSession::Adaptors::Http' + it_behaves_like 'Neo4j::Core::CypherSession::Adaptors::HTTP' end end end diff --git a/spec/neo4j/core/shared_examples/http.rb b/spec/neo4j/core/shared_examples/http.rb index 67656530..e633ab61 100644 --- a/spec/neo4j/core/shared_examples/http.rb +++ b/spec/neo4j/core/shared_examples/http.rb @@ -1,5 +1,5 @@ # Requires that an `http_adaptor` let variable exist with the Faraday adaptor name -RSpec.shared_examples 'Neo4j::Core::CypherSession::Adaptors::Http' do +RSpec.shared_examples 'Neo4j::Core::CypherSession::Adaptors::HTTP' do it 'should connect properly' do Neo4j::Core::CypherSession::Adaptors::HTTP.new(server_url, http_adaptor: http_adaptor).connect.get('/') end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0e081f9e..9493f670 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -154,3 +154,11 @@ def setup_http_request_subscription end } end + +def with_each_faraday_adaptor + 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| + yield adaptor_name + end +end From c40f8e273d80a715d9ac9e5414fc8e6cab92fe74 Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Fri, 18 Nov 2016 02:19:48 -0800 Subject: [PATCH 11/13] Fixing Rubocop and JRuby gem dependency --- Gemfile | 1 + lib/neo4j-server/cypher_session.rb | 2 ++ spec/neo4j-server/e2e/cypher_session_spec.rb | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 7bac0bdb..f9df56b5 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,7 @@ group 'development' do end group 'test' do + gem 'term-ansicolor', '~> 1.3.0' if RUBY_VERSION.to_f < 2.0 gem 'coveralls', require: false gem 'simplecov-html', require: false gem 'tins', '< 1.7' if RUBY_VERSION.to_f < 2.0 diff --git a/lib/neo4j-server/cypher_session.rb b/lib/neo4j-server/cypher_session.rb index 0a1cccab..fe796901 100644 --- a/lib/neo4j-server/cypher_session.rb +++ b/lib/neo4j-server/cypher_session.rb @@ -22,6 +22,7 @@ def initialize(data_url, connection) # @param [Hash] params could be empty or contain basic authentication user and password # @return [Faraday] # @see https://github.com/lostisland/faraday + # rubocop:disable AbcSize def self.create_connection(params, url = nil) http_adaptor = (params.delete(:http_adaptor) || params.delete('http_adaptor') || :net_http_persistent).to_sym require 'typhoeus/adapters/faraday' if http_adaptor == :typhoeus @@ -39,6 +40,7 @@ def self.create_connection(params, url = nil) conn.headers = {'Content-Type' => 'application/json', 'User-Agent' => ::Neo4j::Session.user_agent_string} conn end + # rubocop:enable AbcSize # Opens a session to the database # @see Neo4j::Session#open diff --git a/spec/neo4j-server/e2e/cypher_session_spec.rb b/spec/neo4j-server/e2e/cypher_session_spec.rb index a3a56a36..e00e57e8 100644 --- a/spec/neo4j-server/e2e/cypher_session_spec.rb +++ b/spec/neo4j-server/e2e/cypher_session_spec.rb @@ -45,7 +45,7 @@ def open_session create_server_session(http_adaptor: :something) end - it "will pass through a string key" do + 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 From 9f0debce4bf6ea680f4629d7bbd515ff8ec67a6a Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Fri, 18 Nov 2016 02:30:40 -0800 Subject: [PATCH 12/13] Figured out how to properly use .rubocop_todo.yml --- .rubocop_todo.yml | 24 +++++++++++------------- lib/neo4j-server/cypher_session.rb | 2 -- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0e8cb13e..669ac975 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2015-09-07 09:42:54 +1200 using RuboCop version 0.34.0. +# on 2016-11-18 02:29:17 -0800 using RuboCop version 0.34.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -31,29 +31,29 @@ Lint/UnusedMethodArgument: - 'lib/neo4j/session.rb' - 'lib/neo4j/transaction.rb' -# Offense count: 15 +# Offense count: 19 Metrics/AbcSize: - Max: 17 + Max: 20 -# Offense count: 8 +# Offense count: 9 # Configuration parameters: CountComments. Metrics/ClassLength: Max: 190 -# Offense count: 419 +# Offense count: 513 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 180 -# Offense count: 17 +# Offense count: 21 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 14 -# Offense count: 3 +# Offense count: 1 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 174 + Max: 129 # Offense count: 8 Style/AccessorMethodName: @@ -71,15 +71,13 @@ Style/ClassVars: Exclude: - 'lib/neo4j/session.rb' -# Offense count: 67 +# Offense count: 81 +# Configuration parameters: Exclude. Style/Documentation: Enabled: false -# Offense count: 4 +# Offense count: 1 # Cop supports --auto-correct. Style/RescueEnsureAlignment: Exclude: - - 'lib/neo4j-embedded/label.rb' - - 'spec/shared_examples/label.rb' - 'spec/shared_examples/node_with_tx.rb' - diff --git a/lib/neo4j-server/cypher_session.rb b/lib/neo4j-server/cypher_session.rb index fe796901..0a1cccab 100644 --- a/lib/neo4j-server/cypher_session.rb +++ b/lib/neo4j-server/cypher_session.rb @@ -22,7 +22,6 @@ def initialize(data_url, connection) # @param [Hash] params could be empty or contain basic authentication user and password # @return [Faraday] # @see https://github.com/lostisland/faraday - # rubocop:disable AbcSize def self.create_connection(params, url = nil) http_adaptor = (params.delete(:http_adaptor) || params.delete('http_adaptor') || :net_http_persistent).to_sym require 'typhoeus/adapters/faraday' if http_adaptor == :typhoeus @@ -40,7 +39,6 @@ def self.create_connection(params, url = nil) conn.headers = {'Content-Type' => 'application/json', 'User-Agent' => ::Neo4j::Session.user_agent_string} conn end - # rubocop:enable AbcSize # Opens a session to the database # @see Neo4j::Session#open From 5c5aa6b02386d5b75f452a608559b67883c671ad Mon Sep 17 00:00:00 2001 From: Bruce Krysiak Date: Mon, 21 Nov 2016 16:11:38 -0800 Subject: [PATCH 13/13] Moving to faraday_options --- .rubocop_todo.yml | 18 +++++++---- README.md | 4 +-- lib/neo4j-server/cypher_session.rb | 7 +++-- .../core/cypher_session/adaptors/http.rb | 7 +++-- spec/neo4j-server/e2e/cypher_session_spec.rb | 30 +++++++++++-------- .../shared_examples/cypher_session.rb | 2 +- .../core/cypher_session/adaptors/http_spec.rb | 10 +++---- spec/neo4j/core/shared_examples/http.rb | 2 +- 8 files changed, 47 insertions(+), 33 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 669ac975..991677ed 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2016-11-18 02:29:17 -0800 using RuboCop version 0.34.2. +# on 2016-11-21 16:05:50 -0800 using RuboCop version 0.34.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -31,16 +31,20 @@ Lint/UnusedMethodArgument: - 'lib/neo4j/session.rb' - 'lib/neo4j/transaction.rb' -# Offense count: 19 +# Offense count: 20 Metrics/AbcSize: - Max: 20 + Max: 23 # Offense count: 9 # Configuration parameters: CountComments. Metrics/ClassLength: Max: 190 -# Offense count: 513 +# Offense count: 1 +Metrics/CyclomaticComplexity: + Max: 8 + +# Offense count: 517 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 180 @@ -53,7 +57,11 @@ Metrics/MethodLength: # Offense count: 1 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 129 + Max: 133 + +# Offense count: 1 +Metrics/PerceivedComplexity: + Max: 8 # Offense count: 8 Style/AccessorMethodName: diff --git a/README.md b/README.md index 915eb75f..d39437a8 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ To make a basic connection to Neo4j to execute Cypher queries, first choose an a neo4j_adaptor = Neo4j::Core::CypherSession::Adaptors::Embedded.new('/file/path/to/graph.db') -The HTTP Adaptor can also take an `:http_adaptor` option for `Faraday` (defaulting to `:net_http_persistent`): +The HTTP Adaptor can also take `:faraday_options`. Currently, only :adapter is supported (defaulting to `:net_http_persistent`): - http_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new('http://neo4j:pass@localhost:7474', http_adaptor: :typhoeus) + http_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new('http://neo4j:pass@localhost:7474', faraday_options: { adapter: :typhoeus }) Note you **must** install any required http adaptor gems yourself as per [Faraday](https://github.com/lostisland/faraday). Ex for `:typhoeus`, add to your Gemfile: diff --git a/lib/neo4j-server/cypher_session.rb b/lib/neo4j-server/cypher_session.rb index 0a1cccab..98f58e27 100644 --- a/lib/neo4j-server/cypher_session.rb +++ b/lib/neo4j-server/cypher_session.rb @@ -23,8 +23,9 @@ def initialize(data_url, connection) # @return [Faraday] # @see https://github.com/lostisland/faraday def self.create_connection(params, url = nil) - http_adaptor = (params.delete(:http_adaptor) || params.delete('http_adaptor') || :net_http_persistent).to_sym - require 'typhoeus/adapters/faraday' if http_adaptor == :typhoeus + faraday_options = params.delete(:faraday_options) || params.delete('faraday_options') || {} + adapter = (faraday_options[:adapter] || faraday_options['adapter'] || :net_http_persistent).to_sym + require 'typhoeus/adapters/faraday' if adapter == :typhoeus init_params = params[:initialize] && params.delete(:initialize) conn = Faraday.new(url, init_params) do |b| @@ -34,7 +35,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 http_adaptor + b.adapter adapter 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 aad9b9f6..1ba89653 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] || options['http_adaptor'] || :net_http_persistent).to_sym + @faraday_options = options[:faraday_options] || options['faraday_options'] || {} end def connect @@ -137,14 +137,15 @@ def url_base end def connection - require 'typhoeus/adapters/faraday' if @http_adaptor == :typhoeus + adapter = (@faraday_options[:adapter] || @faraday_options['adapter'] || :net_http_persistent).to_sym + require 'typhoeus/adapters/faraday' if adapter == :typhoeus Faraday.new(@url) do |c| c.request :basic_auth, user, password c.request :multi_json c.response :multi_json, symbolize_keys: true, content_type: 'application/json' - c.adapter @http_adaptor + c.adapter adapter c.headers['Content-Type'] = 'application/json' c.headers['User-Agent'] = user_agent_string diff --git a/spec/neo4j-server/e2e/cypher_session_spec.rb b/spec/neo4j-server/e2e/cypher_session_spec.rb index e00e57e8..35f029e2 100644 --- a/spec/neo4j-server/e2e/cypher_session_spec.rb +++ b/spec/neo4j-server/e2e/cypher_session_spec.rb @@ -39,21 +39,25 @@ def open_session 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 + describe 'faraday_options' do + describe 'the http_adaptor options' do + it 'will pass through a symbol key' do + faraday_hash = {farday_options: {adapter: :something}} + expect(Neo4j::Server::CypherSession).to receive(:open).with(anything, hash_including(faraday_hash)) + create_server_session(faraday_hash) + 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 + it 'will pass through a string key' do + faraday_hash = {farday_options: {adapter: :something}} + expect(Neo4j::Server::CypherSession).to receive(:open).with(anything, hash_including(faraday_hash)) + create_server_session(faraday_hash) + end - with_each_faraday_adaptor do |adaptor_name| - describe "when set to :#{adaptor_name}" do - let(:http_adaptor) { adaptor_name } - it_behaves_like 'Neo4j::Server::CypherSession' + with_each_faraday_adaptor do |adapter_name| + describe "when set to :#{adapter_name}" do + let(:adapter) { adapter_name } + it_behaves_like 'Neo4j::Server::CypherSession' + end end end end diff --git a/spec/neo4j-server/shared_examples/cypher_session.rb b/spec/neo4j-server/shared_examples/cypher_session.rb index 2f62c2ea..9abb6df8 100644 --- a/spec/neo4j-server/shared_examples/cypher_session.rb +++ b/spec/neo4j-server/shared_examples/cypher_session.rb @@ -1,6 +1,6 @@ # Requires that an `http_adaptor` let variable exist with the Faraday adaptor name RSpec.shared_examples 'Neo4j::Server::CypherSession' do it 'should be able to connect and query' do - create_server_session(http_adaptor: http_adaptor).query.create('(n)').return('ID(n) AS id').first[:id] + create_server_session(faraday_options: {adapter: adapter}).query.create('(n)').return('ID(n) AS id').first[:id] 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 8e1a7a32..647a6dd8 100644 --- a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb +++ b/spec/neo4j/core/cypher_session/adaptors/http_spec.rb @@ -26,17 +26,17 @@ 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 + adaptor_class.new(server_url, faraday_options: {adapter: :something}).connect end 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 + adaptor_class.new(server_url, faraday_options: {'adapter' => :something}).connect end - with_each_faraday_adaptor do |adaptor_name| - describe "the :#{adaptor_name} adaptor" do - let(:http_adaptor) { adaptor_name } + with_each_faraday_adaptor do |adapter_name| + describe "the :#{adapter_name} adaptor" do + let(:adapter) { adapter_name } it_behaves_like 'Neo4j::Core::CypherSession::Adaptors::HTTP' end end diff --git a/spec/neo4j/core/shared_examples/http.rb b/spec/neo4j/core/shared_examples/http.rb index e633ab61..96cebf90 100644 --- a/spec/neo4j/core/shared_examples/http.rb +++ b/spec/neo4j/core/shared_examples/http.rb @@ -1,6 +1,6 @@ # Requires that an `http_adaptor` let variable exist with the Faraday adaptor name RSpec.shared_examples 'Neo4j::Core::CypherSession::Adaptors::HTTP' do it 'should connect properly' do - Neo4j::Core::CypherSession::Adaptors::HTTP.new(server_url, http_adaptor: http_adaptor).connect.get('/') + Neo4j::Core::CypherSession::Adaptors::HTTP.new(server_url, faraday_options: {adapter: adapter}).connect.get('/') end end