From bbb420abc683598564d4b84be9427fabe45ed4a2 Mon Sep 17 00:00:00 2001 From: Pete Elmore Date: Mon, 30 Jul 2012 13:00:47 -0700 Subject: [PATCH] Add delete_relationship to batch operations. --- lib/neography/rest.rb | 2 ++ spec/integration/rest_batch_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index c527b39..a01a1af 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -509,6 +509,8 @@ def get_batch(args) {:method => "POST", :to => (args[2].is_a?(String) && args[2].start_with?("{") ? "" : "/node/") + "#{get_id(args[2])}/relationships", :body => {:to => (args[3].is_a?(String) && args[3].start_with?("{") ? "" : "/node/") + "#{get_id(args[3])}", :type => args[1], :data => args[4] } } when :create_unique_relationship {:method => "POST", :to => "/index/relationship/#{args[1]}?unique", :body => {:key => args[2], :value => args[3], :type => args[4], :start => (args[5].is_a?(String) && args[5].start_with?("{") ? "" : "/node/") + "#{get_id(args[5])}", :end=> (args[6].is_a?(String) && args[6].start_with?("{") ? "" : "/node/") + "#{get_id(args[6])}"} } + when :delete_relationship + {:method => "DELETE", :to => "/relationship/#{get_id(args[1])}"} when :set_relationship_property {:method => "PUT", :to => "/relationship/#{get_id(args[1])}/properties/#{args[2].keys.first}", :body => args[2].values.first} when :reset_relationship_properties diff --git a/spec/integration/rest_batch_spec.rb b/spec/integration/rest_batch_spec.rb index 19d4c1b..e70e44d 100644 --- a/spec/integration/rest_batch_spec.rb +++ b/spec/integration/rest_batch_spec.rb @@ -144,6 +144,18 @@ batch_result.first["body"]["end"].split('/').last.should == node2["self"].split('/').last end + it "can delete a single relationship" do + node1 = @neo.create_node + node2 = @neo.create_node + batch_result = @neo.batch [:create_relationship, "friends", node1, node2, {:since => "time immemorial"}] + batch_result.should_not be_nil + batch_result[0]["status"].should == 201 + id = batch_result.first["body"]["self"].split("/").last + batch_result = @neo.batch [:delete_relationship, id] + batch_result[0]["status"].should == 204 + batch_result[0]["from"].should == "/relationship/#{id}" + end + it "can create a unique relationship" do index_name = generate_text(6) key = generate_text(6)