Skip to content

Commit

Permalink
add create unique node to batch
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Mar 6, 2012
1 parent f16ecb6 commit 5e4be72
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions spec/integration/rest_batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5e4be72

Please sign in to comment.