Skip to content

Commit

Permalink
Merge pull request #238 from neo4jrb/hash_in_params_error-5.1.x
Browse files Browse the repository at this point in the history
Hash in params error 5.1.x
  • Loading branch information
subvertallchris committed Oct 27, 2015
2 parents 396fe37 + 562a633 commit 84683ac
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][unreleased]

## [5.1.11] - 2015-10-27

### Fixed

- A bug prevented users of Embedded from executing Cypher queries with hashes contained in params.

## [5.1.10] - 2015-10-23

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion lib/neo4j-core/version.rb
@@ -1,5 +1,5 @@
module Neo4j
module Core
VERSION = '5.1.10'
VERSION = '5.1.11'
end
end
8 changes: 7 additions & 1 deletion lib/neo4j-embedded/embedded_session.rb
Expand Up @@ -146,12 +146,18 @@ def _query(query, params = {}, options = {})
ActiveSupport::Notifications.instrument('neo4j.cypher_query', params: params, context: options[:context],
cypher: query, pretty_cypher: options[:pretty_cypher], params: params) do
@engine ||= Java::OrgNeo4jCypherJavacompat::ExecutionEngine.new(@graph_db)
@engine.execute(query, HashWithIndifferentAccess.new(params))
@engine.execute(query, indifferent_params(params))
end
rescue StandardError => e
raise Neo4j::Session::CypherError.new(e.message, e.class, 'cypher error')
end

def indifferent_params(params)
return {} unless params
params.each { |k, v| params[k] = HashWithIndifferentAccess.new(params[k]) if v.is_a?(Hash) && !v.respond_to?(:nested_under_indifferent_access) }
HashWithIndifferentAccess.new(params)
end

def query_default_return(as)
" RETURN #{as}"
end
Expand Down
9 changes: 9 additions & 0 deletions spec/shared_examples/session.rb
Expand Up @@ -251,6 +251,15 @@ def verify(node)
r = session.query.match(:n).where('ID(n) = {my_var}').return('ID(n) AS id').params(my_var: @jimmy.neo_id)
expect(r.first[:id]).to eq(@jimmy.neo_id)
end

context 'with nested hash' do
it do
expect do
node = session.query.create('(n:FooLabel {foo_params})').params(foo_params: {age: 31}).pluck(:n).first
expect(node.props[:age]).to eq 31
end.not_to raise_error
end
end
end


Expand Down

0 comments on commit 84683ac

Please sign in to comment.