Skip to content

Commit

Permalink
Merge branch 'master' into unpersisted-nodes-and-validations
Browse files Browse the repository at this point in the history
* master:
  Version bump.
  Version bump
  Changelog and version bump.
  merge changelog from 7.2.x
  ActiveRel factories will build CREATE String
  release 7.2.1
  Fix `where` using only first array value in question mark queries.
  Release alpha.10 with #1276 and #1287
  Spec for HTTPS scheme in NEO4J_URL
  Allow HTTPS scheme in the NEO4J_URL
  Revert "Copy change from yet_another_attempt_to_fix_reloading branch".
  Fix Gemfile after merge.
  ActiveRel factories will build CREATE String
  • Loading branch information
ProGM committed Sep 22, 2016
2 parents ec81236 + 624ba21 commit d8358d6
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 7 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- `count` method in associations, now always fire the database like AR does
- Neo4j now passes all association validations specs, taken from AR (thanks @klobuczek)

## [8.0.0.alpha.10] 2016-09-16

### Fixed
- Remove blank objects from association results to be compatible with `ActiveRecord` (see #1276 / thanks klobuczek)
- Allow https scheme in the NEO4J_URL (see #1287 / thanks jacob-ewald)

## [8.0.0.alpha.9] 2016-09-14

Expand Down Expand Up @@ -118,12 +122,30 @@ This project adheres to [Semantic Versioning](http://semver.org/).

- Made some memory optimizations (thanks ProGM / see #1221)

## [7.2.2] - 09-22-2016

### Fixed

- `where` clause with question mark parameter and array values only using the first element (see #1247 #1290)

## [7.2.1] - 09-19-2016

### Fixed

- During ActiveRel create, node and rel property values formatted like Cypher props (`{val}`) were interpreted as props, causing errors.

## [7.2.0] - 08-23-2016

### Added

- Backporting #1245 to 7.x versions. It implements the [`ForbiddenAttributesProtection` API](http://edgeapi.rubyonrails.org/classes/ActionController/StrongParameters.html) from ActiveRecord.

## [7.1.4] - 09-20-2016

### Fixed

- `where` clause with question mark parameter and array values only using the first element (see #1247 #1290)

## [7.1.3] - 08-18-2016

### Changed
Expand All @@ -149,6 +171,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Gemspec dependency requirements were modified where ActiveModel, ActiveSupport, and Railties are concerned. The gem now requires >= 4.0, < 5.1.
- `ActiveModel::Serializers::Xml` is only included if supported if available.

## [7.0.16] - 09-20-2016

### Fixed

- `where` clause with question mark parameter and array values only using the first element (see #1247 #1290)

## [7.0.15] - 08-18-2016

### Changed
Expand Down
13 changes: 11 additions & 2 deletions lib/neo4j/active_node/labels/reloading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ module Reloading
MODELS_TO_RELOAD = []

def self.reload_models!
Neo4j::ActiveNode::Labels::WRAPPED_CLASSES.clear
Neo4j::ActiveNode::Labels.clear_wrapped_models
MODELS_TO_RELOAD.each(&:constantize)
MODELS_TO_RELOAD.clear
end

module ClassMethods
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
end
6 changes: 5 additions & 1 deletion lib/neo4j/active_node/query/query_proxy_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def initialize(clause, arg, args = [])
end

def args(var, rel_var)
@arg.respond_to?(:call) ? @arg.call(var, rel_var) : [@arg, @args].flatten
if @arg.respond_to?(:call)
@arg.call(var, rel_var)
else
[@arg] + @args
end
end

class << self
Expand Down
3 changes: 2 additions & 1 deletion lib/neo4j/shared/query_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def match_string

def create_query
return match_query if graph_object.persisted?
base_query.create(identifier => {graph_object.labels_for_create => graph_object.props_for_create})
labels = graph_object.labels_for_create.map { |l| ":`#{l}`" }.join
base_query.create("(#{identifier}#{labels} {#{identifier}_params})").params(identifier_params => graph_object.props_for_create)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/neo4j/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Neo4j
VERSION = '8.0.0.alpha.9'
VERSION = '8.0.0.alpha.10'
end
4 changes: 4 additions & 0 deletions spec/e2e/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ def self.ordered_by_subject
expect(Teacher.as(:teach).where('teach.name =~ ?', '.*Othmar.*').to_a).to eq([othmar])
end

it 'allows filtering by array' do
expect(Student.as(:s).where('s.name IN ?', %w(Danny Sandra)).to_a).to contain_exactly(danny, sandra)
end

it 'allows filtering and parametarizing by String and Hash in where' do
expect(Teacher.as(:teach).where('teach.name =~ {name}', name: '.*Othmar.*').to_a).to eq([othmar])
end
Expand Down
40 changes: 38 additions & 2 deletions spec/e2e/shared/query_factory_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
describe Neo4j::Shared::QueryFactory do
before do
let!(:factory_from_class) do
stub_active_node_class('FactoryFromClass') do
property :name
end
end

before do
stub_active_node_class('FactoryToClass') do
property :name
end
Expand All @@ -30,9 +32,33 @@ def self.count
context 'unpersisted' do
it 'builds a query to create' do
expect do
expect(from_node_factory.query.pluck(:from_node).first).to be_a(FactoryFromClass)
expect(from_node_factory.query.pluck(:from_node).first.labels).to eq FactoryFromClass.mapped_label_names
end.to change { FactoryFromClass.count }
end

context 'with a value that might be interpreted as a prop' do
let(:from_node) { FactoryFromClass.new(name: '{Tricky .Value}') }
it 'creates without error' do
expect do
expect(from_node_factory.query.pluck(:from_node).first.labels).to eq FactoryFromClass.mapped_label_names
end.to change { FactoryFromClass.where(name: from_node.name).count }
end
end

context 'with multiple labels' do
before do
stub_named_class('FromSubclass', factory_from_class { include Neo4j::ActiveNode })
FromSubclass.property :other_prop
end

let(:from_node) { FromSubclass.new(other_prop: '{Foo .property}') }

it 'creates the node with all labels' do
expect do
expect(from_node_factory.query.pluck(:from_node).first.labels.sort).to eq FromSubclass.mapped_label_names.sort
end.to change { FromSubclass.where(name: from_node.name).count }
end
end
end

context 'persisted' do
Expand All @@ -54,6 +80,16 @@ def self.count
expect(rel_factory.query.pluck(:rel).first).to be_a(FactoryRelClass)
end.to change { FactoryRelClass.count }
end

context 'with a value that might be interpreted as a prop' do
let(:rel) { FactoryRelClass.new(score: '{9000 ....}') }

it 'creates without error' do
expect do
expect(rel_factory.query.pluck(:rel).first).to be_a(FactoryRelClass)
end.to change { FactoryRelClass.count }
end
end
end

context 'persisted' do
Expand Down

0 comments on commit d8358d6

Please sign in to comment.