Skip to content

Commit

Permalink
added remove_node_properties
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Nov 17, 2010
1 parent 3bd4035 commit 25f1abb
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
15 changes: 9 additions & 6 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ There are two ways to use Neography:

A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and returns JSON or Nil:

Neography::Rest.get_root # Get the root node
Neography::Rest.create_node # Create an empty node
Neography::Rest.create_node("age" => 31, "name" => "Max") # Create a node with some properties
Neography::Rest.get_node(id) # Get a node and its properties
Neography::Rest.set_node_properties(id, {"weight" => 200}) # Set a node's properties
Neography::Rest.get_node_properties(id) # Get just the properties
Neography::Rest.get_root # Get the root node
Neography::Rest.create_node # Create an empty node
Neography::Rest.create_node("age" => 31, "name" => "Max") # Create a node with some properties
Neography::Rest.get_node(id) # Get a node and its properties
Neography::Rest.set_node_properties(id, {"weight" => 200}) # Set a node's properties
Neography::Rest.get_node_properties(id) # Get just the properties
Neography::Rest.remove_node_properties(id) # Remove all properties of a node
Neography::Rest.remove_node_properties(id, "weight") # Remove one property of a node
Neography::Rest.remove_node_properties(id, ["weight","age"]) # Remove multiple properties of a node

... and a work in progress more rubyish layer that's not quite ready for use yet.

Expand Down
12 changes: 12 additions & 0 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ def get_node_properties(id)
rescue_ij { get("/node/#{id}/properties") }
end

def remove_node_properties(id, properties = nil)
if properties.nil?
rescue_ij { delete("/node/#{id}/properties") }
else
properties.to_a.each do |property|
rescue_ij { delete("/node/#{id}/properties/#{property}") }
end
end
end



private

# Rescue from Invalid JSON error thrown by Crack Gem
Expand Down
38 changes: 36 additions & 2 deletions spec/integration/rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,49 @@
it "returns nil if it gets the properties on a node that does not have any" do
new_node = Neography::Rest.create_node
new_node[:id] = new_node["self"].split('/').last
Neography::Rest.get_node_properties(new_node[:id].to_i + 1).should be_nil
Neography::Rest.get_node_properties(new_node[:id].to_i + 10000).should be_nil
end

it "returns nil if it fails to get properties on a node that does not exist" do
new_node = Neography::Rest.create_node
new_node[:id] = new_node["self"].split('/').last
Neography::Rest.get_node_properties(new_node[:id].to_i + 1).should be_nil
Neography::Rest.get_node_properties(new_node[:id].to_i + 10000).should be_nil
end
end

describe "remove_node_properties" do
it "can remove a node's properties" do
new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown")
new_node[:id] = new_node["self"].split('/').last
Neography::Rest.remove_node_properties(new_node[:id])
Neography::Rest.get_node_properties(new_node[:id]).should be_nil
end

it "returns nil if it fails to remove the properties of a node that does not exist" do
new_node = Neography::Rest.create_node
new_node[:id] = new_node["self"].split('/').last
Neography::Rest.remove_node_properties(new_node[:id].to_i + 10000).should be_nil
end

it "can remove a specific node property" do
new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown")
new_node[:id] = new_node["self"].split('/').last
Neography::Rest.remove_node_properties(new_node[:id], "weight")
node_properties = Neography::Rest.get_node_properties(new_node[:id])
node_properties["weight"].should be_nil
node_properties["eyes"].should == "brown"
end

it "can remove more than one property" do
new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown", "height" => "2m")
new_node[:id] = new_node["self"].split('/').last
Neography::Rest.remove_node_properties(new_node[:id], ["weight", "eyes"])
node_properties = Neography::Rest.get_node_properties(new_node[:id])
node_properties["weight"].should be_nil
node_properties["eyes"].should be_nil
end

end


end

0 comments on commit 25f1abb

Please sign in to comment.