Skip to content

Commit

Permalink
bug fixes to rest transactional endpoint, updating tests to 2.0.0-M06
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Oct 3, 2013
1 parent f1e1ba9 commit c0431f5
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -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
47 changes: 33 additions & 14 deletions lib/neography/rest/transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 44 additions & 0 deletions spec/integration/rest_transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c0431f5

Please sign in to comment.