From 5e4be722d907161d9fcd800f6d3b7f715138ddc0 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Tue, 6 Mar 2012 04:05:15 +0000 Subject: [PATCH] add create unique node to batch --- lib/neography/rest.rb | 2 ++ spec/integration/rest_batch_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index b916232..b788edc 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -382,6 +382,8 @@ def get_batch(args) {:method => "GET", :to => "/node/#{get_id(args[1])}"} when :create_node {:method => "POST", :to => "/node/", :body => args[1]} + when :create_unique_node + {:method => "POST", :to => "/index/node/#{args[1]}?unique", :body => {:key => args[2], :value => args[3], :properties => args[4]}} when :set_node_property {:method => "PUT", :to => "/node/#{get_id(args[1])}/properties/#{args[2].keys.first}", :body => args[2].values.first} when :reset_node_properties diff --git a/spec/integration/rest_batch_spec.rb b/spec/integration/rest_batch_spec.rb index 7db6e45..20fafb2 100644 --- a/spec/integration/rest_batch_spec.rb +++ b/spec/integration/rest_batch_spec.rb @@ -53,6 +53,26 @@ batch_result.last["body"]["data"]["name"].should == "Marc" end + it "can create a unique node" do + index_name = generate_text(6) + key = generate_text(6) + value = generate_text + @neo.create_node_index(index_name) + batch_result = @neo.batch [:create_unique_node, index_name, key, value, {"age" => 31, "name" => "Max"}] + batch_result.first["body"]["data"]["name"].should == "Max" + batch_result.first["body"]["data"]["age"].should == 31 + new_node_id = batch_result.first["body"]["self"].split('/').last + batch_result = @neo.batch [:create_unique_node, index_name, key, value, {"age" => 31, "name" => "Max"}] + batch_result.first["body"]["self"].split('/').last.should == new_node_id + batch_result.first["body"]["data"]["name"].should == "Max" + batch_result.first["body"]["data"]["age"].should == 31 + + #Sanity Check + existing_node = @neo.create_unique_node(index_name, key, value, {"age" => 31, "name" => "Max"}) + existing_node["self"].split('/').last.should == new_node_id + existing_node["data"]["name"].should == "Max" + existing_node["data"]["age"].should == 31 + end it "can update a property of a node" do new_node = @neo.create_node("name" => "Max")