diff --git a/lib/neo4j-server/cypher_response.rb b/lib/neo4j-server/cypher_response.rb index e2d82906..b166206a 100644 --- a/lib/neo4j-server/cypher_response.rb +++ b/lib/neo4j-server/cypher_response.rb @@ -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 diff --git a/spec/shared_examples/node_with_tx.rb b/spec/shared_examples/node_with_tx.rb index 58bc21e9..6c6529d7 100644 --- a/spec/shared_examples/node_with_tx.rb +++ b/spec/shared_examples/node_with_tx.rb @@ -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