diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ed7febd..555f07c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Changed -- Raise standard `Neo4j::Core::CypherSession::ConnectionFailedError` error instead of individual errors from adaptors +- Raise standard `Neo4j::Core::CypherSession::ConnectionFailedError` error instead of individual errors from adapters ## [7.0.0.alpha.3] - 2016-08-04 @@ -145,7 +145,7 @@ This release contains no changes since the last alpha. Below are all modificatio ### Added -- New session, adaptors, and rewritten Node, Relationship, and Path classes. They are not yet in use but are part of ongoing refactoring and rebuilding. +- New session, adapters, and rewritten Node, Relationship, and Path classes. They are not yet in use but are part of ongoing refactoring and rebuilding. ### Fixed @@ -190,7 +190,7 @@ This release contains no changes since the last alpha. Below are all modificatio - Refactored `Neo4j::Label#create_index` and `Neo4j::Label#create_constraint` to have compatible signatures. As part of the refactoring of `Neo4j::Label#creator_index`, the method no longer accepts multiple properties. The method will need to be called once for each, when needed. ### Added -- New session, adaptors, and rewritten Node, Relationship, and Path classes. They are not yet in use but are part of ongoing refactoring and rebuilding. +- New session, adapters, and rewritten Node, Relationship, and Path classes. They are not yet in use but are part of ongoing refactoring and rebuilding. ## [5.1.12] - 2015-11-23 diff --git a/README.md b/README.md index ac54d9c9..67725ab7 100644 --- a/README.md +++ b/README.md @@ -7,17 +7,17 @@ It can be used standalone without the neo4j gem. ### 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 (support for Neo4j 3.0's [Bolt protocol](http://alpha.neohq.net/docs/server-manual/bolt.html) is planned). You can create an adaptor like: +To make a basic connection to Neo4j to execute Cypher queries, first choose an adapter. Adapters for HTTP and Embedded mode (jRuby only) are available (support for Neo4j 3.0's [Bolt protocol](http://alpha.neohq.net/docs/server-manual/bolt.html) is planned). You can create an adapter like: - http_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new('http://neo4j:pass@localhost:7474') + http_adapter = Neo4j::Core::CypherSession::Adapters::HTTP.new('http://neo4j:pass@localhost:7474') # or - neo4j_adaptor = Neo4j::Core::CypherSession::Adaptors::Embedded.new('/file/path/to/graph.db') + neo4j_adapter = Neo4j::Core::CypherSession::Adapters::Embedded.new('/file/path/to/graph.db') -Once you have an adaptor you can create a session like so: +Once you have an adapter you can create a session like so: - neo4j_session = Neo4j::Core::CypherSession.new(http_adaptor) + neo4j_session = Neo4j::Core::CypherSession.new(http_adapter) From there you can make queries with a Cypher string: @@ -33,7 +33,7 @@ Or via the `Neo4j::Core::Query` class neo4j_session.query(query_obj) -Making multiple queries with one request is support with the HTTP Adaptor: +Making multiple queries with one request is support with the HTTP Adapter: results = neo4j_session.queries do append 'MATCH (n:Foo) RETURN n LIMIT 10' diff --git a/lib/neo4j-embedded/embedded_session.rb b/lib/neo4j-embedded/embedded_session.rb index b16451f4..d730b70b 100644 --- a/lib/neo4j-embedded/embedded_session.rb +++ b/lib/neo4j-embedded/embedded_session.rb @@ -77,7 +77,7 @@ def self.transaction_class Neo4j::Embedded::EmbeddedTransaction end - # Duplicate of CypherSession::Adaptor::Base#transaction + # Duplicate of CypherSession::Adapter::Base#transaction def transaction return self.class.transaction_class.new(self) if !block_given? diff --git a/lib/neo4j-server/cypher_session.rb b/lib/neo4j-server/cypher_session.rb index d49aee5d..e8377186 100644 --- a/lib/neo4j-server/cypher_session.rb +++ b/lib/neo4j-server/cypher_session.rb @@ -94,7 +94,7 @@ def self.transaction_class Neo4j::Server::CypherTransaction end - # Duplicate of CypherSession::Adaptor::Base#transaction + # Duplicate of CypherSession::Adapter::Base#transaction def transaction return self.class.transaction_class.new(self) if !block_given? diff --git a/lib/neo4j/core/cypher_session.rb b/lib/neo4j/core/cypher_session.rb index 83e18aba..d527a871 100644 --- a/lib/neo4j/core/cypher_session.rb +++ b/lib/neo4j/core/cypher_session.rb @@ -1,14 +1,14 @@ module Neo4j module Core class CypherSession - attr_reader :adaptor + attr_reader :adapter - def initialize(adaptor) - fail ArgumentError, "Invalid adaptor: #{adaptor.inspect}" if !adaptor.is_a?(Adaptors::Base) + def initialize(adapter) + fail ArgumentError, "Invalid adapter: #{adapter.inspect}" if !adapter.is_a?(Adapters::Base) - @adaptor = adaptor + @adapter = adapter - @adaptor.connect + @adapter.connect end def transaction_class @@ -19,7 +19,7 @@ def transaction_class version ).each do |method, &_block| define_method(method) do |*args, &block| - @adaptor.send(method, *args, &block) + @adapter.send(method, *args, &block) end end @@ -33,7 +33,7 @@ def transaction_class constraints ).each do |method, &_block| define_method(method) do |*args, &block| - @adaptor.send(method, self, *args, &block) + @adapter.send(method, self, *args, &block) end end end diff --git a/lib/neo4j/core/cypher_session/adaptors.rb b/lib/neo4j/core/cypher_session/adapters.rb similarity index 98% rename from lib/neo4j/core/cypher_session/adaptors.rb rename to lib/neo4j/core/cypher_session/adapters.rb index 713f9148..c1964c9d 100644 --- a/lib/neo4j/core/cypher_session/adaptors.rb +++ b/lib/neo4j/core/cypher_session/adapters.rb @@ -47,7 +47,7 @@ class IndexAlreadyExistsError < CypherError; end end class ConnectionFailedError < StandardError; end - module Adaptors + module Adapters MAP = {} class Base @@ -124,7 +124,7 @@ def queries(session, options = {}, &block) :constraints, :connected?].each do |method| define_method(method) do |*_args| - fail "##{method} method not implemented on adaptor!" + fail "##{method} method not implemented on adapter!" end end @@ -188,7 +188,7 @@ def instrument_queries(queries) end def transaction_class - fail '.transaction_class method not implemented on adaptor!' + fail '.transaction_class method not implemented on adapter!' end end diff --git a/lib/neo4j/core/cypher_session/adaptors/bolt.rb b/lib/neo4j/core/cypher_session/adapters/bolt.rb similarity index 97% rename from lib/neo4j/core/cypher_session/adaptors/bolt.rb rename to lib/neo4j/core/cypher_session/adapters/bolt.rb index 335ed85e..79052ccd 100644 --- a/lib/neo4j/core/cypher_session/adaptors/bolt.rb +++ b/lib/neo4j/core/cypher_session/adapters/bolt.rb @@ -1,7 +1,7 @@ -require 'neo4j/core/cypher_session/adaptors' -require 'neo4j/core/cypher_session/adaptors/has_uri' -require 'neo4j/core/cypher_session/adaptors/bolt/pack_stream' -require 'neo4j/core/cypher_session/adaptors/bolt/chunk_writer_io' +require 'neo4j/core/cypher_session/adapters' +require 'neo4j/core/cypher_session/adapters/has_uri' +require 'neo4j/core/cypher_session/adapters/bolt/pack_stream' +require 'neo4j/core/cypher_session/adapters/bolt/chunk_writer_io' require 'neo4j/core/cypher_session/responses/bolt' require 'io/wait' @@ -9,9 +9,9 @@ module Neo4j module Core class CypherSession - module Adaptors + module Adapters class Bolt < Base - include Adaptors::HasUri + include Adapters::HasUri default_url('bolt://neo4:neo4j@localhost:7687') validate_uri do |uri| uri.scheme == 'bolt' diff --git a/lib/neo4j/core/cypher_session/adaptors/bolt/chunk_writer_io.rb b/lib/neo4j/core/cypher_session/adapters/bolt/chunk_writer_io.rb similarity index 100% rename from lib/neo4j/core/cypher_session/adaptors/bolt/chunk_writer_io.rb rename to lib/neo4j/core/cypher_session/adapters/bolt/chunk_writer_io.rb diff --git a/lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb b/lib/neo4j/core/cypher_session/adapters/bolt/pack_stream.rb similarity index 100% rename from lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream.rb rename to lib/neo4j/core/cypher_session/adapters/bolt/pack_stream.rb diff --git a/lib/neo4j/core/cypher_session/adaptors/embedded.rb b/lib/neo4j/core/cypher_session/adapters/embedded.rb similarity index 96% rename from lib/neo4j/core/cypher_session/adaptors/embedded.rb rename to lib/neo4j/core/cypher_session/adapters/embedded.rb index dc6ac26b..e7de95f2 100644 --- a/lib/neo4j/core/cypher_session/adaptors/embedded.rb +++ b/lib/neo4j/core/cypher_session/adapters/embedded.rb @@ -1,11 +1,11 @@ -require 'neo4j/core/cypher_session/adaptors' +require 'neo4j/core/cypher_session/adapters' require 'neo4j/core/cypher_session/responses/embedded' require 'active_support/hash_with_indifferent_access' module Neo4j module Core class CypherSession - module Adaptors + module Adapters class Embedded < Base attr_reader :graph_db, :path @@ -52,7 +52,7 @@ def version def indexes(session, _label = nil) Transaction.run(session) do - graph_db = session.adaptor.graph_db + graph_db = session.adapter.graph_db graph_db.schema.get_indexes.map do |definition| {properties: definition.property_keys.map(&:to_sym), @@ -100,7 +100,7 @@ def execution_results(queries) end def all_labels(session) - Java::OrgNeo4jTooling::GlobalGraphOperations.at(session.adaptor.graph_db).get_all_labels.to_a + Java::OrgNeo4jTooling::GlobalGraphOperations.at(session.adapter.graph_db).get_all_labels.to_a end def indifferent_params(query) diff --git a/lib/neo4j/core/cypher_session/adaptors/has_uri.rb b/lib/neo4j/core/cypher_session/adapters/has_uri.rb similarity index 94% rename from lib/neo4j/core/cypher_session/adaptors/has_uri.rb rename to lib/neo4j/core/cypher_session/adapters/has_uri.rb index afec36b0..8f14b2e7 100644 --- a/lib/neo4j/core/cypher_session/adaptors/has_uri.rb +++ b/lib/neo4j/core/cypher_session/adapters/has_uri.rb @@ -3,8 +3,8 @@ module Neo4j module Core class CypherSession - module Adaptors - # Containing the logic for dealing with adaptors which use URIs + module Adapters + # Containing the logic for dealing with adapters which use URIs module HasUri extend ActiveSupport::Concern diff --git a/lib/neo4j/core/cypher_session/adaptors/http.rb b/lib/neo4j/core/cypher_session/adapters/http.rb similarity index 97% rename from lib/neo4j/core/cypher_session/adaptors/http.rb rename to lib/neo4j/core/cypher_session/adapters/http.rb index c1019a3e..10277b63 100644 --- a/lib/neo4j/core/cypher_session/adaptors/http.rb +++ b/lib/neo4j/core/cypher_session/adapters/http.rb @@ -1,12 +1,12 @@ -require 'neo4j/core/cypher_session/adaptors' -require 'neo4j/core/cypher_session/adaptors/has_uri' +require 'neo4j/core/cypher_session/adapters' +require 'neo4j/core/cypher_session/adapters/has_uri' require 'neo4j/core/cypher_session/responses/http' # TODO: Work with `Query` objects module Neo4j module Core class CypherSession - module Adaptors + module Adapters class HTTP < Base attr_reader :requestor, :url @@ -90,7 +90,7 @@ def connected? # - Takes care of JSONifying objects passed as body (Hash/Array/Query) # - Sets headers, including user agent string class Requestor - include Adaptors::HasUri + include Adapters::HasUri default_url('http://neo4:neo4j@localhost:7474') validate_uri { |uri| uri.is_a?(URI::HTTP) } diff --git a/lib/neo4j/core/cypher_session/transactions.rb b/lib/neo4j/core/cypher_session/transactions.rb index 8f1a4de9..3e805a63 100644 --- a/lib/neo4j/core/cypher_session/transactions.rb +++ b/lib/neo4j/core/cypher_session/transactions.rb @@ -12,19 +12,19 @@ def query(*args) end options[:transaction] ||= self - adaptor.query(@session, *args) + adapter.query(@session, *args) end def queries(options = {}, &block) - adaptor.queries(@session, {transaction: self}.merge(options), &block) + adapter.queries(@session, {transaction: self}.merge(options), &block) end private # Because we're inheriting from the old Transaction class - # but the new adaptors work much like the old sessions - def adaptor - @session.adaptor + # but the new adapters work much like the old sessions + def adapter + @session.adapter end end end diff --git a/lib/neo4j/core/cypher_session/transactions/bolt.rb b/lib/neo4j/core/cypher_session/transactions/bolt.rb index a53ca246..db403f2b 100644 --- a/lib/neo4j/core/cypher_session/transactions/bolt.rb +++ b/lib/neo4j/core/cypher_session/transactions/bolt.rb @@ -26,8 +26,8 @@ def started? private def tx_query(cypher) - query = Adaptors::Base::Query.new(cypher, {}, cypher) - adaptor.send(:query_set, self, [query], skip_instrumentation: true) + query = Adapters::Base::Query.new(cypher, {}, cypher) + adapter.send(:query_set, self, [query], skip_instrumentation: true) end end end diff --git a/lib/neo4j/core/cypher_session/transactions/embedded.rb b/lib/neo4j/core/cypher_session/transactions/embedded.rb index 05e6ad3d..02549e3c 100644 --- a/lib/neo4j/core/cypher_session/transactions/embedded.rb +++ b/lib/neo4j/core/cypher_session/transactions/embedded.rb @@ -7,7 +7,7 @@ module Transactions class Embedded < Base def initialize(*args) super - @java_tx = adaptor.graph_db.begin_tx + @java_tx = adapter.graph_db.begin_tx end def commit diff --git a/lib/neo4j/core/cypher_session/transactions/http.rb b/lib/neo4j/core/cypher_session/transactions/http.rb index 9d79b37c..b84c2034 100644 --- a/lib/neo4j/core/cypher_session/transactions/http.rb +++ b/lib/neo4j/core/cypher_session/transactions/http.rb @@ -5,15 +5,15 @@ module Core class CypherSession module Transactions class HTTP < Base - # Should perhaps have transaction adaptors only define #close + # Should perhaps have transaction adapters only define #close # commit/delete are, I think, an implementation detail def commit - adaptor.requestor.request(:post, query_path(true)) if started? + adapter.requestor.request(:post, query_path(true)) if started? end def delete - adaptor.requestor.request(:delete, query_path) if started? + adapter.requestor.request(:delete, query_path) if started? end def query_path(commit = false) @@ -43,7 +43,7 @@ def id private def connection - adaptor.connection + adapter.connection end end end diff --git a/spec/neo4j/core/cypher_session/adaptors/bolt/pack_stream_spec.rb b/spec/neo4j/core/cypher_session/adapters/bolt/pack_stream_spec.rb similarity index 99% rename from spec/neo4j/core/cypher_session/adaptors/bolt/pack_stream_spec.rb rename to spec/neo4j/core/cypher_session/adapters/bolt/pack_stream_spec.rb index 5aac5b19..ccc907d2 100644 --- a/spec/neo4j/core/cypher_session/adaptors/bolt/pack_stream_spec.rb +++ b/spec/neo4j/core/cypher_session/adapters/bolt/pack_stream_spec.rb @@ -1,6 +1,6 @@ # encoding: UTF-8 -require './lib/neo4j/core/cypher_session/adaptors/bolt/pack_stream' +require './lib/neo4j/core/cypher_session/adapters/bolt/pack_stream' module Neo4j # rubocop:disable Metrics/ModuleLength diff --git a/spec/neo4j/core/cypher_session/adaptors/bolt_spec.rb b/spec/neo4j/core/cypher_session/adapters/bolt_spec.rb similarity index 67% rename from spec/neo4j/core/cypher_session/adaptors/bolt_spec.rb rename to spec/neo4j/core/cypher_session/adapters/bolt_spec.rb index 3a17a205..0d07807d 100644 --- a/spec/neo4j/core/cypher_session/adaptors/bolt_spec.rb +++ b/spec/neo4j/core/cypher_session/adapters/bolt_spec.rb @@ -1,19 +1,19 @@ require 'spec_helper' -require 'neo4j/core/cypher_session/adaptors/bolt' -require './spec/neo4j/core/shared_examples/adaptor' +require 'neo4j/core/cypher_session/adapters/bolt' +require './spec/neo4j/core/shared_examples/adapter' -describe Neo4j::Core::CypherSession::Adaptors::Bolt, bolt: true do - let(:adaptor_class) { Neo4j::Core::CypherSession::Adaptors::Bolt } +describe Neo4j::Core::CypherSession::Adapters::Bolt, bolt: true do + let(:adapter_class) { Neo4j::Core::CypherSession::Adapters::Bolt } let(:url) { ENV['NEO4J_BOLT_URL'] } - # let(:adaptor) { adaptor_class.new(url, logger_level: Logger::DEBUG) } - let(:adaptor) { adaptor_class.new(url) } + # let(:adapter) { adapter_class.new(url, logger_level: Logger::DEBUG) } + let(:adapter) { adapter_class.new(url) } - subject { adaptor } + subject { adapter } describe '#initialize' do before do - allow_any_instance_of(adaptor_class).to receive(:open_socket) + allow_any_instance_of(adapter_class).to receive(:open_socket) end let_context(url: 'url') { subject_should_raise ArgumentError, /Invalid URL/ } @@ -32,9 +32,9 @@ let_context(url: 'bolt://foo:bar@localhost:7687') { subject_should_not_raise } end - context 'connected adaptor' do - before { adaptor.connect } + context 'connected adapter' do + before { adapter.connect } - it_behaves_like 'Neo4j::Core::CypherSession::Adaptor' + it_behaves_like 'Neo4j::Core::CypherSession::Adapter' end end diff --git a/spec/neo4j/core/cypher_session/adapters/embedded_spec.rb b/spec/neo4j/core/cypher_session/adapters/embedded_spec.rb new file mode 100644 index 00000000..72c16d3c --- /dev/null +++ b/spec/neo4j/core/cypher_session/adapters/embedded_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' +require 'neo4j/core/cypher_session/adapters/embedded' +require './spec/neo4j/core/shared_examples/adapter' +require 'tmpdir' + +describe Neo4j::Core::CypherSession::Adapters::Embedded do + let(:adapter_class) { Neo4j::Core::CypherSession::Adapters::Embedded } + + if Neo4j::Core::Config.using_new_session? + if RUBY_PLATFORM == 'java' + describe '#initialize' do + it 'validates path' do + expect { adapter_class.new('./spec/fixtures/notadirectory') }.to raise_error ArgumentError, /Invalid path:/ + expect { adapter_class.new('./spec/fixtures/adirectory') }.not_to raise_error + end + end + + before(:all) do + path = Dir.mktmpdir('neo4jrb_embedded_adapter_spec') + @adapter = Neo4j::Core::CypherSession::Adapters::Embedded.new(path) + @adapter.connect + end + + let(:adapter) { @adapter } + + it_behaves_like 'Neo4j::Core::CypherSession::Adapter' + else + it 'should raise an error' do + expect { adapter_class.new('/') }.to raise_error 'JRuby is required for embedded mode' + end + end + end +end diff --git a/spec/neo4j/core/cypher_session/adaptors/has_uri_spec.rb b/spec/neo4j/core/cypher_session/adapters/has_uri_spec.rb similarity index 87% rename from spec/neo4j/core/cypher_session/adaptors/has_uri_spec.rb rename to spec/neo4j/core/cypher_session/adapters/has_uri_spec.rb index d3fe5969..8ce14b50 100644 --- a/spec/neo4j/core/cypher_session/adaptors/has_uri_spec.rb +++ b/spec/neo4j/core/cypher_session/adapters/has_uri_spec.rb @@ -1,14 +1,14 @@ require 'spec_helper' -require 'neo4j/core/cypher_session/adaptors/has_uri' +require 'neo4j/core/cypher_session/adapters/has_uri' -describe Neo4j::Core::CypherSession::Adaptors::HasUri do +describe Neo4j::Core::CypherSession::Adapters::HasUri do let(:uri_validation) {} let(:default_url) {} - let!(:adaptor) do + let!(:adapter) do scoped_default_url = default_url scoped_uri_validation = uri_validation Class.new do - include Neo4j::Core::CypherSession::Adaptors::HasUri + include Neo4j::Core::CypherSession::Adapters::HasUri default_url(scoped_default_url) if scoped_default_url validate_uri(&scoped_uri_validation) @@ -18,7 +18,7 @@ def initialize(url) end end - subject { adaptor.new(url) } + subject { adapter.new(url) } let_context default_url: 'foo://bar:baz@biz:1234' do let_context url: nil do diff --git a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb b/spec/neo4j/core/cypher_session/adapters/http_spec.rb similarity index 63% rename from spec/neo4j/core/cypher_session/adaptors/http_spec.rb rename to spec/neo4j/core/cypher_session/adapters/http_spec.rb index f3d61a03..d2d01e13 100644 --- a/spec/neo4j/core/cypher_session/adaptors/http_spec.rb +++ b/spec/neo4j/core/cypher_session/adapters/http_spec.rb @@ -1,34 +1,34 @@ require 'spec_helper' -require 'neo4j/core/cypher_session/adaptors/http' -require './spec/neo4j/core/shared_examples/adaptor' +require 'neo4j/core/cypher_session/adapters/http' +require './spec/neo4j/core/shared_examples/adapter' -describe Neo4j::Core::CypherSession::Adaptors::HTTP do +describe Neo4j::Core::CypherSession::Adapters::HTTP do before(:all) { setup_http_request_subscription } - let(:adaptor_class) { Neo4j::Core::CypherSession::Adaptors::HTTP } + let(:adapter_class) { Neo4j::Core::CypherSession::Adapters::HTTP } let(:url) { ENV['NEO4J_URL'] } - let(:adaptor) { adaptor_class.new(url) } - subject { adaptor } + let(:adapter) { adapter_class.new(url) } + subject { adapter } describe '#initialize' do it 'validates URLs' do - expect { adaptor_class.new('url').connect }.to raise_error ArgumentError, /Invalid URL:/ - expect { adaptor_class.new('https://foo@localhost:7474').connect }.not_to raise_error + expect { adapter_class.new('url').connect }.to raise_error ArgumentError, /Invalid URL:/ + expect { adapter_class.new('https://foo@localhost:7474').connect }.not_to raise_error - expect { adaptor_class.new('http://localhost:7474').connect }.not_to raise_error - expect { adaptor_class.new('https://localhost:7474').connect }.not_to raise_error - expect { adaptor_class.new('https://localhost:7474/').connect }.not_to raise_error - expect { adaptor_class.new('https://foo:bar@localhost:7474').connect }.not_to raise_error - expect { adaptor_class.new('bolt://localhost:7474').connect }.to raise_error ArgumentError, /Invalid URL/ - expect { adaptor_class.new('foo://localhost:7474').connect }.to raise_error ArgumentError, /Invalid URL/ + expect { adapter_class.new('http://localhost:7474').connect }.not_to raise_error + expect { adapter_class.new('https://localhost:7474').connect }.not_to raise_error + expect { adapter_class.new('https://localhost:7474/').connect }.not_to raise_error + expect { adapter_class.new('https://foo:bar@localhost:7474').connect }.not_to raise_error + expect { adapter_class.new('bolt://localhost:7474').connect }.to raise_error ArgumentError, /Invalid URL/ + expect { adapter_class.new('foo://localhost:7474').connect }.to raise_error ArgumentError, /Invalid URL/ end end - let(:session_double) { double('session', adaptor: subject) } + let(:session_double) { double('session', adapter: subject) } before do - adaptor.connect - adaptor.query(session_double, 'MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n, r') + adapter.connect + adapter.query(session_double, 'MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n, r') end describe 'transactions' do @@ -74,5 +74,5 @@ end end - it_behaves_like 'Neo4j::Core::CypherSession::Adaptor' + it_behaves_like 'Neo4j::Core::CypherSession::Adapter' end diff --git a/spec/neo4j/core/cypher_session/adaptors/embedded_spec.rb b/spec/neo4j/core/cypher_session/adaptors/embedded_spec.rb deleted file mode 100644 index d9dc70a2..00000000 --- a/spec/neo4j/core/cypher_session/adaptors/embedded_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'spec_helper' -require 'neo4j/core/cypher_session/adaptors/embedded' -require './spec/neo4j/core/shared_examples/adaptor' -require 'tmpdir' - -describe Neo4j::Core::CypherSession::Adaptors::Embedded do - let(:adaptor_class) { Neo4j::Core::CypherSession::Adaptors::Embedded } - - if Neo4j::Core::Config.using_new_session? - if RUBY_PLATFORM == 'java' - describe '#initialize' do - it 'validates path' do - expect { adaptor_class.new('./spec/fixtures/notadirectory') }.to raise_error ArgumentError, /Invalid path:/ - expect { adaptor_class.new('./spec/fixtures/adirectory') }.not_to raise_error - end - end - - before(:all) do - path = Dir.mktmpdir('neo4jrb_embedded_adaptor_spec') - @adaptor = Neo4j::Core::CypherSession::Adaptors::Embedded.new(path) - @adaptor.connect - end - - let(:adaptor) { @adaptor } - - it_behaves_like 'Neo4j::Core::CypherSession::Adaptor' - else - it 'should raise an error' do - expect { adaptor_class.new('/') }.to raise_error 'JRuby is required for embedded mode' - end - end - end -end diff --git a/spec/neo4j/core/cypher_session/cypher_error_spec.rb b/spec/neo4j/core/cypher_session/cypher_error_spec.rb index 7ded7cdd..b8755f6e 100644 --- a/spec/neo4j/core/cypher_session/cypher_error_spec.rb +++ b/spec/neo4j/core/cypher_session/cypher_error_spec.rb @@ -1,5 +1,5 @@ require 'spec_helper' -require 'neo4j/core/cypher_session/adaptors' +require 'neo4j/core/cypher_session/adapters' module Neo4j module Core diff --git a/spec/neo4j/core/cypher_session_spec.rb b/spec/neo4j/core/cypher_session_spec.rb index 9f8dd73a..42daf050 100644 --- a/spec/neo4j/core/cypher_session_spec.rb +++ b/spec/neo4j/core/cypher_session_spec.rb @@ -3,16 +3,16 @@ describe Neo4j::Core::CypherSession do describe '#initialize' do - it 'fails with invalid adaptor' do + it 'fails with invalid adapter' do expect do Neo4j::Core::CypherSession.new(Object.new) - end.to raise_error ArgumentError, /^Invalid adaptor: / + end.to raise_error ArgumentError, /^Invalid adapter: / end - it 'takes an Adaptors::Base object' do + it 'takes an Adapters::Base object' do expect do - http_adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new(ENV['NEO4J_URL']) - Neo4j::Core::CypherSession.new(http_adaptor) + http_adapter = Neo4j::Core::CypherSession::Adapters::HTTP.new(ENV['NEO4J_URL']) + Neo4j::Core::CypherSession.new(http_adapter) end.not_to raise_error end end diff --git a/spec/neo4j/core/shared_examples/adaptor.rb b/spec/neo4j/core/shared_examples/adapter.rb similarity index 78% rename from spec/neo4j/core/shared_examples/adaptor.rb rename to spec/neo4j/core/shared_examples/adapter.rb index ddda1854..cafb2cc6 100644 --- a/spec/neo4j/core/shared_examples/adaptor.rb +++ b/spec/neo4j/core/shared_examples/adapter.rb @@ -1,37 +1,37 @@ -# Requires that an `adaptor` let variable exist with the connected adaptor -RSpec.shared_examples 'Neo4j::Core::CypherSession::Adaptor' do +# Requires that an `adapter` let variable exist with the connected adapter +RSpec.shared_examples 'Neo4j::Core::CypherSession::Adapter' do let(:real_session) do - expect(adaptor).to receive(:connect) - Neo4j::Core::CypherSession.new(adaptor) + expect(adapter).to receive(:connect) + Neo4j::Core::CypherSession.new(adapter) end - let(:session_double) { double('session', adaptor: adaptor) } + let(:session_double) { double('session', adapter: adapter) } # TODO: Test cypher errors - before { adaptor.query(session_double, 'MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n, r') } + before { adapter.query(session_double, 'MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n, r') } - subject { adaptor } + subject { adapter } describe '#query' do it 'Can make a query' do - adaptor.query(session_double, 'MERGE path=(n)-[rel:r]->(o) RETURN n, rel, o, path LIMIT 1') + adapter.query(session_double, 'MERGE path=(n)-[rel:r]->(o) RETURN n, rel, o, path LIMIT 1') end it 'can make a query with a large payload' do - adaptor.query(session_double, 'CREATE (n:Test) SET n = {props} RETURN n', props: {text: 'a' * 10_000}) + adapter.query(session_double, 'CREATE (n:Test) SET n = {props} RETURN n', props: {text: 'a' * 10_000}) end end describe '#queries' do it 'allows for multiple queries' do - result = adaptor.queries(session_double) do + result = adapter.queries(session_double) do append 'CREATE (n:Label1) RETURN n' append 'CREATE (n:Label2) RETURN n' end expect(result[0].to_a[0].n).to be_a(Neo4j::Core::Node) expect(result[1].to_a[0].n).to be_a(Neo4j::Core::Node) - # Maybe should have method like adaptor.returns_node_and_relationship_metadata? - if adaptor.is_a?(::Neo4j::Core::CypherSession::Adaptors::HTTP) && adaptor.version < '2.1.5' + # Maybe should have method like adapter.returns_node_and_relationship_metadata? + if adapter.is_a?(::Neo4j::Core::CypherSession::Adapters::HTTP) && adapter.version < '2.1.5' expect(result[0].to_a[0].n.labels).to eq(nil) expect(result[1].to_a[0].n.labels).to eq(nil) else @@ -41,12 +41,12 @@ end it 'allows for building with Query API' do - result = adaptor.queries(session_double) do + result = adapter.queries(session_double) do append query.create(n: {Label1: {}}).return(:n) end expect(result[0].to_a[0].n).to be_a(Neo4j::Core::Node) - if adaptor.is_a?(::Neo4j::Core::CypherSession::Adaptors::HTTP) && adaptor.version < '2.1.5' + if adapter.is_a?(::Neo4j::Core::CypherSession::Adapters::HTTP) && adapter.version < '2.1.5' expect(result[0].to_a[0].n.labels).to eq(nil) else expect(result[0].to_a[0].n.labels).to eq([:Label1]) @@ -59,102 +59,102 @@ def create_object_by_id(id, tx) tx.query('CREATE (t:Temporary {id: {id}})', id: id) end - def get_object_by_id(id, adaptor) - first = adaptor.query(session_double, 'MATCH (t:Temporary {id: {id}}) RETURN t', id: id).first + def get_object_by_id(id, adapter) + first = adapter.query(session_double, 'MATCH (t:Temporary {id: {id}}) RETURN t', id: id).first first && first.t end it 'logs one query per query_set in transaction' do expect_queries(1) do - tx = adaptor.transaction(session_double) + tx = adapter.transaction(session_double) create_object_by_id(1, tx) tx.close end - expect(get_object_by_id(1, adaptor)).to be_a(Neo4j::Core::Node) + expect(get_object_by_id(1, adapter)).to be_a(Neo4j::Core::Node) expect_queries(1) do - adaptor.transaction(session_double) do |tx| + adapter.transaction(session_double) do |tx| create_object_by_id(2, tx) end end - expect(get_object_by_id(2, adaptor)).to be_a(Neo4j::Core::Node) + expect(get_object_by_id(2, adapter)).to be_a(Neo4j::Core::Node) end it 'allows for rollback' do expect_queries(1) do - tx = adaptor.transaction(session_double) + tx = adapter.transaction(session_double) create_object_by_id(3, tx) tx.mark_failed tx.close end - expect(get_object_by_id(3, adaptor)).to be_nil + expect(get_object_by_id(3, adapter)).to be_nil expect_queries(1) do - adaptor.transaction(session_double) do |tx| + adapter.transaction(session_double) do |tx| create_object_by_id(4, tx) tx.mark_failed end end - expect(get_object_by_id(4, adaptor)).to be_nil + expect(get_object_by_id(4, adapter)).to be_nil expect_queries(1) do expect do - adaptor.transaction(session_double) do |tx| + adapter.transaction(session_double) do |tx| create_object_by_id(5, tx) fail 'Failing transaction with error' end end.to raise_error 'Failing transaction with error' end - expect(get_object_by_id(5, adaptor)).to be_nil + expect(get_object_by_id(5, adapter)).to be_nil # Nested transaction, error from inside inner transaction handled outside of inner transaction expect_queries(1) do - adaptor.transaction(session_double) do |_tx| + adapter.transaction(session_double) do |_tx| expect do - adaptor.transaction(session_double) do |tx| + adapter.transaction(session_double) do |tx| create_object_by_id(6, tx) fail 'Failing transaction with error' end end.to raise_error 'Failing transaction with error' end end - expect(get_object_by_id(6, adaptor)).to be_nil + expect(get_object_by_id(6, adapter)).to be_nil # Nested transaction, error from inside inner transaction handled outside of inner transaction expect_queries(2) do - adaptor.transaction(session_double) do |tx| + adapter.transaction(session_double) do |tx| create_object_by_id(7, tx) expect do - adaptor.transaction(session_double) do |tx| + adapter.transaction(session_double) do |tx| create_object_by_id(8, tx) fail 'Failing transaction with error' end end.to raise_error 'Failing transaction with error' end end - expect(get_object_by_id(7, adaptor)).to be_nil - expect(get_object_by_id(8, adaptor)).to be_nil + expect(get_object_by_id(7, adapter)).to be_nil + expect(get_object_by_id(8, adapter)).to be_nil # Nested transaction, error from inside inner transaction handled outside of outer transaction expect_queries(1) do expect do - adaptor.transaction(session_double) do |_tx| - adaptor.transaction(session_double) do |tx| + adapter.transaction(session_double) do |_tx| + adapter.transaction(session_double) do |tx| create_object_by_id(9, tx) fail 'Failing transaction with error' end end end.to raise_error 'Failing transaction with error' end - expect(get_object_by_id(9, adaptor)).to be_nil + expect(get_object_by_id(9, adapter)).to be_nil end # it 'does not allow transactions in the wrong order' do - # expect { adaptor.end_transaction }.to raise_error(RuntimeError, /Cannot close transaction without starting one/) + # expect { adapter.end_transaction }.to raise_error(RuntimeError, /Cannot close transaction without starting one/) end describe 'results' do it 'handles array results' do - result = adaptor.query(session_double, "CREATE (a {b: 'c'}) RETURN [a] AS arr") + result = adapter.query(session_double, "CREATE (a {b: 'c'}) RETURN [a] AS arr") expect(result.hashes).to be_a(Array) expect(result.hashes.size).to be(1) @@ -164,7 +164,7 @@ def get_object_by_id(id, adaptor) end it 'handles map results' do - result = adaptor.query(session_double, "CREATE (a {b: 'c'}) RETURN {foo: a} AS map") + result = adapter.query(session_double, "CREATE (a {b: 'c'}) RETURN {foo: a} AS map") expect(result.hashes).to be_a(Array) expect(result.hashes.size).to be(1) @@ -174,7 +174,7 @@ def get_object_by_id(id, adaptor) end it 'handles map results with arrays' do - result = adaptor.query(session_double, "CREATE (a {b: 'c'}) RETURN {foo: [a]} AS map") + result = adapter.query(session_double, "CREATE (a {b: 'c'}) RETURN {foo: [a]} AS map") expect(result.hashes).to be_a(Array) expect(result.hashes.size).to be(1) @@ -185,7 +185,7 @@ def get_object_by_id(id, adaptor) end it 'symbolizes keys for Neo4j objects' do - result = adaptor.query(session_double, 'RETURN {a: 1} AS obj') + result = adapter.query(session_double, 'RETURN {a: 1} AS obj') expect(result.hashes).to eq([{obj: {a: 1}}]) @@ -228,7 +228,7 @@ def initialize(obj) # Default wrap_level should be :core_entity let(:wrap_level) { nil } - subject { adaptor.query(session_double, query, {}, wrap_level: wrap_level).to_a[0].result } + subject { adapter.query(session_double, query, {}, wrap_level: wrap_level).to_a[0].result } let_context return_clause: 'n' do it { should be_a(Neo4j::Core::Node) } @@ -301,9 +301,9 @@ def initialize(obj) describe 'unique constraint error' do it 'raises an error?' do - adaptor.query(real_session, "CREATE (:Album {uuid: 'dup'})").to_a + adapter.query(real_session, "CREATE (:Album {uuid: 'dup'})").to_a expect do - adaptor.query(real_session, "CREATE (:Album {uuid: 'dup'})").to_a + adapter.query(real_session, "CREATE (:Album {uuid: 'dup'})").to_a end.to raise_error(::Neo4j::Core::CypherSession::SchemaErrors::ConstraintValidationFailedError) end end @@ -323,7 +323,7 @@ def initialize(obj) describe 'constraints' do let(:label) {} - subject { adaptor.constraints(real_session) } + subject { adapter.constraints(real_session) } it do should match_array([ @@ -336,7 +336,7 @@ def initialize(obj) describe 'indexes' do let(:label) {} - subject { adaptor.indexes(real_session) } + subject { adapter.indexes(real_session) } it do should match_array([ diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b89cad03..095de225 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -47,16 +47,16 @@ def [](key) require 'neo4j/core/cypher_session' -require 'neo4j/core/cypher_session/adaptors/http' -require 'neo4j/core/cypher_session/adaptors/bolt' -require 'neo4j/core/cypher_session/adaptors/embedded' +require 'neo4j/core/cypher_session/adapters/http' +require 'neo4j/core/cypher_session/adapters/bolt' +require 'neo4j/core/cypher_session/adapters/embedded' module Neo4jSpecHelpers def log_queries! Neo4j::Server::CypherSession.log_with(&method(:puts)) - Neo4j::Core::CypherSession::Adaptors::Base.subscribe_to_query(&method(:puts)) - Neo4j::Core::CypherSession::Adaptors::HTTP.subscribe_to_request(&method(:puts)) - Neo4j::Core::CypherSession::Adaptors::Bolt.subscribe_to_request(&method(:puts)) - Neo4j::Core::CypherSession::Adaptors::Embedded.subscribe_to_transaction(&method(:puts)) + Neo4j::Core::CypherSession::Adapters::Base.subscribe_to_query(&method(:puts)) + Neo4j::Core::CypherSession::Adapters::HTTP.subscribe_to_request(&method(:puts)) + Neo4j::Core::CypherSession::Adapters::Bolt.subscribe_to_request(&method(:puts)) + Neo4j::Core::CypherSession::Adapters::Embedded.subscribe_to_transaction(&method(:puts)) end def current_transaction @@ -83,7 +83,7 @@ def expect_http_requests(count) def setup_http_request_subscription $expect_http_request_count = 0 - Neo4j::Core::CypherSession::Adaptors::HTTP.subscribe_to_request do |_message| + Neo4j::Core::CypherSession::Adapters::HTTP.subscribe_to_request do |_message| $expect_http_request_count += 1 end end @@ -155,7 +155,7 @@ def subject_should_not_raise(*args) # for expect_queries method Neo4jSpecHelpers.expect_queries_count = 0 - Neo4j::Core::CypherSession::Adaptors::Base.subscribe_to_query do |_message| + Neo4j::Core::CypherSession::Adapters::Base.subscribe_to_query do |_message| Neo4jSpecHelpers.expect_queries_count += 1 end end