From cc73e0a8096173b9a0bc079634418fed93673d1b Mon Sep 17 00:00:00 2001 From: Brian Underwood Date: Mon, 11 Jul 2016 22:40:44 +0200 Subject: [PATCH 01/14] Fix issue with label / model mappings getting stuck before all models have a chance to load. Also don't clear WRAPPED_CLASSES (I think this will fix the CypherNode issue we've been seeing in development --- lib/neo4j/active_node.rb | 2 ++ lib/neo4j/active_node/labels.rb | 7 +------ lib/neo4j/active_node/labels/reloading.rb | 1 - spec/spec_helper.rb | 1 + 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/neo4j/active_node.rb b/lib/neo4j/active_node.rb index ec2116797..4fad50072 100644 --- a/lib/neo4j/active_node.rb +++ b/lib/neo4j/active_node.rb @@ -68,6 +68,8 @@ def nodeify(object) include Neo4j::Timestamps if Neo4j::Config[:record_timestamps] def self.inherited(other) + Neo4j::ActiveNode::Labels.clear_wrapped_models + inherit_id_property(other) attributes.each_pair do |k, v| other.inherit_property k.to_sym, v.clone, declared_properties[k].options diff --git a/lib/neo4j/active_node/labels.rb b/lib/neo4j/active_node/labels.rb index bf1e7d356..77e4fe060 100644 --- a/lib/neo4j/active_node/labels.rb +++ b/lib/neo4j/active_node/labels.rb @@ -11,11 +11,7 @@ module Labels MODELS_FOR_LABELS_CACHE.clear included do |model| - def self.inherited(model) - add_wrapped_class(model) - - super - end + Neo4j::ActiveNode::Labels.clear_wrapped_models Neo4j::ActiveNode::Labels.add_wrapped_class(model) unless Neo4j::ActiveNode::Labels._wrapped_classes.include?(model) end @@ -69,7 +65,6 @@ def self.model_for_labels(labels) end def self.clear_wrapped_models - WRAPPED_CLASSES.clear MODELS_FOR_LABELS_CACHE.clear Neo4j::Node::Wrapper::CONSTANTS_FOR_LABELS_CACHE.clear end diff --git a/lib/neo4j/active_node/labels/reloading.rb b/lib/neo4j/active_node/labels/reloading.rb index 67cbefdf1..92c53aa9a 100644 --- a/lib/neo4j/active_node/labels/reloading.rb +++ b/lib/neo4j/active_node/labels/reloading.rb @@ -14,7 +14,6 @@ def before_remove_const associations.each_value(&:queue_model_refresh!) MODELS_FOR_LABELS_CACHE.clear WRAPPED_CLASSES.each { |c| MODELS_TO_RELOAD << c.name } - WRAPPED_CLASSES.clear end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b961946cf..f88354a9d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -149,6 +149,7 @@ def expect_queries(count) Dir["#{File.dirname(__FILE__)}/shared_examples/**/*.rb"].each { |f| require f } def clear_model_memory_caches + Neo4j::ActiveNode::Labels::WRAPPED_CLASSES.clear Neo4j::ActiveNode::Labels.clear_wrapped_models end From 186c1ce03274c1dbab09f585ae3da3c3759960c0 Mon Sep 17 00:00:00 2001 From: Brian Underwood Date: Wed, 13 Jul 2016 22:12:27 +0200 Subject: [PATCH 02/14] Put this back, because of course it broke things --- lib/neo4j/active_node/labels/reloading.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/neo4j/active_node/labels/reloading.rb b/lib/neo4j/active_node/labels/reloading.rb index 92c53aa9a..67cbefdf1 100644 --- a/lib/neo4j/active_node/labels/reloading.rb +++ b/lib/neo4j/active_node/labels/reloading.rb @@ -14,6 +14,7 @@ def before_remove_const associations.each_value(&:queue_model_refresh!) MODELS_FOR_LABELS_CACHE.clear WRAPPED_CLASSES.each { |c| MODELS_TO_RELOAD << c.name } + WRAPPED_CLASSES.clear end end end From d8727fd033d3843ce5a206639a56a6c1bdaeb815 Mon Sep 17 00:00:00 2001 From: Brian Underwood Date: Mon, 1 Aug 2016 15:32:37 +0200 Subject: [PATCH 03/14] Up to 7.1.2 to include fix from model_label_map_fix --- CHANGELOG.md | 6 ++++++ lib/neo4j/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5c27d643..5f3e02f4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. This file should follow the standards specified on [http://keepachangelog.com/] This project adheres to [Semantic Versioning](http://semver.org/). +## [7.1.2] - 08-01-2016 + +### Fixed + +- Fixed issue where the label wrapping cache would get stuck + ## [7.1.1] - 07-22-2016 ### Fixed diff --git a/lib/neo4j/version.rb b/lib/neo4j/version.rb index 9533bed65..03b5f0ccc 100644 --- a/lib/neo4j/version.rb +++ b/lib/neo4j/version.rb @@ -1,3 +1,3 @@ module Neo4j - VERSION = '7.1.1' + VERSION = '7.1.2' end From c64c2d572ea65ae63fafe6093123742195876f3f Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 12 Aug 2016 10:10:17 -0400 Subject: [PATCH 04/14] Update ActiveRel.rst Neo4j::Session::CypherError: Parentheses are required to identify nodes in patterns, i.e. (s) (line 1, column 12 (offset: 11)) "MATCH (s), s-[rel1:`exchange`]->n2 WHERE (ID(s) = {ID_s}) RETURN rel1" --- docs/ActiveRel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ActiveRel.rst b/docs/ActiveRel.rst index 6142b9851..46f6cc0b3 100644 --- a/docs/ActiveRel.rst +++ b/docs/ActiveRel.rst @@ -118,7 +118,7 @@ Any of these methods can return relationship objects. Student.first.lessons.each_rel { |r| } Student.first.lessons.each_with_rel { |node, rel| } - Student.first.query_as(:s).match('s-[rel1:\`enrolled_in\`]->n2').pluck(:rel1) + Student.first.query_as(:s).match('(s)-[rel1:\`enrolled_in\`]->(n2)').pluck(:rel1) These are available as both class or instance methods. Because both each_rel and each_with_rel return enumerables when a block is skipped, you can take advantage of the full suite of enumerable methods: From 63f2c92175eda2ff86567b07984a866bdcdb0a89 Mon Sep 17 00:00:00 2001 From: Brian Underwood Date: Mon, 15 Aug 2016 22:21:19 +0200 Subject: [PATCH 05/14] Add information about which exceptions are replacing old exceptions --- docs/UpgradeGuide.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/UpgradeGuide.rst b/docs/UpgradeGuide.rst index e0f69c65f..772347144 100644 --- a/docs/UpgradeGuide.rst +++ b/docs/UpgradeGuide.rst @@ -131,3 +131,17 @@ In version 8.0 of the ``neo4j`` gem support was added to allow for definining th .. warning:: Use of ``neo_id`` as a perminent identifier should be done with caution. Neo4j can recycle IDs from deleted nodes meaning that URLs or other external references using that ID will reference the wrong item. Neo4j may be updated in the future to support internal IDs which aren't recycled, but for now use at your own risk + +Exceptions +^^^^^^^^^^ + +With the new API comes some new exceptions which are raised. With the new adaptor API errors are more dependable across different ways of connecting to Neo4j. + +======================================================= ========================================================================= +Old Exception New Exception +------------------------------------------------------- ------------------------------------------------------------------------- +Neo4j::Server::Resource::ServerException Neo4j::Core::CypherSession::ConnectionFailedError +Neo4j::Server::CypherResponse::ConstraintViolationError Neo4j::Core::CypherSession::SchemaErrors::ConstraintValidationFailedError +Neo4j::Session::CypherError Neo4j::Core::CypherSession::CypherError +======================================================= ========================================================================= + From 13ab52a842174ee8674c9938cf276c22f5704559 Mon Sep 17 00:00:00 2001 From: ProGM Date: Tue, 16 Aug 2016 01:40:17 +0200 Subject: [PATCH 06/14] Accepting `nil` as enum value --- Gemfile | 8 ++++---- lib/neo4j/shared/enum.rb | 8 ++++---- lib/neo4j/shared/type_converters.rb | 3 ++- neo4j.gemspec | 2 +- spec/e2e/enum_spec.rb | 23 +++++++++++++++++++++-- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 4c637a80c..ef486ed10 100644 --- a/Gemfile +++ b/Gemfile @@ -2,10 +2,10 @@ source 'http://rubygems.org' gemspec -if ENV['CI'] - gem 'neo4j-core', github: 'neo4jrb/neo4j-core', branch: 'master' - gem 'neo4j-rake_tasks', github: 'neo4jrb/neo4j-rake_tasks', branch: 'master' -end +# if ENV['CI'] +# gem 'neo4j-core', github: 'neo4jrb/neo4j-core', branch: 'master' +# gem 'neo4j-rake_tasks', github: 'neo4jrb/neo4j-rake_tasks', branch: 'master' +# end # gem 'active_attr', github: 'neo4jrb/active_attr', branch: 'performance' # gem 'active_attr', path: '../active_attr' diff --git a/lib/neo4j/shared/enum.rb b/lib/neo4j/shared/enum.rb index b0ab43781..39bb38165 100644 --- a/lib/neo4j/shared/enum.rb +++ b/lib/neo4j/shared/enum.rb @@ -67,7 +67,7 @@ def normalize_key_list(enum_keys) end end - VALID_OPTIONS_FOR_ENUMS = [:_index, :_prefix, :_suffix] + VALID_OPTIONS_FOR_ENUMS = [:_index, :_prefix, :_suffix, :_default] DEFAULT_OPTIONS_FOR_ENUMS = { _index: true } @@ -88,12 +88,12 @@ def split_options_and_parameters(parameters) def define_property(property_name, enum_keys, options) property_options = build_property_options(enum_keys, options) property property_name, property_options - serialize property_name, Neo4j::Shared::TypeConverters::EnumConverter.new(enum_keys) + serialize property_name, Neo4j::Shared::TypeConverters::EnumConverter.new(enum_keys, property_options) end - def build_property_options(enum_keys, _options = {}) + def build_property_options(_enum_keys, options = {}) { - default: enum_keys.keys.first + default: options[:_default] } end diff --git a/lib/neo4j/shared/type_converters.rb b/lib/neo4j/shared/type_converters.rb index e64ff0a8d..d4d9aec33 100644 --- a/lib/neo4j/shared/type_converters.rb +++ b/lib/neo4j/shared/type_converters.rb @@ -264,8 +264,9 @@ def to_ruby(value) end class EnumConverter - def initialize(enum_keys) + def initialize(enum_keys, options) @enum_keys = enum_keys + @options = options end def converted?(value) diff --git a/neo4j.gemspec b/neo4j.gemspec index 0ae7fc5bf..6a4a81c07 100644 --- a/neo4j.gemspec +++ b/neo4j.gemspec @@ -29,7 +29,7 @@ A Neo4j OGM (Object-Graph-Mapper) for use in Ruby on Rails and Rack frameworks h s.add_dependency('orm_adapter', '~> 0.5.0') s.add_dependency('activemodel', '~> 4') s.add_dependency('activesupport', '~> 4') - s.add_dependency('neo4j-core', '>= 6.0.0') + s.add_dependency('neo4j-core', '< 7.0.0') s.add_dependency('neo4j-community', '~> 2.0') if RUBY_PLATFORM =~ /java/ s.add_development_dependency('railties', '~> 4') s.add_development_dependency('pry') diff --git a/spec/e2e/enum_spec.rb b/spec/e2e/enum_spec.rb index 831f4461c..5b949e2d2 100644 --- a/spec/e2e/enum_spec.rb +++ b/spec/e2e/enum_spec.rb @@ -1,7 +1,7 @@ describe Neo4j::ActiveNode do before(:each) do stub_active_node_class('StoredFile') do - enum type: [:unknown, :image, :video] + enum type: [:unknown, :image, :video], _default: :unknown enum size: {big: 100, medium: 7, small: 2}, _prefix: :dimension enum flag: [:clean, :dangerous], _suffix: true @@ -31,7 +31,12 @@ end describe 'getters and setters' do - it 'returns a type as symbol' do + it 'returns nil by default' do + file = StoredFile.new + expect(file.flag).to be_nil + end + + it 'returns the default value' do file = StoredFile.new expect(file.type).to eq(:unknown) end @@ -49,6 +54,14 @@ expect(StoredFile.as(:f).pluck('f.type')).to eq([2]) expect(file.reload.type).to eq(:video) end + + it 'accepts nil as value' do + file = StoredFile.new + file.flag = nil + file.save! + expect(StoredFile.as(:f).where(id: file.id).pluck('f.flag')).to eq([nil]) + expect(file.reload.flag).to eq(nil) + end end describe 'scopes' do @@ -93,6 +106,12 @@ end describe '? methods' do + it 'returns false when accessing to a nil value' do + file = StoredFile.new + expect(file).not_to be_clean_flag + expect(file).not_to be_dangerous_flag + end + it 'returns true when the enum is in the current state' do file = StoredFile.new file.type = :video From 3d6a982fb1cb770ef87d8805a3334fe7bbc03142 Mon Sep 17 00:00:00 2001 From: ProGM Date: Tue, 16 Aug 2016 10:54:45 +0200 Subject: [PATCH 07/14] Fix Gemfile for jruby. --- Gemfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index ef486ed10..373d12223 100644 --- a/Gemfile +++ b/Gemfile @@ -14,13 +14,18 @@ gem 'listen', '< 3.1' group 'test' do gem 'coveralls', require: false + if RUBY_VERSION.to_f < 2.0 + gem 'tins', '< 1.7' + gem 'overcommit', '< 0.35.0' + else + gem 'overcommit' + end gem 'codecov', require: false gem 'simplecov', require: false gem 'simplecov-html', require: false gem 'rspec', '~> 3.4' gem 'its' gem 'test-unit' - gem 'overcommit' gem 'colored' gem 'dotenv' gem 'timecop' From e4e56f7921b8bb198327382a617dd5c65cb366e6 Mon Sep 17 00:00:00 2001 From: ProGM Date: Tue, 16 Aug 2016 22:38:38 +0200 Subject: [PATCH 08/14] Fix gemspec. --- neo4j.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo4j.gemspec b/neo4j.gemspec index 6a4a81c07..c4fdda0eb 100644 --- a/neo4j.gemspec +++ b/neo4j.gemspec @@ -29,7 +29,7 @@ A Neo4j OGM (Object-Graph-Mapper) for use in Ruby on Rails and Rack frameworks h s.add_dependency('orm_adapter', '~> 0.5.0') s.add_dependency('activemodel', '~> 4') s.add_dependency('activesupport', '~> 4') - s.add_dependency('neo4j-core', '< 7.0.0') + s.add_dependency('neo4j-core', '>= 6.0.0', '< 7.0.0') s.add_dependency('neo4j-community', '~> 2.0') if RUBY_PLATFORM =~ /java/ s.add_development_dependency('railties', '~> 4') s.add_development_dependency('pry') From 818ba3b1b1d14a23a535cce6cd5381e65abd26da Mon Sep 17 00:00:00 2001 From: ProGM Date: Thu, 18 Aug 2016 14:57:40 +0200 Subject: [PATCH 09/14] Trying to fix ruby 2.0 build. --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 373d12223..2e3924c2b 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,7 @@ group 'test' do gem 'overcommit', '< 0.35.0' else gem 'overcommit' + gem 'activesupport', '>= 4.2' end gem 'codecov', require: false gem 'simplecov', require: false From 3fb890a620766930004719066f9eac4a244dfba8 Mon Sep 17 00:00:00 2001 From: Brian Underwood Date: Thu, 18 Aug 2016 16:22:05 +0200 Subject: [PATCH 10/14] Release .15 patch with #1270 change --- CHANGELOG.md | 6 ++++++ lib/neo4j/version.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35e9a1856..102d9725b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. This file should follow the standards specified on [http://keepachangelog.com/] This project adheres to [Semantic Versioning](http://semver.org/). +## [7.0.15] - 08-18-2016 + +### Changed + +- Default value for `enum` is `nil` instead of the first value. This is a **BREAKING** change but is being released as a patch because the original behavior was considered a bug. See [this pull request](https://github.com/neo4jrb/neo4j/pull/1270) (thanks to ProGM and andyweiss1982) + ## [7.0.14] - 07-10-2016 ### Fixed diff --git a/lib/neo4j/version.rb b/lib/neo4j/version.rb index 00f07f24e..512e20cf7 100644 --- a/lib/neo4j/version.rb +++ b/lib/neo4j/version.rb @@ -1,3 +1,3 @@ module Neo4j - VERSION = '7.0.14' + VERSION = '7.0.15' end From 3001b0509cce0456650922003ba103df82f0b9f5 Mon Sep 17 00:00:00 2001 From: Brian Underwood Date: Fri, 19 Aug 2016 16:01:26 +0200 Subject: [PATCH 11/14] Use ActiveSupport::Logger instead of base Logger --- lib/neo4j/active_base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/neo4j/active_base.rb b/lib/neo4j/active_base.rb index 933cedfc6..eb312ae0c 100644 --- a/lib/neo4j/active_base.rb +++ b/lib/neo4j/active_base.rb @@ -61,7 +61,7 @@ def label_object(label_name) end def logger - @logger ||= (Neo4j::Config[:logger] || Logger.new(STDOUT)) + @logger ||= (Neo4j::Config[:logger] || ActiveSupport::Logger.new(STDOUT)) end end end From fcec588ad8e0464c8ccd87d3df932c413dfd2fae Mon Sep 17 00:00:00 2001 From: Brian Underwood Date: Fri, 19 Aug 2016 16:09:04 +0200 Subject: [PATCH 12/14] Destroy should return object like in ActiveRecord --- lib/neo4j/shared/persistence.rb | 2 ++ spec/shared_examples/destroyable_model.rb | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/neo4j/shared/persistence.rb b/lib/neo4j/shared/persistence.rb index b2caa066f..ac16e7437 100644 --- a/lib/neo4j/shared/persistence.rb +++ b/lib/neo4j/shared/persistence.rb @@ -123,6 +123,8 @@ def destroy destroy_query.exec if _persisted_obj @_deleted = true + + self end def exist? diff --git a/spec/shared_examples/destroyable_model.rb b/spec/shared_examples/destroyable_model.rb index 91b2b7950..9b2c918c3 100644 --- a/spec/shared_examples/destroyable_model.rb +++ b/spec/shared_examples/destroyable_model.rb @@ -4,12 +4,16 @@ subject.save! @other = subject.class.find_by_id(subject.id) @old_id = subject.id - subject.destroy + @result = subject.destroy end it { is_expected.to be_frozen } it 'should remove the model from the database' do expect(subject.class.find_by_id(@old_id)).to be_nil end + + it 'returns the model object' do + expect(@result).to eq(subject) + end end end From c73bb179a77dcf0c94c63f033c91664cf0707a8d Mon Sep 17 00:00:00 2001 From: Brian Underwood Date: Fri, 19 Aug 2016 16:03:51 +0000 Subject: [PATCH 13/14] Improvements based on #1264 --- docs/UpgradeGuide.rst | 56 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/docs/UpgradeGuide.rst b/docs/UpgradeGuide.rst index 772347144..0edaf3c12 100644 --- a/docs/UpgradeGuide.rst +++ b/docs/UpgradeGuide.rst @@ -101,7 +101,61 @@ If you are using version ``8.0`` of the ``neo4j`` gem, that will be accessible, server_db ^^^^^^^^^ -In previous version of the ``neo4j`` gem to connect to Neo4j via HTTP you would define the value ``server_db`` in the ``neo4j.yml`` file, the ``NEO4J_TYPE`` environment variable, or a Rails configuration (``config.neo4j.session_type``). This should now be replaced and either ``bolt`` or ``http`` should be used. +In previous version of the ``neo4j`` gem to connect to Neo4j via HTTP you would define the value ``server_db`` in the ``neo4j.yml`` file, the ``NEO4J_TYPE`` environment variable, or a Rails configuration (``config.neo4j.session_type``). This should now be replaced and either ``bolt`` or ``http`` should be used depending on which connection type you need. + +Some examples: + +.. code-block:: yaml + + # config/neo4j.yml + # Before + development: + type: server_db + url: http://localhost:7474 + + # After + development: + type: http # or bolt + url: http://localhost:7474 + +.. code-block:: ruby + + # Rails config/application.rb, config/environments/development.rb, etc... + + # Before + config.neo4j.session_type = :server_db + config.neo4j.session_url = 'http://localhost:7474' + + # AFter + config.neo4j.session_type = :http # or :bolt + config.neo4j.session_url = 'http://localhost:7474' + +Outside of Rails +^^^^^^^^^^^^^^^^ + +The ``neo4j`` gem will automatically set up a number of things with it's ``railtie``. If you aren't using Rails you may need to set some things up yourself and some of the details have changed with version 8.0 of the ``neo4j`` gem. + +Previously a connection with be established with ``Neo4j::Session.open`` and the default session from ``neo4j-core`` would be used. In version 7.0 of the ``neo4j-core`` gem, no such default session exists for the new API so you will need to establish a session to use the ``ActiveNode`` and ``ActiveRel`` modules like so: + +.. code-block:: ruby + + adaptor = Neo4j::Core::CypherSession::Adaptors::HTTP.new('http://username:password@localhost:7474') + + session = Neo4j::Core::CypherSession.new(adaptor) + + Neo4j::ActiveBase.current_session = session + + # Or skip setting up the session yourself: + + Neo4j::ActiveBase.current_adaptor = adaptor + +Migrations: + +If you would like to use the migrations provided by the ``neo4j`` outside of Rails you can include this in your ``Rakefile``: + +.. code-block:: ruby + load 'neo4j/tasks/migration.rake' + Indexes and Constraints ^^^^^^^^^^^^^^^^^^^^^^^ From 9d5d93ea44cf908e5b23e1f25cbd5216e18e03af Mon Sep 17 00:00:00 2001 From: Brian Underwood Date: Sun, 21 Aug 2016 05:37:16 -0500 Subject: [PATCH 14/14] CHANGELOG entry for #1254 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dae84eaba..c1465ca57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. This file should follow the standards specified on [http://keepachangelog.com/] This project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Changed + +- `ActiveNode#destroy` and `ActiveRel#destroy` now return the object in question rather than `true` to be compatible with `ActiveRecord` (see #1254) + ## [8.0.0.alpha.2] 2016-08-05 ### Changed