From 9a9b24a06f19c50af719d21d662ead78e46d3f64 Mon Sep 17 00:00:00 2001 From: maxdemarzi Date: Mon, 15 Nov 2010 14:57:16 -0800 Subject: [PATCH] return nil if trying to get properties of a node or relationship that does not exist --- lib/neography/node.rb | 6 ++++- lib/neography/relationship.rb | 20 +++++++++------- spec/integration/node_spec.rb | 5 ++++ spec/integration/relationship_spec.rb | 33 +++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/lib/neography/node.rb b/lib/neography/node.rb index 30b044e..d4f5a2f 100644 --- a/lib/neography/node.rb +++ b/lib/neography/node.rb @@ -30,7 +30,11 @@ def load(id) end def properties(id) - get("/node/#{id}/properties") + begin + get("/node/#{id}/properties") + rescue + nil + end end def set_properties(id, properties) diff --git a/lib/neography/relationship.rb b/lib/neography/relationship.rb index 5cacd53..ec73fcf 100644 --- a/lib/neography/relationship.rb +++ b/lib/neography/relationship.rb @@ -14,17 +14,21 @@ def new(type, from, to, props = nil) end def load(id) - begin - response = get("/node/#{id}") - evaluate_response(response) - build_relationship(response) - rescue - nil - end + begin + response = get("/relationship/#{id}") + evaluate_response(response) + build_relationship(response) + rescue + nil + end end def properties(id) - get("/relationship/#{id}/properties") + begin + get("/relationship/#{id}/properties") + rescue + nil + end end def set_properties(id, properties) diff --git a/spec/integration/node_spec.rb b/spec/integration/node_spec.rb index 579762d..2eec6d4 100644 --- a/spec/integration/node_spec.rb +++ b/spec/integration/node_spec.rb @@ -30,6 +30,11 @@ Neography::Node.properties(1).should be_nil end + + it "returns nil if the properties of a node that does not exist are requested" do + Neography::Node.properties(999).should be_nil + end + it "can set a node's properties" do Neography::Node.set_properties(2, {:age => 32, :name => "Tom"} ).should be_nil Neography::Node.properties(2).should include("age"=>32, "name"=>"Tom") diff --git a/spec/integration/relationship_spec.rb b/spec/integration/relationship_spec.rb index c5b03fe..231d9fb 100644 --- a/spec/integration/relationship_spec.rb +++ b/spec/integration/relationship_spec.rb @@ -24,4 +24,37 @@ Neography::Relationship.properties(rel[:rel_id]).should be_nil end + it "can set a relationship's properties" do + rel = Neography::Relationship.new(:friends, Neography::Node.new, Neography::Node.new) + Neography::Relationship.set_properties(rel[:rel_id], {:since => '10-1-2010'} ).should be_nil + Neography::Relationship.properties(rel[:rel_id]).should include("since"=>"10-1-2010") + end + + it "returns nil if it tries to delete a property that does not exist" do + rel = Neography::Relationship.new(:friends, Neography::Node.new, Neography::Node.new) + Neography::Relationship.set_properties(rel[:rel_id], {:since => '10-1-2010'} ).should be_nil + Neography::Relationship.remove_property(rel[:rel_id], :closeness).should be_nil + end + + it "returns nil if it tries to delete a property on a relationship that does not exist" do + Neography::Relationship.remove_property(9999, :closeness).should be_nil + end + + it "can delete all of a relationship's properties" do + rel = Neography::Relationship.new(:friends, Neography::Node.new, Neography::Node.new) + Neography::Relationship.set_properties(rel[:rel_id], {:since => '10-1-2010'} ).should be_nil + Neography::Relationship.remove_properties(rel[:rel_id]).should be_nil + Neography::Relationship.properties(rel[:rel_id]).should be_nil + end + + it "can delete a relationship" do + rel = Neography::Relationship.new(:friends, Neography::Node.new, Neography::Node.new) + Neography::Relationship.del(rel[:rel_id]).should be_nil + Neography::Relationship.properties(rel[:rel_id]).should be_nil + end + + it "returns nil if it tries to delete a relationship that does not exist" do + Neography::Relationship.del(9999).should be_nil + end + end \ No newline at end of file