diff --git a/README.rdoc b/README.rdoc index bc7dfce..e25301c 100644 --- a/README.rdoc +++ b/README.rdoc @@ -142,11 +142,13 @@ The Neo4j ID is available by using node.neo_id . my_node.exist? # returns true/false if node exists in Neo4j my_node = Node.create("age" => 31, "name" => "Max") - my_node[:age] #returns 31 # Get a node's property using [:key] - my_node.name #returns "Max" # Get a node's property as a method - my_node[:age] = 24 #changes age to 24 # Set a node's property using [:key] = - my_node.name = "Alex" #changes name to "Alex" # Set a node's property as a method - + my_node[:age] #returns 31 # Get a node property using [:key] + my_node.name #returns "Max" # Get a node property as a method + my_node[:age] = 24 #changes age to 24 # Set a node property using [:key] = + my_node.name = "Alex" #changes name to "Alex" # Set a node property as a method + my_node[:name] = nil # Delete a node property using [:key] = nil + my_node.name = nil # Delete a node property by setting it to nil + See Neo4j API for: * {Order}[http://components.neo4j.org/neo4j-examples/1.2.M04/apidocs/org/neo4j/graphdb/Traverser.Order.html] diff --git a/lib/neography/property.rb b/lib/neography/property.rb index a13c587..087ef17 100644 --- a/lib/neography/property.rb +++ b/lib/neography/property.rb @@ -11,9 +11,11 @@ def []=(key, value) k = key.to_s if value.nil? if self.is_a? Neography::Node - neo_server.remove_node_properties(self.neo_id, {k => value}) + neo_server.remove_node_properties(self.neo_id, [key]) + @table[key] = nil else - neo_server.remove_relationship_properties(self.neo_id, {k => value}) + neo_server.remove_relationship_properties(self.neo_id, [key]) + @table[key] = nil end else if self.is_a? Neography::Node diff --git a/spec/integration/node_spec.rb b/spec/integration/node_spec.rb index 74d3a0a..0eb40de 100644 --- a/spec/integration/node_spec.rb +++ b/spec/integration/node_spec.rb @@ -156,5 +156,43 @@ new_node[:weight].should == 150 new_node[:eyes].should == "green" end + + it "can get node properties" do + new_node = Neography::Node.create("weight" => 150, "eyes" => "green") + new_node.weight.should == 150 + new_node.eyes.should == "green" + end + end + + describe "delete node properties" do + it "can delete node properties using []" do + new_node = Neography::Node.create("weight" => 150, "eyes" => "green") + + new_node[:weight] = nil + new_node[:eyes] = nil + + new_node[:weight].should be_nil + new_node[:eyes].should be_nil + + existing_node = Neography::Node.load(new_node) + existing_node.weight.should be_nil + existing_node.eyes.should be_nil + end + + it "can delete node properties" do + new_node = Neography::Node.create("weight" => 150, "eyes" => "green") + + new_node.weight = nil + new_node.eyes = nil + + new_node.weight.should be_nil + new_node.eyes.should be_nil + + existing_node = Neography::Node.load(new_node) + existing_node.weight.should be_nil + existing_node.eyes.should be_nil + end end + + end \ No newline at end of file