From c0431f5b4a6fe76819492e9028ec6a7bc21debb5 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Wed, 2 Oct 2013 19:25:28 -0500 Subject: [PATCH] bug fixes to rest transactional endpoint, updating tests to 2.0.0-M06 --- .travis.yml | 2 +- lib/neography/rest/transactions.rb | 47 ++++++++++++++++------- spec/integration/rest_transaction_spec.rb | 44 +++++++++++++++++++++ 3 files changed, 78 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 11c2bc2..118b914 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -script: "bundle exec rake neo4j:install['enterprise','2.0.0-M05'] neo4j:start spec --trace" +script: "bundle exec rake neo4j:install['enterprise','2.0.0-M06'] neo4j:start spec --trace" language: ruby rvm: - 1.9.3 diff --git a/lib/neography/rest/transactions.rb b/lib/neography/rest/transactions.rb index 42e1a8d..e8c7506 100644 --- a/lib/neography/rest/transactions.rb +++ b/lib/neography/rest/transactions.rb @@ -60,24 +60,43 @@ def convert_cypher(statements) query = nil parameters = nil Array(statements).each do |statement| - if query && parameters - array << {:statement => query, :parameters => {:props => parameters}} - query = statement - parameters = nil - elsif query && statement.is_a?(String) - array << {:statement => query} - query = statement - parameters = nil - elsif query && statement.is_a?(Hash) - array << {:statement => query, :parameters => {:props => parameters}} - query = nil - parameters = nil + case + when query && parameters && statement.is_a?(Array) + then + array << {:statement => query, :parameters => parameters, :resultDataContents => statement } + query = nil + parameters = nil + when query && parameters && statement.is_a?(String) + then + array << {:statement => query, :parameters => parameters} + query = statement + parameters = nil + when query && statement.is_a?(Hash) + then + parameters = statement + when query && statement.is_a?(Array) + then + array << {:statement => query, :resultDataContents => statement } + query = nil + parameters = nil + else + query = statement end - query = statement + + end + + if query && parameters + array << {:statement => query, :parameters => parameters} + query = nil end - array << {:statement => query} if query + + if query + array << {:statement => query} + end + { :statements => array } end + end end end diff --git a/spec/integration/rest_transaction_spec.rb b/spec/integration/rest_transaction_spec.rb index a0f0af8..19f730e 100644 --- a/spec/integration/rest_transaction_spec.rb +++ b/spec/integration/rest_transaction_spec.rb @@ -18,6 +18,19 @@ tx.should have_key("results") tx["results"].should_not be_empty end + + it "can start a transaction with statements and represent them as a graph" do + tx = @neo.begin_transaction(["CREATE ( bike:Bike { weight: 10 } ) CREATE ( frontWheel:Wheel { spokes: 3 } ) CREATE ( backWheel:Wheel { spokes: 32 } ) CREATE p1 = bike -[:HAS { position: 1 } ]-> frontWheel CREATE p2 = bike -[:HAS { position: 2 } ]-> backWheel RETURN bike, p1, p2", + ["row", "graph", "rest"]]) + tx.should have_key("transaction") + tx.should have_key("results") + tx["results"].should_not be_empty + tx["results"].first["data"].first["row"].should_not be_empty + tx["results"].first["data"].first["graph"].should_not be_empty + tx["results"].first["data"].first["rest"].should_not be_empty + end + + end describe "keep a transaction" do @@ -43,6 +56,37 @@ existing_tx.should have_key("results") existing_tx["results"].should_not be_empty end + + it "can add to a transaction with parameters" do + tx = @neo.begin_transaction + tx.should have_key("transaction") + tx["results"].should be_empty + existing_tx = @neo.in_transaction(tx, ["start n=node({id}) return n", {:id => 0}]) + existing_tx.should have_key("transaction") + existing_tx.should have_key("results") + existing_tx["results"].should_not be_empty + end + + it "can add to a transaction with representation" do + tx = @neo.begin_transaction + tx.should have_key("transaction") + tx["results"].should be_empty + existing_tx = @neo.in_transaction(tx, ["start n=node(0) return n", [:row,:rest]]) + existing_tx.should have_key("transaction") + existing_tx.should have_key("results") + existing_tx["results"].should_not be_empty + end + + it "can add to a transaction with parameters and representation" do + tx = @neo.begin_transaction + tx.should have_key("transaction") + tx["results"].should be_empty + existing_tx = @neo.in_transaction(tx, ["start n=node({id}) return n", {:id => 0}, [:row,:rest]]) + existing_tx.should have_key("transaction") + existing_tx.should have_key("results") + existing_tx["results"].should_not be_empty + end + end describe "commit a transaction" do