Skip to content

Commit

Permalink
changed set to reset and added regular set node properties
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Nov 17, 2010
1 parent 25f1abb commit 60e0b4c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and
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.reset_node_properties(id, {"age" => 31}) # Reset a node's 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
Expand Down
9 changes: 7 additions & 2 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_node(id)
rescue_ij { get("/node/#{id}") }
end

def set_node_properties(id, properties)
def reset_node_properties(id, properties)
options = { :body => properties.to_json, :headers => {'Content-Type' => 'application/json'} }
rescue_ij { put("/node/#{id}/properties", options) }
end
Expand All @@ -42,7 +42,12 @@ def remove_node_properties(id, properties = nil)
end
end


def set_node_properties(id, properties)
properties.each do |key, value|
options = { :body => value.to_json, :headers => {'Content-Type' => 'application/json'} }
rescue_ij { put("/node/#{id}/properties/#{key}", options) }
end
end

private

Expand Down
27 changes: 25 additions & 2 deletions spec/integration/rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,33 @@
existing_node["data"]["eyes"].should == "brown"
end

it "returns nil if it fails to set properties on a node that does not exist" do
it "it fails to set 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.set_node_properties(new_node[:id].to_i + 1, {"weight" => 200, "eyes" => "brown"}).should be_nil
Neography::Rest.set_node_properties(new_node[:id].to_i + 1000, {"weight" => 150, "hair" => "blonde"})
node_properties = Neography::Rest.get_node_properties(new_node[:id].to_i + 1000)
node_properties.should be_nil
end
end

describe "reset_node_properties" do
it "can reset a node's properties" do
new_node = Neography::Rest.create_node
new_node[:id] = new_node["self"].split('/').last
Neography::Rest.set_node_properties(new_node[:id], {"weight" => 200, "eyes" => "brown", "hair" => "black"})
Neography::Rest.reset_node_properties(new_node[:id], {"weight" => 190, "eyes" => "blue"})
existing_node = Neography::Rest.get_node(new_node[:id])
existing_node["data"]["weight"].should == 190
existing_node["data"]["eyes"].should == "blue"
existing_node["data"]["hair"].should be_nil
end

it "it fails to reset 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.reset_node_properties(new_node[:id].to_i + 1000, {"weight" => 170, "eyes" => "green"})
node_properties = Neography::Rest.get_node_properties(new_node[:id].to_i + 1000)
node_properties.should be_nil
end
end

Expand Down

0 comments on commit 60e0b4c

Please sign in to comment.