Skip to content

Commit

Permalink
Merge pull request #213 from neo4jrb/collections_within_transactions
Browse files Browse the repository at this point in the history
fixes handling of collections within transactions
  • Loading branch information
subvertallchris committed Jun 24, 2015
2 parents 0f7fa28 + 6c33421 commit 7faa2dc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
3 changes: 2 additions & 1 deletion lib/neo4j-server/cypher_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ def id_from_url(url)
attr_reader :result_index

def mapped_rest_data
response.body[:results][0][:data][result_index][:rest][row_index]
data = response.body[:results][0][:data][result_index][:rest][row_index]
data.is_a?(Array) ? data.first : data
end
end
end
Expand Down
53 changes: 39 additions & 14 deletions spec/shared_examples/node_with_tx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,46 @@
end
end

describe 'returning a hash from cypher' do
before { Neo4j::Node.create({name: 'Foo'}, :person) }
describe 'complex structures' do
let!(:node) { Neo4j::Node.create({name: 'Foo'}, :Person) }

describe 'returning a collection' do
it 'does not raise an error' do
begin
tx = Neo4j::Transaction.new
expect { Neo4j::Session.current.query.match(p: :Person).pluck('collect(p)') }.not_to raise_error
ensure
tx.close
end
end

it 'is not mistaken for a malformed object' do
begin
tx = Neo4j::Transaction.new
Neo4j::Session.current.query.match(person: 'person').pluck('person limit 1')
response = Neo4j::Session.current.query.match(person: 'person').where(person: {name: 'Foo'})
.pluck('person, { name: person.name, labels: LABELS(person)[0]} as ph').first
expect(response[1]).to be_a(Hash)
# Behavior differs slightly in JRuby/Embedded.
key = response[1].key?('name') ? 'name' : :name
expect(response[1][key]).to eq 'Foo'
ensure
tx.close if Neo4j::Transaction.current
it 'returns a node within an array' do
begin
tx = Neo4j::Transaction.new
result = Neo4j::Session.current.query.match(p: :Person).pluck('collect(p)').first
expect(result).to be_a(Array)
expect(result.first).to respond_to(:neo_id)
expect(result.first.labels).to include(:Person)
ensure
tx.close
end
end
end

describe 'returning a hash from cypher' do
it 'is not mistaken for a malformed object' do
begin
tx = Neo4j::Transaction.new
Neo4j::Session.current.query.match(person: 'Person').pluck('person limit 1')
response = Neo4j::Session.current.query.match(person: 'Person').where(person: {name: 'Foo'})
.pluck('person, { name: person.name, labels: LABELS(person)[0]} as ph').first
expect(response[1]).to be_a(Hash)
# Behavior differs slightly in JRuby/Embedded.
key = response[1].key?('name') ? 'name' : :name
expect(response[1][key]).to eq 'Foo'
ensure
tx.close if Neo4j::Transaction.current
end
end
end
end
Expand Down

0 comments on commit 7faa2dc

Please sign in to comment.