Skip to content

Commit

Permalink
return nil if trying to get properties of a node or relationship that…
Browse files Browse the repository at this point in the history
… does not exist
  • Loading branch information
maxdemarzi committed Nov 15, 2010
1 parent 3a1cef5 commit 9a9b24a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
6 changes: 5 additions & 1 deletion lib/neography/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 12 additions & 8 deletions lib/neography/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions spec/integration/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
33 changes: 33 additions & 0 deletions spec/integration/relationship_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9a9b24a

Please sign in to comment.