diff --git a/README.rdoc b/README.rdoc index 42e8fae..e0b024a 100644 --- a/README.rdoc +++ b/README.rdoc @@ -80,10 +80,10 @@ To Use: === To Do -Path tests -Traverse tests -@neo.traverse() -examples +* Traverse tests +* @neo.traverse() +* examples +* batch import with typhoeus ? === License diff --git a/lib/neography/config.rb b/lib/neography/config.rb deleted file mode 100644 index 64640ad..0000000 --- a/lib/neography/config.rb +++ /dev/null @@ -1,152 +0,0 @@ -module Neography - - # == Keeps configuration for neography - # - # The most important configuration options are Neograophy::Config[:server] and Neograophy::Config[:port] which are - # used to locate where the neo4j database and is stored on the network. - # If these options are not supplied then the default of localhost:9999 will be used. - # - # ==== Default Configurations - # :protocol:: default http:// protocol to use (can be https://) - # :server:: default localhost where the database is stored on the network - # :port:: default 7474 what port is listening - # - class Config - # This code is copied from merb-core/config.rb. - class << self - # Returns the hash of default config values for neography - # - # ==== Returns - # Hash:: The defaults for the config. - def defaults - @defaults ||= { - :protocol => 'http://', - :server => 'localhost', - :port => '7474' - } - end - - - # Yields the configuration. - # - # ==== Block parameters - # c :: The configuration parameters, a hash. - # - # ==== Examples - # Neography::Config.use do |config| - # config[:server] = '192.168.1.13' - # end - # - # ==== Returns - # nil - def use - @configuration ||= {} - yield @configuration - nil - end - - - # Set the value of a config entry. - # - # ==== Parameters - # key :: The key to set the parameter for. - # val :: The value of the parameter. - # - def []=(key, val) - (@configuration ||= setup)[key] = val - end - - - # Gets the the value of a config entry - # - # ==== Parameters - # key:: The key of the config entry value we want - # - def [](key) - (@configuration ||= setup)[key] - end - - - # Remove the value of a config entry. - # - # ==== Parameters - # key:: The key of the parameter to delete. - # - # ==== Returns - # The value of the removed entry. - # - def delete(key) - @configuration.delete(key) - end - - - # Remove all configuration. This can be useful for testing purpose. - # - # - # ==== Returns - # nil - # - def delete_all - @configuration = nil - end - - - # Retrieve the value of a config entry, returning the provided default if the key is not present - # - # ==== Parameters - # key:: The key to retrieve the parameter for. - # default::The default value to return if the parameter is not set. - # - # ==== Returns - # The value of the configuration parameter or the default. - # - def fetch(key, default) - @configuration.fetch(key, default) - end - - # Sets up the configuration - # - # ==== Returns - # The configuration as a hash. - # - def setup() - @configuration = {} - @configuration.merge!(defaults) - @configuration - end - - - # Returns the configuration as a hash. - # - # ==== Returns - # The config as a hash. - # - def to_hash - @configuration - end - - # Returns the config as YAML. - # - # ==== Returns - # The config as YAML. - # - def to_yaml - require "yaml" - @configuration.to_yaml - end - - # Returns the configuration as a string. - # - # ==== Returns - # The config as a string. - # - def to_s - setup - @configuration[:protocol] + @configuration[:server].to_s + ':' + @configuration[:port].to_s - end - - - end - end - -end \ No newline at end of file diff --git a/spec/integration/rest_path_spec.rb b/spec/integration/rest_path_spec.rb index 3957282..b392455 100644 --- a/spec/integration/rest_path_spec.rb +++ b/spec/integration/rest_path_spec.rb @@ -19,41 +19,235 @@ end it "can get the shortest path between two nodes" do - pending + 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") + 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"]] end it "can get a simple path between two nodes" do - pending + 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") + 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"]] end - it "can get a path between two nodes of max depth 3" do - pending + 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") + path["start"].should be_nil + path["end"].should be_nil end it "can get a path between two nodes of a specific relationship" do - pending + 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") + 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"]] end end describe "get paths" do it "can get the shortest paths between two nodes" do - pending + 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") + paths.length.should == 2 + paths[0]["length"].should == 2 + paths[0]["start"].should == new_node1["self"] + paths[0]["end"].should == new_node5["self"] + paths[1]["length"].should == 2 + paths[1]["start"].should == new_node1["self"] + paths[1]["end"].should == new_node5["self"] end it "can get all paths between two nodes" do - pending + 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") + paths.length.should == 3 + paths[0]["length"].should == 2 + paths[0]["start"].should == new_node1["self"] + paths[0]["end"].should == new_node5["self"] + paths[1]["length"].should == 3 + paths[1]["start"].should == new_node1["self"] + paths[1]["end"].should == new_node5["self"] + paths[2]["length"].should == 2 + paths[2]["start"].should == new_node1["self"] + paths[2]["end"].should == new_node5["self"] end it "can get all simple paths between two nodes" do - pending + 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") + paths.length.should == 3 + paths[0]["length"].should == 2 + paths[0]["start"].should == new_node1["self"] + paths[0]["end"].should == new_node5["self"] + paths[1]["length"].should == 3 + paths[1]["start"].should == new_node1["self"] + paths[1]["end"].should == new_node5["self"] + paths[2]["length"].should == 2 + paths[2]["start"].should == new_node1["self"] + paths[2]["end"].should == new_node5["self"] end - it "can get paths between two nodes of max depth 3" do - pending - end + 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") + paths.length.should == 2 + paths[0]["length"].should == 2 + paths[0]["start"].should == new_node1["self"] + paths[0]["end"].should == new_node5["self"] + paths[1]["length"].should == 2 + paths[1]["start"].should == new_node1["self"] + paths[1]["end"].should == new_node5["self"] end it "can get paths between two nodes of a specific relationship" do - pending + 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") + paths[0]["length"].should == 2 + paths[0]["start"].should == new_node1["self"] + paths[0]["end"].should == new_node5["self"] + paths[1]["length"].should == 2 + paths[1]["start"].should == new_node1["self"] + paths[1]["end"].should == new_node5["self"] end end