diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..887c946 --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,5 @@ +Maintainer: + Max De Marzi + +Contributors: +* Peter Neubauer diff --git a/Gemfile.lock b/Gemfile.lock index ecb86b9..1aef492 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - neography (0.0.1) + neography (0.0.2) httparty (~> 0.6.1) json diff --git a/README.rdoc b/README.rdoc index a4ea1cd..d7d30d1 100644 --- a/README.rdoc +++ b/README.rdoc @@ -46,45 +46,45 @@ To Use: @neo = Neography::Rest.new - @neo.get_root # Get the root node - @neo.create_node # Create an empty node - @neo.create_node("age" => 31, "name" => "Max") # Create a node with some properties - @neo.get_node(id) # Get a node and its properties - @neo.delete_node(id) # Delete an unrelated node - @neo.delete_node!(id) # Delete a node and all its relationships - - @neo.reset_node_properties(id, {"age" => 31}) # Reset a node's properties - @neo.set_node_properties(id, {"weight" => 200}) # Set a node's properties - @neo.get_node_properties(id) # Get just the node properties - @neo.get_node_properties(id, ["weight","age"]) # Get some of the node properties - @neo.remove_node_properties(id) # Remove all properties of a node - @neo.remove_node_properties(id, "weight") # Remove one property of a node - @neo.remove_node_properties(id, ["weight","age"]) # Remove multiple properties of a node - - @neo.create_relationship("friends", node1, node2) # Create a relationship between node1 and node2 - @neo.get_node_relationships(id) # Get all relationships - @neo.get_node_relationships(id, "in") # Get only incoming relationships - @neo.get_node_relationships(id, "all", "enemies") # Get all relationships of type enemies - @neo.get_node_relationships(id, "in", "enemies") # Get only incoming relationships of type enemies - @neo.delete_relationship(id) # Delete a relationship - - @neo.reset_relationship_properties(id, {"age" => 31}) # Reset a relationship's properties - @neo.set_relationship_properties(id, {"weight" => 200}) # Set a relationship's properties - @neo.get_relationship_properties(id) # Get just the relationship properties - @neo.get_relationship_properties(id, ["since","met"]) # Get some of the relationship properties - @neo.remove_relationship_properties(id) # Remove all properties of a relationship - @neo.remove_relationship_properties(id, "since") # Remove one property of a relationship - @neo.remove_relationship_properties(id, ["since","met"]) # Remove multiple properties of a relationship - - @neo.list_indexes # doesn't really seam to do what the api says it does - @neo.add_to_index(key, value, id) # adds a node to an index with the given key/value pair - @neo.remove_from_index(key, value, id) # removes a node to an index with the given key/value pair - @neo.get_index(key, value) # gets an index with the given key/value pair - - @neo.get_path(from, to, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes - @neo.get_paths(from, to, relationships, depth=3, algorithm="allPaths") # finds all paths between two nodes - - nodes = @neo.traverse(id, # the id of the node where the traversal starts + @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.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 + + @neo.reset_node_properties(node1, {"age" => 31}) # Reset a node's properties + @neo.set_node_properties(node1, {"weight" => 200}) # Set a node's properties + @neo.get_node_properties(node1) # Get just the node properties + @neo.get_node_properties(node1, ["weight","age"]) # Get some of the node properties + @neo.remove_node_properties(node1) # Remove all properties of a node + @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 + @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 + @neo.get_node_relationships(node1, "in", "enemies") # Get only incoming relationships of type enemies + @neo.delete_relationship(rel1) # Delete a relationship + + @neo.reset_relationship_properties(rel1, {"age" => 31}) # Reset a relationship's properties + @neo.set_relationship_properties(rel1, {"weight" => 200}) # Set a relationship's properties + @neo.get_relationship_properties(rel1) # Get just the relationship properties + @neo.get_relationship_properties(rel1, ["since","met"]) # Get some of the relationship properties + @neo.remove_relationship_properties(rel1) # Remove all properties of a relationship + @neo.remove_relationship_properties(rel1, "since") # Remove one property of a relationship + @neo.remove_relationship_properties(rel1, ["since","met"]) # Remove multiple properties of a relationship + + @neo.list_indexes # doesn't really seam to do what the api says it does + @neo.add_to_index(key, value, node1) # adds a node to an index with the given key/value pair + @neo.remove_from_index(key, value, node1) # removes a node to an index with the given key/value pair + @neo.get_index(key, value) # gets an index with the given key/value pair + + @neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes + @neo.get_paths(node1, node2, relationships, depth=3, algorithm="allPaths") # finds all paths between two nodes + + nodes = @neo.traverse(node1, # the node where the traversal starts "nodes", # return_type (can be "nodes", "relationships" or "paths" {"order" => "breadth first", # "breadth first" or "depth first" traversal order "uniqueness" => "node global", # See Uniqueness in API documentation for options. diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 4491edc..3c0556f 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -36,21 +36,21 @@ def create_node(*args) end def get_node(id) - get("/node/#{id}") + get("/node/#{get_id(id)}") end def reset_node_properties(id, properties) options = { :body => properties.to_json, :headers => {'Content-Type' => 'application/json'} } - put("/node/#{id}/properties", options) + put("/node/#{get_id(id)}/properties", options) end def get_node_properties(id, properties = nil) if properties.nil? - get("/node/#{id}/properties") + get("/node/#{get_id(id)}/properties") else node_properties = Hash.new properties.to_a.each do |property| - value = get("/node/#{id}/properties/#{property}") + value = get("/node/#{get_id(id)}/properties/#{property}") node_properties[property] = value unless value.nil? end return nil if node_properties.empty? @@ -60,10 +60,10 @@ def get_node_properties(id, properties = nil) def remove_node_properties(id, properties = nil) if properties.nil? - delete("/node/#{id}/properties") + delete("/node/#{get_id(id)}/properties") else properties.to_a.each do |property| - delete("/node/#{id}/properties/#{property}") + delete("/node/#{get_id(id)}/properties/#{property}") end end end @@ -71,31 +71,31 @@ def remove_node_properties(id, properties = nil) def set_node_properties(id, properties) properties.each do |key, value| options = { :body => value.to_json, :headers => {'Content-Type' => 'application/json'} } - put("/node/#{id}/properties/#{key}", options) + put("/node/#{get_id(id)}/properties/#{key}", options) end end def delete_node(id) - delete("/node/#{id}") + delete("/node/#{get_id(id)}") end def create_relationship(type, from, to, props = nil) - options = { :body => {:to => self.configuration + "/node/#{to}", :data => props, :type => type }.to_json, :headers => {'Content-Type' => 'application/json'} } - post("/node/#{from}/relationships", options) + options = { :body => {:to => self.configuration + "/node/#{get_id(to)}", :data => props, :type => type }.to_json, :headers => {'Content-Type' => 'application/json'} } + post("/node/#{get_id(from)}/relationships", options) end def reset_relationship_properties(id, properties) options = { :body => properties.to_json, :headers => {'Content-Type' => 'application/json'} } - put("/relationship/#{id}/properties", options) + put("/relationship/#{get_id(id)}/properties", options) end def get_relationship_properties(id, properties = nil) if properties.nil? - get("/relationship/#{id}/properties") + get("/relationship/#{get_id(id)}/properties") else relationship_properties = Hash.new properties.to_a.each do |property| - value = get("/relationship/#{id}/properties/#{property}") + value = get("/relationship/#{get_id(id)}/properties/#{property}") relationship_properties[property] = value unless value.nil? end return nil if relationship_properties.empty? @@ -105,10 +105,10 @@ def get_relationship_properties(id, properties = nil) def remove_relationship_properties(id, properties = nil) if properties.nil? - delete("/relationship/#{id}/properties") + delete("/relationship/#{get_id(id)}/properties") else properties.to_a.each do |property| - delete("/relationship/#{id}/properties/#{property}") + delete("/relationship/#{get_id(id)}/properties/#{property}") end end end @@ -116,30 +116,30 @@ def remove_relationship_properties(id, properties = nil) def set_relationship_properties(id, properties) properties.each do |key, value| options = { :body => value.to_json, :headers => {'Content-Type' => 'application/json'} } - put("/relationship/#{id}/properties/#{key}", options) + put("/relationship/#{get_id(id)}/properties/#{key}", options) end end def delete_relationship(id) - delete("/relationship/#{id}") + delete("/relationship/#{get_id(id)}") end def get_node_relationships(id, dir=nil, types=nil) dir = get_dir(dir) if types.nil? - node_relationships = get("/node/#{id}/relationships/#{dir}") || Array.new + node_relationships = get("/node/#{get_id(id)}/relationships/#{dir}") || Array.new else - node_relationships = get("/node/#{id}/relationships/#{dir}/#{types.to_a.join('&')}") || Array.new + node_relationships = get("/node/#{get_id(id)}/relationships/#{dir}/#{types.to_a.join('&')}") || Array.new end return nil if node_relationships.empty? node_relationships end def delete_node!(id) - relationships = get_node_relationships(id) + relationships = get_node_relationships(get_id(id)) relationships.each { |r| delete_relationship(r["self"].split('/').last) } unless relationships.nil? - delete("/node/#{id}") + delete("/node/#{get_id(id)}") end def list_indexes @@ -147,12 +147,12 @@ def list_indexes end def add_to_index(key, value, id) - options = { :body => (self.configuration + "/node/#{id}").to_json, :headers => {'Content-Type' => 'application/json'} } + options = { :body => (self.configuration + "/node/#{get_id(id)}").to_json, :headers => {'Content-Type' => 'application/json'} } post("/index/node/#{key}/#{value}", options) end def remove_from_index(key, value, id) - delete("/index/node/#{key}/#{value}/#{id}") + delete("/index/node/#{key}/#{value}/#{get_id(id)}") end def get_index(key, value) @@ -168,17 +168,17 @@ def traverse(id, return_type, description) "prune evaluator" => description["prune evaluator"], "return filter" => description["return filter"], "max depth" => get_depth(description["depth"]), }.to_json, :headers => {'Content-Type' => 'application/json'} } - traversal = post("/node/#{id}/traverse/#{get_type(return_type)}", options) || Array.new + traversal = post("/node/#{get_id(id)}/traverse/#{get_type(return_type)}", options) || Array.new end def get_path(from, to, relationships, depth=1, algorithm="shortestPath") - options = { :body => {"to" => self.configuration + "/node/#{to}", "relationships" => relationships, "max depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} } - path = post("/node/#{from}/path", options) || Hash.new + options = { :body => {"to" => self.configuration + "/node/#{get_id(to)}", "relationships" => relationships, "max depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} } + path = post("/node/#{get_id(from)}/path", options) || Hash.new end def get_paths(from, to, relationships, depth=1, algorithm="allPaths") - options = { :body => {"to" => self.configuration + "/node/#{to}", "relationships" => relationships, "max depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} } - paths = post("/node/#{from}/paths", options) || Array.new + options = { :body => {"to" => self.configuration + "/node/#{get_id(to)}", "relationships" => relationships, "max depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} } + paths = post("/node/#{get_id(from)}/paths", options) || Array.new end private @@ -190,10 +190,10 @@ def evaluate_response(response) case code when 200 @logger.debug "OK" if @log_enabled - response + response.parsed_response when 201 @logger.debug "OK, created #{body}" if @log_enabled - response + response.parsed_response when 204 @logger.debug "OK, no content returned" if @log_enabled nil @@ -225,6 +225,17 @@ def delete(path,options={}) evaluate_response(HTTParty.delete(configuration + path, options)) end + def get_id(id) + case id + when Hash + id["self"].split('/').last + when String + id.split('/').last + else + id + end + end + def get_dir(dir) case dir when :incoming, "incoming", :in, "in" diff --git a/spec/integration/rest_index_spec.rb b/spec/integration/rest_index_spec.rb index 939376f..4c27525 100644 --- a/spec/integration/rest_index_spec.rb +++ b/spec/integration/rest_index_spec.rb @@ -14,26 +14,24 @@ describe "add to index" do it "can add a node to an index" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last key = generate_text(6) value = generate_text - @neo.add_to_index(key, value, new_node[:id]) + @neo.add_to_index(key, value, new_node) new_index = @neo.get_index(key, value) new_index.should_not be_nil - @neo.remove_from_index(key, value, new_node[:id]) + @neo.remove_from_index(key, value, new_node) end end describe "remove from index" do it "can remove a node from an index" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last key = generate_text(6) value = generate_text - @neo.add_to_index(key, value, new_node[:id]) + @neo.add_to_index(key, value, new_node) new_index = @neo.get_index(key, value) new_index.should_not be_nil - @neo.remove_from_index(key, value, new_node[:id]) + @neo.remove_from_index(key, value, new_node) new_index = @neo.get_index(key, value) new_index.should be_nil end @@ -42,13 +40,12 @@ describe "get index" do it "can get an index" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last key = generate_text(6) value = generate_text - @neo.add_to_index(key, value, new_node[:id]) + @neo.add_to_index(key, value, new_node) new_index = @neo.get_index(key, value) new_index.should_not be_nil - @neo.remove_from_index(key, value, new_node[:id]) + @neo.remove_from_index(key, value, new_node) end end diff --git a/spec/integration/rest_node_spec.rb b/spec/integration/rest_node_spec.rb index b282429..1beb0b3 100644 --- a/spec/integration/rest_node_spec.rb +++ b/spec/integration/rest_node_spec.rb @@ -34,7 +34,7 @@ it "can get a node that exists" do new_node = @neo.create_node new_node[:id] = new_node["self"].split('/').last - existing_node = @neo.get_node(new_node[:id]) + existing_node = @neo.get_node(new_node) existing_node.should_not be_nil existing_node.should have_key("self") existing_node["self"].split('/').last.should == new_node[:id] @@ -42,8 +42,8 @@ it "returns nil if it tries to get a node that does not exist" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - existing_node = @neo.get_node(new_node[:id].to_i + 1000) + fake_node = new_node["self"].split('/').last.to_i + 1000 + existing_node = @neo.get_node(fake_node) existing_node.should be_nil end end @@ -51,18 +51,17 @@ describe "set_node_properties" do it "can set a node's properties" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.set_node_properties(new_node[:id], {"weight" => 200, "eyes" => "brown"}) - existing_node = @neo.get_node(new_node[:id]) + @neo.set_node_properties(new_node, {"weight" => 200, "eyes" => "brown"}) + existing_node = @neo.get_node(new_node) existing_node["data"]["weight"].should == 200 existing_node["data"]["eyes"].should == "brown" end it "it fails to set properties on a node that does not exist" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.set_node_properties(new_node[:id].to_i + 1000, {"weight" => 150, "hair" => "blonde"}) - node_properties = @neo.get_node_properties(new_node[:id].to_i + 1000) + fake_node = new_node["self"].split('/').last.to_i + 1000 + @neo.set_node_properties(fake_node, {"weight" => 150, "hair" => "blonde"}) + node_properties = @neo.get_node_properties(fake_node) node_properties.should be_nil end end @@ -70,10 +69,9 @@ describe "reset_node_properties" do it "can reset a node's properties" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.set_node_properties(new_node[:id], {"weight" => 200, "eyes" => "brown", "hair" => "black"}) - @neo.reset_node_properties(new_node[:id], {"weight" => 190, "eyes" => "blue"}) - existing_node = @neo.get_node(new_node[:id]) + @neo.set_node_properties(new_node, {"weight" => 200, "eyes" => "brown", "hair" => "black"}) + @neo.reset_node_properties(new_node, {"weight" => 190, "eyes" => "blue"}) + existing_node = @neo.get_node(new_node) existing_node["data"]["weight"].should == 190 existing_node["data"]["eyes"].should == "blue" existing_node["data"]["hair"].should be_nil @@ -81,9 +79,9 @@ it "it fails to reset properties on a node that does not exist" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.reset_node_properties(new_node[:id].to_i + 1000, {"weight" => 170, "eyes" => "green"}) - node_properties = @neo.get_node_properties(new_node[:id].to_i + 1000) + fake_node = new_node["self"].split('/').last.to_i + 1000 + @neo.reset_node_properties(fake_node, {"weight" => 170, "eyes" => "green"}) + node_properties = @neo.get_node_properties(fake_node) node_properties.should be_nil end end @@ -91,16 +89,14 @@ describe "get_node_properties" do it "can get all of a node's properties" do new_node = @neo.create_node("weight" => 200, "eyes" => "brown") - new_node[:id] = new_node["self"].split('/').last - node_properties = @neo.get_node_properties(new_node[:id]) + node_properties = @neo.get_node_properties(new_node) node_properties["weight"].should == 200 node_properties["eyes"].should == "brown" end it "can get some of a node's properties" do new_node = @neo.create_node("weight" => 200, "eyes" => "brown", "height" => "2m") - new_node[:id] = new_node["self"].split('/').last - node_properties = @neo.get_node_properties(new_node[:id], ["weight", "height"]) + node_properties = @neo.get_node_properties(new_node, ["weight", "height"]) node_properties["weight"].should == 200 node_properties["height"].should == "2m" node_properties["eyes"].should be_nil @@ -108,51 +104,46 @@ it "returns nil if it gets the properties on a node that does not have any" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.get_node_properties(new_node[:id]).should be_nil + @neo.get_node_properties(new_node).should be_nil end it "returns nil if it tries to get some of the properties on a node that does not have any" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.get_node_properties(new_node[:id], ["weight", "height"]).should be_nil + @neo.get_node_properties(new_node, ["weight", "height"]).should be_nil end it "returns nil if it fails to get properties on a node that does not exist" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.get_node_properties(new_node[:id].to_i + 10000).should be_nil + fake_node = new_node["self"].split('/').last.to_i + 1000 + @neo.get_node_properties(fake_node).should be_nil end end describe "remove_node_properties" do it "can remove a node's properties" do new_node = @neo.create_node("weight" => 200, "eyes" => "brown") - new_node[:id] = new_node["self"].split('/').last - @neo.remove_node_properties(new_node[:id]) - @neo.get_node_properties(new_node[:id]).should be_nil + @neo.remove_node_properties(new_node) + @neo.get_node_properties(new_node).should be_nil end it "returns nil if it fails to remove the properties of a node that does not exist" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.remove_node_properties(new_node[:id].to_i + 10000).should be_nil + fake_node = new_node["self"].split('/').last.to_i + 1000 + @neo.remove_node_properties(fake_node).should be_nil end it "can remove a specific node property" do new_node = @neo.create_node("weight" => 200, "eyes" => "brown") - new_node[:id] = new_node["self"].split('/').last - @neo.remove_node_properties(new_node[:id], "weight") - node_properties = @neo.get_node_properties(new_node[:id]) + @neo.remove_node_properties(new_node, "weight") + node_properties = @neo.get_node_properties(new_node) node_properties["weight"].should be_nil node_properties["eyes"].should == "brown" end it "can remove more than one property" do new_node = @neo.create_node("weight" => 200, "eyes" => "brown", "height" => "2m") - new_node[:id] = new_node["self"].split('/').last - @neo.remove_node_properties(new_node[:id], ["weight", "eyes"]) - node_properties = @neo.get_node_properties(new_node[:id]) + @neo.remove_node_properties(new_node, ["weight", "eyes"]) + node_properties = @neo.get_node_properties(new_node) node_properties["weight"].should be_nil node_properties["eyes"].should be_nil end @@ -161,39 +152,35 @@ describe "delete_node" do it "can delete an unrelated node" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.delete_node(new_node[:id]).should be_nil - existing_node = @neo.get_node(new_node[:id]) + @neo.delete_node(new_node).should be_nil + existing_node = @neo.get_node(new_node) existing_node.should be_nil end it "cannot delete a node that has relationships" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - @neo.delete_node(new_node1[:id]).should be_nil - existing_node = @neo.get_node(new_node1[:id]) + @neo.create_relationship("friends", new_node1, new_node2) + @neo.delete_node(new_node1).should be_nil + existing_node = @neo.get_node(new_node1) existing_node.should_not be_nil end it "returns nil if it tries to delete a node that does not exist" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.delete_node(new_node[:id].to_i + 1000).should be_nil - existing_node = @neo.get_node(new_node[:id].to_i + 1000) + fake_node = new_node["self"].split('/').last.to_i + 1000 + @neo.delete_node(fake_node).should be_nil + existing_node = @neo.get_node(fake_node) existing_node.should be_nil end it "returns nil if it tries to delete a node that has already been deleted" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.delete_node(new_node[:id]).should be_nil - existing_node = @neo.get_node(new_node[:id]) + @neo.delete_node(new_node).should be_nil + existing_node = @neo.get_node(new_node) existing_node.should be_nil - @neo.delete_node(new_node[:id]).should be_nil - existing_node = @neo.get_node(new_node[:id]) + @neo.delete_node(new_node).should be_nil + existing_node = @neo.get_node(new_node) existing_node.should be_nil end end @@ -201,39 +188,35 @@ describe "delete_node!" do it "can delete an unrelated node" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.delete_node!(new_node[:id]).should be_nil - existing_node = @neo.get_node(new_node[:id]) + @neo.delete_node!(new_node).should be_nil + existing_node = @neo.get_node(new_node) existing_node.should be_nil end it "can delete a node that has relationships" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - @neo.delete_node!(new_node1[:id]).should be_nil - existing_node = @neo.get_node(new_node1[:id]) + @neo.create_relationship("friends", new_node1, new_node2) + @neo.delete_node!(new_node1).should be_nil + existing_node = @neo.get_node(new_node1) existing_node.should be_nil end it "returns nil if it tries to delete a node that does not exist" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.delete_node!(new_node[:id].to_i + 1000).should be_nil - existing_node = @neo.get_node(new_node[:id].to_i + 1000) + fake_node = new_node["self"].split('/').last.to_i + 1000 + @neo.delete_node!(fake_node).should be_nil + existing_node = @neo.get_node(fake_node) existing_node.should be_nil end it "returns nil if it tries to delete a node that has already been deleted" do new_node = @neo.create_node - new_node[:id] = new_node["self"].split('/').last - @neo.delete_node!(new_node[:id]).should be_nil - existing_node = @neo.get_node(new_node[:id]) + @neo.delete_node!(new_node).should be_nil + existing_node = @neo.get_node(new_node) existing_node.should be_nil - @neo.delete_node!(new_node[:id]).should be_nil - existing_node = @neo.get_node(new_node[:id]) + @neo.delete_node!(new_node).should be_nil + existing_node = @neo.get_node(new_node) existing_node.should be_nil end end diff --git a/spec/integration/rest_path_spec.rb b/spec/integration/rest_path_spec.rb index b392455..6c83323 100644 --- a/spec/integration/rest_path_spec.rb +++ b/spec/integration/rest_path_spec.rb @@ -8,11 +8,9 @@ describe "get path" do it "can get a path between two nodes" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"}) - path = @neo.get_path(new_node1[:id], new_node2[:id], {"type"=> "friends", "direction" => "out"}) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"}) + path = @neo.get_path(new_node1, new_node2, {"type"=> "friends", "direction" => "out"}) path["start"].should == new_node1["self"] path["end"].should == new_node2["self"] path["nodes"].should == [new_node1["self"], new_node2["self"]] @@ -20,21 +18,16 @@ it "can get the shortest path between two nodes" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - @neo.create_relationship("friends", new_node2[:id], new_node3[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - path = @neo.get_path(new_node1[:id], new_node5[:id], {"type"=> "friends", "direction" => "out"}, depth=3, algorithm="shortestPath") + @neo.create_relationship("friends", new_node1, new_node2) + @neo.create_relationship("friends", new_node2, new_node3) + @neo.create_relationship("friends", new_node3, new_node4) + @neo.create_relationship("friends", new_node4, new_node5) + @neo.create_relationship("friends", new_node3, new_node5) + path = @neo.get_path(new_node1, new_node5, {"type"=> "friends", "direction" => "out"}, depth=3, algorithm="shortestPath") path["start"].should == new_node1["self"] path["end"].should == new_node5["self"] path["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"], new_node5["self"]] @@ -42,21 +35,16 @@ it "can get a simple path between two nodes" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - @neo.create_relationship("friends", new_node2[:id], new_node3[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - path = @neo.get_path(new_node1[:id], new_node5[:id], {"type"=> "friends", "direction" => "out"}, depth=3, algorithm="simplePaths") + @neo.create_relationship("friends", new_node1, new_node2) + @neo.create_relationship("friends", new_node2, new_node3) + @neo.create_relationship("friends", new_node3, new_node4) + @neo.create_relationship("friends", new_node4, new_node5) + @neo.create_relationship("friends", new_node3, new_node5) + path = @neo.get_path(new_node1, new_node5, {"type"=> "friends", "direction" => "out"}, depth=3, algorithm="simplePaths") path["start"].should == new_node1["self"] path["end"].should == new_node5["self"] path["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"], new_node5["self"]] @@ -64,43 +52,33 @@ it "fails to get a path between two nodes 3 nodes apart when using max depth of 2" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - @neo.create_relationship("friends", new_node2[:id], new_node3[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - path = @neo.get_path(new_node1[:id], new_node5[:id], {"type"=> "friends", "direction" => "out"}, depth=2, algorithm="shortestPath") + @neo.create_relationship("friends", new_node1, new_node2) + @neo.create_relationship("friends", new_node2, new_node3) + @neo.create_relationship("friends", new_node3, new_node4) + @neo.create_relationship("friends", new_node4, new_node5) + @neo.create_relationship("friends", new_node3, new_node5) + path = @neo.get_path(new_node1, new_node5, {"type"=> "friends", "direction" => "out"}, depth=2, algorithm="shortestPath") path["start"].should be_nil path["end"].should be_nil end it "can get a path between two nodes of a specific relationship" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - @neo.create_relationship("classmates", new_node1[:id], new_node2[:id]) - @neo.create_relationship("classmates", new_node2[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - @neo.create_relationship("friends", new_node2[:id], new_node3[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - path = @neo.get_path(new_node1[:id], new_node5[:id], {"type"=> "friends", "direction" => "out"}, depth=4, algorithm="shortestPath") + @neo.create_relationship("classmates", new_node1, new_node2) + @neo.create_relationship("classmates", new_node2, new_node5) + @neo.create_relationship("friends", new_node1, new_node2) + @neo.create_relationship("friends", new_node2, new_node3) + @neo.create_relationship("friends", new_node3, new_node4) + @neo.create_relationship("friends", new_node4, new_node5) + path = @neo.get_path(new_node1, new_node5, {"type"=> "friends", "direction" => "out"}, depth=4, algorithm="shortestPath") path["start"].should == new_node1["self"] path["end"].should == new_node5["self"] path["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"], new_node4["self"], new_node5["self"]] @@ -110,22 +88,17 @@ describe "get paths" do it "can get the shortest paths between two nodes" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - @neo.create_relationship("friends", new_node2[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node1[:id], new_node3[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - paths = @neo.get_paths(new_node1[:id], new_node5[:id], {"type"=> "friends", "direction" => "out"}, depth=4, algorithm="shortestPath") + @neo.create_relationship("friends", new_node1, new_node2) + @neo.create_relationship("friends", new_node2, new_node5) + @neo.create_relationship("friends", new_node1, new_node3) + @neo.create_relationship("friends", new_node3, new_node4) + @neo.create_relationship("friends", new_node4, new_node5) + @neo.create_relationship("friends", new_node3, new_node5) + paths = @neo.get_paths(new_node1, new_node5, {"type"=> "friends", "direction" => "out"}, depth=4, algorithm="shortestPath") paths.length.should == 2 paths[0]["length"].should == 2 paths[0]["start"].should == new_node1["self"] @@ -137,22 +110,17 @@ it "can get all paths between two nodes" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - @neo.create_relationship("friends", new_node2[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node1[:id], new_node3[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - paths = @neo.get_paths(new_node1[:id], new_node5[:id], {"type"=> "friends", "direction" => "out"}, depth=4, algorithm="allPaths") + @neo.create_relationship("friends", new_node1, new_node2) + @neo.create_relationship("friends", new_node2, new_node5) + @neo.create_relationship("friends", new_node1, new_node3) + @neo.create_relationship("friends", new_node3, new_node4) + @neo.create_relationship("friends", new_node4, new_node5) + @neo.create_relationship("friends", new_node3, new_node5) + paths = @neo.get_paths(new_node1, new_node5, {"type"=> "friends", "direction" => "out"}, depth=4, algorithm="allPaths") paths.length.should == 3 paths[0]["length"].should == 2 paths[0]["start"].should == new_node1["self"] @@ -167,23 +135,18 @@ it "can get all simple paths between two nodes" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - @neo.create_relationship("friends", new_node2[:id], new_node1[:id]) - @neo.create_relationship("friends", new_node2[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node1[:id], new_node3[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - paths = @neo.get_paths(new_node1[:id], new_node5[:id], {"type"=> "friends", "direction" => "out"}, depth=4, algorithm="allSimplePaths") + @neo.create_relationship("friends", new_node1, new_node2) + @neo.create_relationship("friends", new_node2, new_node1) + @neo.create_relationship("friends", new_node2, new_node5) + @neo.create_relationship("friends", new_node1, new_node3) + @neo.create_relationship("friends", new_node3, new_node4) + @neo.create_relationship("friends", new_node4, new_node5) + @neo.create_relationship("friends", new_node3, new_node5) + paths = @neo.get_paths(new_node1, new_node5, {"type"=> "friends", "direction" => "out"}, depth=4, algorithm="allSimplePaths") paths.length.should == 3 paths[0]["length"].should == 2 paths[0]["start"].should == new_node1["self"] @@ -198,22 +161,17 @@ it "can get paths between two nodes of max depth 2" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - @neo.create_relationship("friends", new_node2[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node1[:id], new_node3[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - paths = @neo.get_paths(new_node1[:id], new_node5[:id], {"type"=> "friends", "direction" => "out"}, depth=2, algorithm="allPaths") + @neo.create_relationship("friends", new_node1, new_node2) + @neo.create_relationship("friends", new_node2, new_node5) + @neo.create_relationship("friends", new_node1, new_node3) + @neo.create_relationship("friends", new_node3, new_node4) + @neo.create_relationship("friends", new_node4, new_node5) + @neo.create_relationship("friends", new_node3, new_node5) + paths = @neo.get_paths(new_node1, new_node5, {"type"=> "friends", "direction" => "out"}, depth=2, algorithm="allPaths") paths.length.should == 2 paths[0]["length"].should == 2 paths[0]["start"].should == new_node1["self"] @@ -224,24 +182,19 @@ it "can get paths between two nodes of a specific relationship" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - @neo.create_relationship("classmates", new_node1[:id], new_node2[:id]) - @neo.create_relationship("classmates", new_node2[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - @neo.create_relationship("friends", new_node2[:id], new_node3[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - @neo.create_relationship("classmates", new_node1[:id], new_node3[:id]) - @neo.create_relationship("classmates", new_node3[:id], new_node5[:id]) - paths = @neo.get_paths(new_node1[:id], new_node5[:id], {"type"=> "classmates", "direction" => "out"}, depth=4, algorithm="allPaths") + @neo.create_relationship("classmates", new_node1, new_node2) + @neo.create_relationship("classmates", new_node2, new_node5) + @neo.create_relationship("friends", new_node1, new_node2) + @neo.create_relationship("friends", new_node2, new_node3) + @neo.create_relationship("friends", new_node3, new_node4) + @neo.create_relationship("friends", new_node4, new_node5) + @neo.create_relationship("classmates", new_node1, new_node3) + @neo.create_relationship("classmates", new_node3, new_node5) + paths = @neo.get_paths(new_node1, new_node5, {"type"=> "classmates", "direction" => "out"}, depth=4, algorithm="allPaths") paths[0]["length"].should == 2 paths[0]["start"].should == new_node1["self"] paths[0]["end"].should == new_node5["self"] diff --git a/spec/integration/rest_relationship_spec.rb b/spec/integration/rest_relationship_spec.rb index 08bbf63..0792962 100644 --- a/spec/integration/rest_relationship_spec.rb +++ b/spec/integration/rest_relationship_spec.rb @@ -8,10 +8,8 @@ describe "create_relationship" do it "can create an empty relationship" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2) new_relationship["start"].should_not be_nil new_relationship["end"].should_not be_nil end @@ -21,16 +19,14 @@ new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010'}) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010'}) new_relationship["data"]["since"].should == '10-1-2010' end it "can create a relationship with more than one property" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"}) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"}) new_relationship["data"]["since"].should == '10-1-2010' new_relationship["data"]["met"].should == "college" end @@ -39,14 +35,11 @@ describe "set_relationship_properties" do it "can set a relationship's properties" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - new_relationship[:id] = new_relationship["self"].split('/').last - @neo.set_relationship_properties(new_relationship[:id], {"since" => '10-1-2010', "met" => "college"}) - @neo.set_relationship_properties(new_relationship[:id], {"roommates" => "no"}) - relationship_properties = @neo.get_relationship_properties(new_relationship[:id]) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2) + @neo.set_relationship_properties(new_relationship, {"since" => '10-1-2010', "met" => "college"}) + @neo.set_relationship_properties(new_relationship, {"roommates" => "no"}) + relationship_properties = @neo.get_relationship_properties(new_relationship) relationship_properties["since"].should == '10-1-2010' relationship_properties["met"].should == "college" relationship_properties["roommates"].should == "no" @@ -54,13 +47,11 @@ it "it fails to set properties on a relationship that does not exist" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - new_relationship[:id] = new_relationship["self"].split('/').last - @neo.set_relationship_properties(new_relationship[:id].to_i + 10000, {"since" => '10-1-2010', "met" => "college"}) - relationship_properties = @neo.get_relationship_properties(new_relationship[:id].to_i + 10000) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2) + fake_relationship = new_relationship["self"].split('/').last.to_i + 1000 + @neo.set_relationship_properties(fake_relationship, {"since" => '10-1-2010', "met" => "college"}) + relationship_properties = @neo.get_relationship_properties(fake_relationship) relationship_properties.should be_nil end end @@ -68,14 +59,11 @@ describe "reset_relationship_properties" do it "can reset a relationship's properties" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - new_relationship[:id] = new_relationship["self"].split('/').last - @neo.set_relationship_properties(new_relationship[:id], {"since" => '10-1-2010', "met" => "college"}) - @neo.reset_relationship_properties(new_relationship[:id], {"roommates" => "no"}) - relationship_properties = @neo.get_relationship_properties(new_relationship[:id]) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2) + @neo.set_relationship_properties(new_relationship, {"since" => '10-1-2010', "met" => "college"}) + @neo.reset_relationship_properties(new_relationship, {"roommates" => "no"}) + relationship_properties = @neo.get_relationship_properties(new_relationship) relationship_properties["since"].should be_nil relationship_properties["met"].should be_nil relationship_properties["roommates"].should == "no" @@ -83,13 +71,11 @@ it "it fails to reset properties on a relationship that does not exist" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - new_relationship[:id] = new_relationship["self"].split('/').last - @neo.reset_relationship_properties(new_relationship[:id].to_i + 10000, {"since" => '10-1-2010', "met" => "college"}) - relationship_properties = @neo.get_relationship_properties(new_relationship[:id].to_i + 10000) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2) + fake_relationship = new_relationship["self"].split('/').last.to_i + 1000 + @neo.reset_relationship_properties(fake_relationship, {"since" => '10-1-2010', "met" => "college"}) + relationship_properties = @neo.get_relationship_properties(fake_relationship) relationship_properties.should be_nil end end @@ -97,24 +83,18 @@ describe "get_relationship_properties" do it "can get all of a relationship's properties" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"}) - new_relationship[:id] = new_relationship["self"].split('/').last - relationship_properties = @neo.get_relationship_properties(new_relationship[:id]) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"}) + relationship_properties = @neo.get_relationship_properties(new_relationship) relationship_properties["since"].should == '10-1-2010' relationship_properties["met"].should == "college" end it "can get some of a relationship's properties" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college", "roommates" => "no"}) - new_relationship[:id] = new_relationship["self"].split('/').last - relationship_properties = @neo.get_relationship_properties(new_relationship[:id], ["since", "roommates"]) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college", "roommates" => "no"}) + relationship_properties = @neo.get_relationship_properties(new_relationship, ["since", "roommates"]) relationship_properties["since"].should == '10-1-2010' relationship_properties["met"].should be_nil relationship_properties["roommates"].should == "no" @@ -122,34 +102,26 @@ it "returns nil if it gets the properties on a relationship that does not have any" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - new_relationship[:id] = new_relationship["self"].split('/').last - relationship_properties = @neo.get_relationship_properties(new_relationship[:id]) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2) + relationship_properties = @neo.get_relationship_properties(new_relationship) relationship_properties.should be_nil end it "returns nil if it tries to get some of the properties on a relationship that does not have any" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - new_relationship[:id] = new_relationship["self"].split('/').last - relationship_properties = @neo.get_relationship_properties(new_relationship[:id], ["since", "roommates"]) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2) + relationship_properties = @neo.get_relationship_properties(new_relationship, ["since", "roommates"]) relationship_properties.should be_nil end it "returns nil if it fails to get properties on a relationship that does not exist" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - new_relationship[:id] = new_relationship["self"].split('/').last - relationship_properties = @neo.get_relationship_properties(new_relationship[:id].to_i + 10000) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2) + fake_relationship = new_relationship["self"].split('/').last.to_i + 1000 + relationship_properties = @neo.get_relationship_properties(fake_relationship) relationship_properties.should be_nil end end @@ -157,48 +129,37 @@ describe "remove_relationship_properties" do it "can remove a relationship's properties" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"}) - new_relationship[:id] = new_relationship["self"].split('/').last - @neo.remove_relationship_properties(new_relationship[:id]) - @neo.get_relationship_properties(new_relationship[:id]).should be_nil + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"}) + @neo.remove_relationship_properties(new_relationship) + @neo.get_relationship_properties(new_relationship).should be_nil end it "returns nil if it fails to remove the properties of a relationship that does not exist" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"}) - new_relationship[:id] = new_relationship["self"].split('/').last - @neo.remove_relationship_properties(new_relationship[:id]) - @neo.get_relationship_properties(new_relationship[:id].to_i + 10000).should be_nil + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"}) + fake_relationship = new_relationship["self"].split('/').last.to_i + 1000 + @neo.remove_relationship_properties(fake_relationship).should be_nil + @neo.get_relationship_properties(fake_relationship).should be_nil end it "can remove a specific relationship property" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"}) - new_relationship[:id] = new_relationship["self"].split('/').last - @neo.remove_relationship_properties(new_relationship[:id], "met") - relationship_properties = @neo.get_relationship_properties(new_relationship[:id], ["met", "since"]) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"}) + @neo.remove_relationship_properties(new_relationship, "met") + relationship_properties = @neo.get_relationship_properties(new_relationship, ["met", "since"]) relationship_properties["met"].should be_nil relationship_properties["since"].should == '10-1-2010' end it "can remove more than one relationship property" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college", "roommates" => "no"}) - new_relationship[:id] = new_relationship["self"].split('/').last - @neo.remove_relationship_properties(new_relationship[:id], ["met", "since"]) - relationship_properties = @neo.get_relationship_properties(new_relationship[:id], ["since", "met", "roommates"]) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college", "roommates" => "no"}) + @neo.remove_relationship_properties(new_relationship, ["met", "since"]) + relationship_properties = @neo.get_relationship_properties(new_relationship, ["since", "met", "roommates"]) relationship_properties["met"].should be_nil relationship_properties["since"].should be_nil relationship_properties["roommates"].should == "no" @@ -208,37 +169,29 @@ describe "delete_relationship" do it "can delete an existing relationship" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"}) - new_relationship[:id] = new_relationship["self"].split('/').last - @neo.delete_relationship(new_relationship[:id]) - relationships = @neo.get_node_relationships(new_node1[:id]) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"}) + @neo.delete_relationship(new_relationship) + relationships = @neo.get_node_relationships(new_node1) relationships.should be_nil end it "returns nil if it tries to delete a relationship that does not exist" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"}) - new_relationship[:id] = new_relationship["self"].split('/').last - existing_relationship = @neo.delete_relationship(new_relationship[:id].to_i + 1000) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"}) + fake_relationship = new_relationship["self"].split('/').last.to_i + 1000 + existing_relationship = @neo.delete_relationship(fake_relationship) existing_relationship.should be_nil end it "returns nil if it tries to delete a relationship that has already been deleted" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2010', "met" => "college"}) - new_relationship[:id] = new_relationship["self"].split('/').last - existing_relationship = @neo.delete_relationship(new_relationship[:id]) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2010', "met" => "college"}) + existing_relationship = @neo.delete_relationship(new_relationship) existing_relationship.should be_nil - existing_relationship = @neo.delete_relationship(new_relationship[:id]) + existing_relationship = @neo.delete_relationship(new_relationship) existing_relationship.should be_nil end end @@ -246,14 +199,12 @@ describe "get_node_relationships" do it "can get a node's relationship" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"}) - relationships = @neo.get_node_relationships(new_node1[:id]) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"}) + relationships = @neo.get_node_relationships(new_node1) relationships.should_not be_nil - relationships[0]["start"].split('/').last.should == new_node1[:id] - relationships[0]["end"].split('/').last.should == new_node2[:id] + relationships[0]["start"].should == new_node1["self"] + relationships[0]["end"].should == new_node2["self"] relationships[0]["type"].should == "friends" relationships[0]["data"]["met"].should == "college" relationships[0]["data"]["since"].should == '10-1-2005' @@ -261,22 +212,19 @@ it "can get a node's multiple relationships" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"}) - new_relationship = @neo.create_relationship("enemies", new_node1[:id], new_node3[:id], {"since" => '10-2-2010', "met" => "work"}) - relationships = @neo.get_node_relationships(new_node1[:id]) + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"}) + new_relationship = @neo.create_relationship("enemies", new_node1, new_node3, {"since" => '10-2-2010', "met" => "work"}) + relationships = @neo.get_node_relationships(new_node1) relationships.should_not be_nil - relationships[0]["start"].split('/').last.should == new_node1[:id] - relationships[0]["end"].split('/').last.should == new_node2[:id] + relationships[0]["start"].should == new_node1["self"] + relationships[0]["end"].should == new_node2["self"] relationships[0]["type"].should == "friends" relationships[0]["data"]["met"].should == "college" relationships[0]["data"]["since"].should == '10-1-2005' - relationships[1]["start"].split('/').last.should == new_node1[:id] - relationships[1]["end"].split('/').last.should == new_node3[:id] + relationships[1]["start"].should == new_node1["self"] + relationships[1]["end"].should == new_node3["self"] relationships[1]["type"].should == "enemies" relationships[1]["data"]["met"].should == "work" relationships[1]["data"]["since"].should == '10-2-2010' @@ -284,17 +232,14 @@ it "can get a node's outgoing relationship" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"}) - new_relationship = @neo.create_relationship("enemies", new_node3[:id], new_node1[:id], {"since" => '10-2-2010', "met" => "work"}) - relationships = @neo.get_node_relationships(new_node1[:id], "out") + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"}) + new_relationship = @neo.create_relationship("enemies", new_node3, new_node1, {"since" => '10-2-2010', "met" => "work"}) + relationships = @neo.get_node_relationships(new_node1, "out") relationships.should_not be_nil - relationships[0]["start"].split('/').last.should == new_node1[:id] - relationships[0]["end"].split('/').last.should == new_node2[:id] + relationships[0]["start"].should == new_node1["self"] + relationships[0]["end"].should == new_node2["self"] relationships[0]["type"].should == "friends" relationships[0]["data"]["met"].should == "college" relationships[0]["data"]["since"].should == '10-1-2005' @@ -303,17 +248,14 @@ it "can get a node's incoming relationship" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"}) - new_relationship = @neo.create_relationship("enemies", new_node3[:id], new_node1[:id], {"since" => '10-2-2010', "met" => "work"}) - relationships = @neo.get_node_relationships(new_node1[:id], "in") + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"}) + new_relationship = @neo.create_relationship("enemies", new_node3, new_node1, {"since" => '10-2-2010', "met" => "work"}) + relationships = @neo.get_node_relationships(new_node1, "in") relationships.should_not be_nil - relationships[0]["start"].split('/').last.should == new_node3[:id] - relationships[0]["end"].split('/').last.should == new_node1[:id] + relationships[0]["start"].should == new_node3["self"] + relationships[0]["end"].should == new_node1["self"] relationships[0]["type"].should == "enemies" relationships[0]["data"]["met"].should == "work" relationships[0]["data"]["since"].should == '10-2-2010' @@ -322,17 +264,14 @@ it "can get a specific type of node relationships" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"}) - new_relationship = @neo.create_relationship("enemies", new_node1[:id], new_node3[:id], {"since" => '10-2-2010', "met" => "work"}) - relationships = @neo.get_node_relationships(new_node1[:id], "all", "friends") + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"}) + new_relationship = @neo.create_relationship("enemies", new_node1, new_node3, {"since" => '10-2-2010', "met" => "work"}) + relationships = @neo.get_node_relationships(new_node1, "all", "friends") relationships.should_not be_nil - relationships[0]["start"].split('/').last.should == new_node1[:id] - relationships[0]["end"].split('/').last.should == new_node2[:id] + relationships[0]["start"].should == new_node1["self"] + relationships[0]["end"].should == new_node2["self"] relationships[0]["type"].should == "friends" relationships[0]["data"]["met"].should == "college" relationships[0]["data"]["since"].should == '10-1-2005' @@ -341,20 +280,16 @@ it "can get a specific type and direction of a node relationships" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last - new_relationship = @neo.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"}) - new_relationship = @neo.create_relationship("enemies", new_node1[:id], new_node3[:id], {"since" => '10-2-2010', "met" => "work"}) - new_relationship = @neo.create_relationship("enemies", new_node4[:id], new_node1[:id], {"since" => '10-3-2010', "met" => "gym"}) - relationships = @neo.get_node_relationships(new_node1[:id], "in", "enemies") + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"since" => '10-1-2005', "met" => "college"}) + new_relationship = @neo.create_relationship("enemies", new_node1, new_node3, {"since" => '10-2-2010', "met" => "work"}) + new_relationship = @neo.create_relationship("enemies", new_node4, new_node1, {"since" => '10-3-2010', "met" => "gym"}) + relationships = @neo.get_node_relationships(new_node1, "in", "enemies") relationships.should_not be_nil - relationships[0]["start"].split('/').last.should == new_node4[:id] - relationships[0]["end"].split('/').last.should == new_node1[:id] + relationships[0]["start"].should == new_node4["self"] + relationships[0]["end"].should == new_node1["self"] relationships[0]["type"].should == "enemies" relationships[0]["data"]["met"].should == "gym" relationships[0]["data"]["since"].should == '10-3-2010' @@ -363,8 +298,7 @@ it "returns nil if there are no relationships" do new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last - relationships = @neo.get_node_relationships(new_node1[:id]) + relationships = @neo.get_node_relationships(new_node1) relationships.should be_nil end end diff --git a/spec/integration/rest_traverse_spec.rb b/spec/integration/rest_traverse_spec.rb index f915891..c2dc875 100644 --- a/spec/integration/rest_traverse_spec.rb +++ b/spec/integration/rest_traverse_spec.rb @@ -3,52 +3,35 @@ describe Neography::Rest do before(:each) do @neo = Neography::Rest.new + @new_node1 = @neo.create_node("age" => 31, "name" => "Max") + @new_node2 = @neo.create_node("age" => 30, "name" => "Helene") + @new_node3 = @neo.create_node("age" => 17, "name" => "Alex") + @new_node4 = @neo.create_node("age" => 24, "name" => "Eric") + @new_node5 = @neo.create_node("age" => 32, "name" => "Leslie") end describe "traverse" do it "can traverse the graph and return nodes" do - new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last - new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last - new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last - new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - @neo.create_relationship("friends", new_node2[:id], new_node3[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - nodes = @neo.traverse(new_node1[:id], "nodes", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} ) + @neo.create_relationship("friends", @new_node1, @new_node2) + @neo.create_relationship("friends", @new_node2, @new_node3) + @neo.create_relationship("friends", @new_node3, @new_node4) + @neo.create_relationship("friends", @new_node4, @new_node5) + @neo.create_relationship("friends", @new_node3, @new_node5) + nodes = @neo.traverse(@new_node1, "nodes", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} ) nodes.should_not be_nil - nodes[0]["self"].should == new_node2["self"] - nodes[1]["self"].should == new_node3["self"] - nodes[2]["self"].should == new_node4["self"] - nodes[3]["self"].should == new_node5["self"] + nodes[0]["self"].should == @new_node2["self"] + nodes[1]["self"].should == @new_node3["self"] + nodes[2]["self"].should == @new_node4["self"] + nodes[3]["self"].should == @new_node5["self"] end - it "can traverse the graph and return relationships" do - new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last - new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last - new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last - new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - - new_relationship1= @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - new_relationship2= @neo.create_relationship("friends", new_node2[:id], new_node3[:id]) - new_relationship3= @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - new_relationship4= @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - new_relationship5= @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - - relationships = @neo.traverse(new_node1[:id], "relationships", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} ) + new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2) + new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3) + new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4) + new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5) + new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5) + + relationships = @neo.traverse(@new_node1, "relationships", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} ) relationships.should_not be_nil relationships[0]["self"].should == new_relationship1["self"] @@ -58,173 +41,109 @@ end it "can traverse the graph and return paths" do - new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last - new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last - new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last - new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - - new_relationship1= @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - new_relationship2= @neo.create_relationship("friends", new_node2[:id], new_node3[:id]) - new_relationship3= @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - new_relationship4= @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - new_relationship5= @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - - paths = @neo.traverse(new_node1[:id], "paths", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} ) + new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2) + new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3) + new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4) + new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5) + new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5) + + paths = @neo.traverse(@new_node1, "paths", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} ) paths.should_not be_nil - paths[0]["nodes"].should == [new_node1["self"], new_node2["self"]] - paths[1]["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"]] - paths[2]["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"], new_node4["self"]] - paths[3]["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"], new_node4["self"], new_node5["self"]] + paths[0]["nodes"].should == [@new_node1["self"], @new_node2["self"]] + paths[1]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"]] + paths[2]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"]] + paths[3]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"], @new_node5["self"]] end it "can traverse the graph up to a certain depth" do - new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last - new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last - new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last - new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - - new_relationship1= @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - new_relationship2= @neo.create_relationship("friends", new_node2[:id], new_node3[:id]) - new_relationship3= @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - new_relationship4= @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - new_relationship5= @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - - paths = @neo.traverse(new_node1[:id], "paths", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 3} ) + new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2) + new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3) + new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4) + new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5) + new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5) + + paths = @neo.traverse(@new_node1, "paths", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 3} ) paths.should_not be_nil - paths[0]["nodes"].should == [new_node1["self"], new_node2["self"]] - paths[1]["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"]] - paths[2]["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"], new_node4["self"]] - paths[3]["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"], new_node5["self"]] + paths[0]["nodes"].should == [@new_node1["self"], @new_node2["self"]] + paths[1]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"]] + paths[2]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"]] + paths[3]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node5["self"]] end it "can traverse the graph in a certain order" do - new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last - new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last - new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last - new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - - new_relationship1= @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - new_relationship2= @neo.create_relationship("friends", new_node2[:id], new_node3[:id]) - new_relationship3= @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - new_relationship4= @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - new_relationship5= @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - - paths = @neo.traverse(new_node1[:id], "paths", {"order" => "breadth first", "relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} ) + new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2) + new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3) + new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4) + new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5) + new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5) + + paths = @neo.traverse(@new_node1, "paths", {"order" => "breadth first", "relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 4} ) paths.should_not be_nil - paths[0]["nodes"].should == [new_node1["self"], new_node2["self"]] - paths[1]["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"]] - paths[2]["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"], new_node4["self"]] - paths[3]["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"], new_node5["self"]] + paths[0]["nodes"].should == [@new_node1["self"], @new_node2["self"]] + paths[1]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"]] + paths[2]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"]] + paths[3]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node5["self"]] end it "can traverse the graph with a specific uniqueness" do - new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last - new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last - new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last - new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - - new_relationship1= @neo.create_relationship("roommates", new_node1[:id], new_node2[:id]) - new_relationship2= @neo.create_relationship("roommates", new_node2[:id], new_node3[:id]) - new_relationship1= @neo.create_relationship("friends", new_node3[:id], new_node2[:id]) - new_relationship2= @neo.create_relationship("friends", new_node2[:id], new_node5[:id]) - new_relationship3= @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - new_relationship4= @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - new_relationship5= @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - - paths = @neo.traverse(new_node1[:id], "paths", {"order" => "breadth first", "uniqueness" => "node global", "relationships" => [{"type"=> "roommates", "direction" => "all"},{"type"=> "friends", "direction" => "out"}], "depth" => 4} ) + new_relationship1= @neo.create_relationship("roommates", @new_node1, @new_node2) + new_relationship2= @neo.create_relationship("roommates", @new_node2, @new_node3) + new_relationship1= @neo.create_relationship("friends", @new_node3, @new_node2) + new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node5) + new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4) + new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5) + new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5) + + paths = @neo.traverse(@new_node1, "paths", {"order" => "breadth first", "uniqueness" => "node global", "relationships" => [{"type"=> "roommates", "direction" => "all"},{"type"=> "friends", "direction" => "out"}], "depth" => 4} ) paths.should_not be_nil - paths[0]["nodes"].should == [new_node1["self"], new_node2["self"]] - paths[1]["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"]] - paths[2]["nodes"].should == [new_node1["self"], new_node2["self"], new_node5["self"]] - paths[3]["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"], new_node4["self"]] + paths[0]["nodes"].should == [@new_node1["self"], @new_node2["self"]] + paths[1]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"]] + paths[2]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node5["self"]] + paths[3]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"], @new_node4["self"]] end it "can traverse the graph with a prune evaluator" do - new_node1 = @neo.create_node("age" => 31, "name" => "Max") - new_node1[:id] = new_node1["self"].split('/').last - new_node2 = @neo.create_node("age" => 30, "name" => "Helene") - new_node2[:id] = new_node2["self"].split('/').last - new_node3 = @neo.create_node("age" => 17, "name" => "Alex") - new_node3[:id] = new_node3["self"].split('/').last - new_node4 = @neo.create_node("age" => 24, "name" => "Eric") - new_node4[:id] = new_node4["self"].split('/').last - new_node5 = @neo.create_node("age" => 32, "name" => "Leslie") - new_node5[:id] = new_node5["self"].split('/').last - - new_relationship1= @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - new_relationship2= @neo.create_relationship("friends", new_node2[:id], new_node3[:id]) - new_relationship3= @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - new_relationship4= @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - new_relationship5= @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - - paths = @neo.traverse(new_node1[:id], + new_relationship1= @neo.create_relationship("friends", @new_node1, @new_node2) + new_relationship2= @neo.create_relationship("friends", @new_node2, @new_node3) + new_relationship3= @neo.create_relationship("friends", @new_node3, @new_node4) + new_relationship4= @neo.create_relationship("friends", @new_node4, @new_node5) + new_relationship5= @neo.create_relationship("friends", @new_node3, @new_node5) + + paths = @neo.traverse(@new_node1, "paths", {"relationships" => {"type"=> "friends", "direction" => "out"}, "depth" => 3, "prune evaluator" => {"language" => "javascript", "body" => "position.endNode().getProperty('age') < 21;" }} ) paths.should_not be_nil - paths[0]["nodes"].should == [new_node1["self"], new_node2["self"]] - paths[1]["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"]] + paths[0]["nodes"].should == [@new_node1["self"], @new_node2["self"]] + paths[1]["nodes"].should == [@new_node1["self"], @new_node2["self"], @new_node3["self"]] paths[2].should be_nil end it "can traverse the graph with a return filter" do - new_node1 = @neo.create_node - new_node1[:id] = new_node1["self"].split('/').last - new_node2 = @neo.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_node3 = @neo.create_node - new_node3[:id] = new_node3["self"].split('/').last - new_node4 = @neo.create_node - new_node4[:id] = new_node4["self"].split('/').last - new_node5 = @neo.create_node - new_node5[:id] = new_node5["self"].split('/').last - @neo.create_relationship("friends", new_node1[:id], new_node2[:id]) - @neo.create_relationship("friends", new_node2[:id], new_node3[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node4[:id]) - @neo.create_relationship("friends", new_node4[:id], new_node5[:id]) - @neo.create_relationship("friends", new_node3[:id], new_node5[:id]) - nodes = @neo.traverse(new_node1[:id], "nodes", {"relationships" => {"type"=> "friends", "direction" => "out"}, + @neo.create_relationship("friends", @new_node1, @new_node2) + @neo.create_relationship("friends", @new_node2, @new_node3) + @neo.create_relationship("friends", @new_node3, @new_node4) + @neo.create_relationship("friends", @new_node4, @new_node5) + @neo.create_relationship("friends", @new_node3, @new_node5) + nodes = @neo.traverse(@new_node1, "nodes", {"relationships" => {"type"=> "friends", "direction" => "out"}, "return filter" => {"language" => "builtin", "name" => "all"}, "depth" => 4} ) nodes.should_not be_nil - nodes[0]["self"].should == new_node1["self"] - nodes[1]["self"].should == new_node2["self"] - nodes[2]["self"].should == new_node3["self"] - nodes[3]["self"].should == new_node4["self"] - nodes[4]["self"].should == new_node5["self"] + nodes[0]["self"].should == @new_node1["self"] + nodes[1]["self"].should == @new_node2["self"] + nodes[2]["self"].should == @new_node3["self"] + nodes[3]["self"].should == @new_node4["self"] + nodes[4]["self"].should == @new_node5["self"] end + end end \ No newline at end of file