Skip to content

Commit

Permalink
adding tests and readme for unique nodes and relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Feb 9, 2012
1 parent 914d4d3 commit 3313e4a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
26 changes: 17 additions & 9 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Neography is a thin Ruby wrapper to the Neo4j Rest API, for more information:

If you want to the full power of Neo4j, you will want to use JRuby and the excellent Neo4j.rb gem at https://github.com/andreasronge/neo4j by Andreas Ronge

A complement to Neography is the Neology Gem at https://github.com/lordkada/neology by Carlo Alberto Degli Atti
Complement to Neography are the:
Neology Gem at https://github.com/lordkada/neology by Carlo Alberto Degli Atti
Neoid Gem at https://github.com/elado/neoid by Elad Ossadon

An alternative is the Architect4r Gem at https://github.com/namxam/architect4r by Maximilian Schulz

Expand Down Expand Up @@ -96,8 +98,11 @@ To Use:
@neo = Neography::Rest.new # Inialize using all default parameters

@neo.get_root # Get the root node
node1 = @neo.create_node # Create an empty node
node2 = @neo.create_node("age" => 31, "name" => "Max") # Create a node with some properties
@neo.create_node # Create an empty node
@neo.create_node("age" => 31, "name" => "Max") # Create a node with some properties
@neo.create_unique_node(index_name, key, unique_value, # Create a unique node
{"age" => 31, "name" => "Max"}) # this needs an existing index

@neo.get_node(node2) # Get a node and its properties
@neo.delete_node(node2) # Delete an unrelated node
@neo.delete_node!(node2) # Delete a node and all its relationships
Expand All @@ -110,8 +115,11 @@ To Use:
@neo.remove_node_properties(node1, "weight") # Remove one property of a node
@neo.remove_node_properties(node1, ["weight","age"]) # Remove multiple properties of a node

rel1 = @neo.create_relationship("friends", node1, node2) # Create a relationship between node1 and node2
rel2 = @neo.get_relationship(rel1) # Get a relationship
@neo.create_relationship("friends", node1, node2) # Create a relationship between node1 and node2
@neo.create_unique_relationship(index_name, key, value, # Create a unique relationship between nodes
"friends", new_node1, new_node2) # this needs an existing index

@neo.get_relationship(rel1) # Get a relationship
@neo.get_node_relationships(node1) # Get all relationships
@neo.get_node_relationships(node1, "in") # Get only incoming relationships
@neo.get_node_relationships(node1, "all", "enemies") # Get all relationships of type enemies
Expand Down Expand Up @@ -169,10 +177,6 @@ To Use:
# "depth" is a short-hand way of specifying a prune evaluator which prunes after a certain depth.
# If not specified a depth of 1 is used and if a "prune evaluator" is specified instead of a depth, no depth limit is set.

Please see the specs for more examples.

Batch (in progress):

@neo.batch [:get_node, node1], [:get_node, node2] # Gets two nodes in a batch
@neo.batch [:create_node, {"name" => "Max"}],
[:create_node, {"name" => "Marc"}] # Creates two nodes in a batch
Expand All @@ -198,6 +202,10 @@ Batch (in progress):

See http://docs.neo4j.org/chunked/milestone/rest-api-batch-ops.html for Neo4j Batch operations documentation.


Please see the specs for more examples.


Experimental:

nodes = @neo.create_nodes(5) # Create 5 empty nodes
Expand Down
11 changes: 11 additions & 0 deletions spec/integration/rest_node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
new_node["data"]["name"].should == "Max"
new_node["data"]["age"].should == 31
end

it "can create a unique node with more than one property" do
index_name = generate_text(6)
key = generate_text(6)
value = generate_text
@neo.create_node_index(index_name)
new_node = @neo.create_unique_node(index_name, key, value, {"age" => 31, "name" => "Max"})
new_node["data"]["name"].should == "Max"
new_node["data"]["age"].should == 31
end

end

describe "get_node" do
Expand Down
22 changes: 22 additions & 0 deletions spec/integration/rest_relationship_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@
new_relationship["data"]["since"].should == '10-1-2010'
new_relationship["data"]["met"].should == "college"
end

it "can create a unique node with more than one property" do
index_name = generate_text(6)
key = generate_text(6)
value = generate_text
@neo.create_node_index(index_name)
new_node = @neo.create_unique_node(index_name, key, value, {"age" => 31, "name" => "Max"})
new_node["data"]["name"].should == "Max"
new_node["data"]["age"].should == 31
end

it "can create a unique relationship" do
index_name = generate_text(6)
key = generate_text(6)
value = generate_text
new_node1 = @neo.create_node
new_node2 = @neo.create_node
new_relationship = @neo.create_unique_relationship(index_name, key, value, "friends", new_node1, new_node2)
new_relationship["data"][key].should == value
end


end

describe "get_relationship" do
Expand Down

0 comments on commit 3313e4a

Please sign in to comment.