From bc22a90424beb15e88a2aadf12bd7ef5c11ba8e1 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Wed, 19 Jun 2013 12:02:17 -0500 Subject: [PATCH] fixing transactions --- README.md | 8 ++++++++ lib/neography/rest.rb | 6 +++--- lib/neography/rest/transactions.rb | 6 +++--- spec/integration/rest_transaction_spec.rb | 22 ++++++++++++++++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fbf7f8e..9e974d6 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,14 @@ It supports indexes, Gremlin scripts, Cypher queries and batch operations. Some of this functionality is shown here, but all of it is explained in the following Wiki pages: +2.0 Only features: + +* [Schema indexes](https://github.com/maxdemarzi/neography/wiki/Schema-indexes) - Create, get and delete schema indexes. +* [Node labels](https://github.com/maxdemarzi/neography/wiki/Node-labels) - Create, get and delete node labels. +* [Transactions](https://github.com/maxdemarzi/neography/wiki/Transactions) - Begin, add to, commit, rollback transactions. + +1.8+ features: + * [Nodes](https://github.com/maxdemarzi/neography/wiki/Nodes) - Create, get and delete nodes. * [Node properties](https://github.com/maxdemarzi/neography/wiki/Node-properties) - Set, get and remove node properties. * [Node relationships](https://github.com/maxdemarzi/neography/wiki/Node-relationships) - Create and get relationships between nodes. diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index b1bd302..acf08b4 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -136,10 +136,10 @@ def keep_transaction(tx) end def commit_transaction(tx, statements=[]) - if tx.is_a?(Array) - @transactions.begin(tx, "commit") - else + if (tx.is_a?(Hash) || tx.is_a?(Integer)) @transactions.commit(tx, statements) + else + @transactions.begin(tx, "/commit") end end diff --git a/lib/neography/rest/transactions.rb b/lib/neography/rest/transactions.rb index d96bdd0..42e1a8d 100644 --- a/lib/neography/rest/transactions.rb +++ b/lib/neography/rest/transactions.rb @@ -60,15 +60,15 @@ def convert_cypher(statements) query = nil parameters = nil Array(statements).each do |statement| - if query & parameters + if query && parameters array << {:statement => query, :parameters => {:props => parameters}} query = statement parameters = nil - elsif query & statement.is_a?(String) + elsif query && statement.is_a?(String) array << {:statement => query} query = statement parameters = nil - elsif query & statement.is_a?(Hash) + elsif query && statement.is_a?(Hash) array << {:statement => query, :parameters => {:props => parameters}} query = nil parameters = nil diff --git a/spec/integration/rest_transaction_spec.rb b/spec/integration/rest_transaction_spec.rb index 7197122..a0f0af8 100644 --- a/spec/integration/rest_transaction_spec.rb +++ b/spec/integration/rest_transaction_spec.rb @@ -74,6 +74,28 @@ existing_tx.should have_key("results") existing_tx["results"].should_not be_empty end + + it "can commit an new transaction right away" do + tx = @neo.commit_transaction(["start n=node(0) return n"]) + tx.should_not have_key("transaction") + tx.should have_key("results") + tx["results"].should_not be_empty + end + + it "can commit an new transaction right away with parameters" do + tx = @neo.commit_transaction(["start n=node({id}) return n", {:id => 0}]) + tx.should_not have_key("transaction") + tx.should have_key("results") + tx["results"].should_not be_empty + end + + it "can commit an new transaction right away without parameters" do + tx = @neo.commit_transaction("start n=node(0) return n") + tx.should_not have_key("transaction") + tx.should have_key("results") + tx["results"].should_not be_empty + end + end describe "rollback a transaction" do