diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 0a36524..bc5fc75 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -1,40 +1,40 @@ module Neography class Rest include HTTParty - base_uri 'http://localhost:9999' + base_uri Neography::Config.to_s format :json class << self def get_root - rescue_ij { get('/') } + rescue_ij { get('/db/data/') } end def create_node(*args) if args[0].respond_to?(:each_pair) && args[0] options = { :body => args[0].to_json, :headers => {'Content-Type' => 'application/json'} } - rescue_ij { post("/node", options) } + rescue_ij { post("/db/data/node", options) } else - rescue_ij { post("/node") } + rescue_ij { post("/db/data/node") } end end def get_node(id) - rescue_ij { get("/node/#{id}") } + rescue_ij { get("/db/data/node/#{id}") } end def reset_node_properties(id, properties) options = { :body => properties.to_json, :headers => {'Content-Type' => 'application/json'} } - rescue_ij { put("/node/#{id}/properties", options) } + rescue_ij { put("/db/data/node/#{id}/properties", options) } end def get_node_properties(id, properties = nil) if properties.nil? - rescue_ij { get("/node/#{id}/properties") } + rescue_ij { get("/db/data/node/#{id}/properties") } else node_properties = Hash.new properties.to_a.each do |property| - value = rescue_ij { get("/node/#{id}/properties/#{property}") } + value = rescue_ij { get("/db/data/node/#{id}/properties/#{property}") } node_properties[property] = value unless value.nil? end return nil if node_properties.empty? @@ -44,10 +44,10 @@ def get_node_properties(id, properties = nil) def remove_node_properties(id, properties = nil) if properties.nil? - rescue_ij { delete("/node/#{id}/properties") } + rescue_ij { delete("/db/data/node/#{id}/properties") } else properties.to_a.each do |property| - rescue_ij { delete("/node/#{id}/properties/#{property}") } + rescue_ij { delete("/db/data/node/#{id}/properties/#{property}") } end end end @@ -55,31 +55,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'} } - rescue_ij { put("/node/#{id}/properties/#{key}", options) } + rescue_ij { put("/db/data/node/#{id}/properties/#{key}", options) } end end def delete_node(id) - rescue_ij { delete("/node/#{id}") } + rescue_ij { delete("/db/data/node/#{id}") } end def create_relationship(type, from, to, props = nil) options = { :body => {:to => Neography::Config.to_s + "/node/#{to}", :data => props, :type => type }.to_json, :headers => {'Content-Type' => 'application/json'} } - rescue_ij { post("/node/#{from}/relationships", options) } + rescue_ij { post("/db/data/node/#{from}/relationships", options) } end def reset_relationship_properties(id, properties) options = { :body => properties.to_json, :headers => {'Content-Type' => 'application/json'} } - rescue_ij { put("/relationship/#{id}/properties", options) } + rescue_ij { put("/db/data/relationship/#{id}/properties", options) } end def get_relationship_properties(id, properties = nil) if properties.nil? - rescue_ij { get("/relationship/#{id}/properties") } + rescue_ij { get("/db/data/relationship/#{id}/properties") } else relationship_properties = Hash.new properties.to_a.each do |property| - value = rescue_ij { get("/relationship/#{id}/properties/#{property}") } + value = rescue_ij { get("/db/data/relationship/#{id}/properties/#{property}") } relationship_properties[property] = value unless value.nil? end return nil if relationship_properties.empty? @@ -89,10 +89,10 @@ def get_relationship_properties(id, properties = nil) def remove_relationship_properties(id, properties = nil) if properties.nil? - rescue_ij { delete("/relationship/#{id}/properties") } + rescue_ij { delete("/db/data/relationship/#{id}/properties") } else properties.to_a.each do |property| - rescue_ij { delete("/relationship/#{id}/properties/#{property}") } + rescue_ij { delete("/db/data/relationship/#{id}/properties/#{property}") } end end end @@ -100,21 +100,21 @@ 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'} } - rescue_ij { put("/relationship/#{id}/properties/#{key}", options) } + rescue_ij { put("/db/data/relationship/#{id}/properties/#{key}", options) } end end def delete_relationship(id) - rescue_ij { delete("/relationship/#{id}") } + rescue_ij { delete("/db/data/relationship/#{id}") } end def get_node_relationships(id, dir=nil, types=nil) dir = get_dir(dir) if types.nil? - node_relationships = rescue_ij { get("/node/#{id}/relationships/#{dir}") } || Array.new + node_relationships = rescue_ij { get("/db/data/node/#{id}/relationships/#{dir}") } || Array.new else - node_relationships = rescue_ij { get("/node/#{id}/relationships/#{dir}/#{types.to_a.join('&')}") } || Array.new + node_relationships = rescue_ij { get("/db/data/node/#{id}/relationships/#{dir}/#{types.to_a.join('&')}") } || Array.new end return nil if node_relationships.empty? node_relationships @@ -123,36 +123,36 @@ def get_node_relationships(id, dir=nil, types=nil) def delete_node!(id) relationships = get_node_relationships(id) relationships.each { |r| delete_relationship(r["self"].split('/').last) } unless relationships.nil? - rescue_ij { delete("/node/#{id}") } + rescue_ij { delete("/db/data/node/#{id}") } end def list_indexes - rescue_ij { get("/index") } + rescue_ij { get("/db/data/index") } end def add_to_index(key, value, id) options = { :body => (Neography::Config.to_s + "/node/#{id}").to_json, :headers => {'Content-Type' => 'application/json'} } - rescue_ij { post("/index/node/#{key}/#{value}", options) } + rescue_ij { post("/db/data/index/node/#{key}/#{value}", options) } end def remove_from_index(key, value, id) - rescue_ij { delete("/index/node/#{key}/#{value}/#{id}") } + rescue_ij { delete("/db/data/index/node/#{key}/#{value}/#{id}") } end def get_index(key, value) - index = rescue_ij { get("/index/node/#{key}/#{value}") } || Array.new + index = rescue_ij { get("/db/data/index/node/#{key}/#{value}") } || Array.new return nil if index.empty? index end def get_path(from, to, relationships, depth=1, algorithm="allPaths") options = { :body => {"to" => Neography::Config.to_s + "/node/#{to}", "relationships" => relationships, "max depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} } - path = rescue_ij { post("/node/#{from}/path", options) } || Hash.new + path = rescue_ij { post("/db/data/node/#{from}/path", options) } || Hash.new end def get_paths(from, to, relationships, depth=1, algorithm="allPaths") options = { :body => {"to" => Neography::Config.to_s + "/node/#{to}", "relationships" => relationships, "max depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} } - paths = rescue_ij { post("/node/#{from}/paths", options) } || Array.new + paths = rescue_ij { post("/db/data/node/#{from}/paths", options) } || Array.new end private diff --git a/spec/integration/node_spec.rb b/spec/integration/node_spec.rb deleted file mode 100644 index e439f63..0000000 --- a/spec/integration/node_spec.rb +++ /dev/null @@ -1,120 +0,0 @@ -require File.join(File.dirname(__FILE__), '..', 'spec_helper') - -describe Neography::Node do - it "can create an empty node" do - node1 = Neography::Node.new - node1.should include(:neo_id) - Neography::Node.exists?(node1[:neo_id]).should be_true - end - - it "can create a node with one property" do - Neography::Node.new(:name => "Max").should include("name"=>"Max") - end - - it "can create a node with more than one property" do - Neography::Node.new(:age => 31, :name => "Max").should include("age"=>31, "name"=>"Max") - end - - it "can tell if a node does not exist" do - Neography::Node.exists?(999).should be_false - end - - it "can find a node by its id" do - Neography::Node.load(2).should include(:neo_id=>"2") - end - - it "fails to find a node that does not exist" do - Neography::Node.load(999).should be_nil - end - - it "can get a node's properties" do - Neography::Node.set_properties(3, {:age => 31, :name => "Max"} ).should be_nil - Neography::Node.properties(3).should include("age"=>31, "name"=>"Max") - end - - it "returns nil if a node has no properties" do - Neography::Node.properties(1).should be_nil - end - - - it "returns nil if the properties of a node that does not exist are requested" do - Neography::Node.properties(999).should be_nil - end - - it "can set a node's properties" do - Neography::Node.set_properties(2, {:age => 32, :name => "Tom"} ).should be_nil - Neography::Node.properties(2).should include("age"=>32, "name"=>"Tom") - end - - it "returns nil if it fails to set properties on a node that does not exist" do - Neography::Node.set_properties(999,{:age => 33, :name => "Harry"}).should be_nil - end - - it "can delete a node's property" do - Neography::Node.set_properties(2, {:age => 32, :name => "Tom", :weight => 200} ).should be_nil - Neography::Node.remove_property(2, :weight).should be_nil - Neography::Node.properties(2).should_not include("weight"=>200) - end - - it "returns nil if it tries to delete a property that does not exist" do - Neography::Node.set_properties(2, {:age => 32, :name => "Tom", :weight => 200} ).should be_nil - Neography::Node.remove_property(2, :height).should be_nil - end - - it "returns nil if it tries to delete a property on a node that does not exist" do - Neography::Node.remove_property(9999, :height).should be_nil - end - - it "can delete all of a node's properties" do - Neography::Node.set_properties(2, {:age => 32, :name => "Tom", :weight => 200} ).should be_nil - Neography::Node.remove_properties(2).should be_nil - Neography::Node.properties(2).should be_nil - end - - it "can delete an unrelated node" do - newnode = Neography::Node.new - Neography::Node.del(newnode[:neo_id]).should be_nil - end - - it "returns nil if it tries to delete a node that does not exist" do - Neography::Node.del(9999).should be_nil - end - - it "returns nil if it tries to delete a node that has already been deleted" do - newnode = Neography::Node.new - Neography::Node.del(newnode[:neo_id]).should be_nil - Neography::Node.del(newnode[:neo_id]).should be_nil - end - - it "does not delete a node that has existing relationships" do - node1 = Neography::Node.new - node2 = Neography::Node.new - Neography::Relationship.new(:friends, node1, node2) - Neography::Node.del(node1[:neo_id]).should be_nil - Neography::Node.del(node2[:neo_id]).should be_nil - Neography::Node.exists?(node1[:neo_id]).should be_true - Neography::Node.exists?(node2[:neo_id]).should be_true - end - - it "does delete! a node that has existing relationships" do - node1 = Neography::Node.new - node2 = Neography::Node.new - Neography::Relationship.new(:friends, node1, node2) - Neography::Node.del!(node1[:neo_id]).should be_nil - Neography::Node.del!(node2[:neo_id]).should be_nil - Neography::Node.exists?(node1[:neo_id]).should be_false - Neography::Node.exists?(node2[:neo_id]).should be_false - end - - it "can find get a node's existing relationships" do - node1 = Neography::Node.new - node2 = Neography::Node.new - Neography::Relationship.new(:friends, node1, node2) - Neography::Node.rels(node1[:neo_id]).to_s.should include("rel_id") - Neography::Node.rels(node1[:neo_id])[0][:rel_id].should_not be_nil - - end - - - -end diff --git a/spec/integration/relationship_spec.rb b/spec/integration/relationship_spec.rb deleted file mode 100644 index 231d9fb..0000000 --- a/spec/integration/relationship_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -require File.join(File.dirname(__FILE__), '..', 'spec_helper') - -describe Neography::Relationship do - it "can create an empty relationship" do - Neography::Relationship.new(:friends, Neography::Node.new, Neography::Node.new).should include(:rel_id) - end - - it "can create a relationship with one property" do - Neography::Relationship.new(:friends, Neography::Node.new, Neography::Node.new, {:since => '10-1-2010'}).should include("since") - end - - it "can create a relationship with multiple properties" do - Neography::Relationship.new(:friends, Neography::Node.new, Neography::Node.new, {:since => '10-1-2010', :closeness => 'bff'}).should include("closeness"=>"bff", "since"=>"10-1-2010") - end - - it "can get a relationship's properties" do - rel = Neography::Relationship.new(:friends, Neography::Node.new, Neography::Node.new) - Neography::Relationship.set_properties(rel[:rel_id], {:since => '10-1-2010'} ).should be_nil - Neography::Relationship.properties(rel[:rel_id]).should include("since"=>"10-1-2010") - end - - it "returns nil if a relationship has no properties" do - rel = Neography::Relationship.new(:friends, Neography::Node.new, Neography::Node.new) - Neography::Relationship.properties(rel[:rel_id]).should be_nil - end - - it "can set a relationship's properties" do - rel = Neography::Relationship.new(:friends, Neography::Node.new, Neography::Node.new) - Neography::Relationship.set_properties(rel[:rel_id], {:since => '10-1-2010'} ).should be_nil - Neography::Relationship.properties(rel[:rel_id]).should include("since"=>"10-1-2010") - end - - it "returns nil if it tries to delete a property that does not exist" do - rel = Neography::Relationship.new(:friends, Neography::Node.new, Neography::Node.new) - Neography::Relationship.set_properties(rel[:rel_id], {:since => '10-1-2010'} ).should be_nil - Neography::Relationship.remove_property(rel[:rel_id], :closeness).should be_nil - end - - it "returns nil if it tries to delete a property on a relationship that does not exist" do - Neography::Relationship.remove_property(9999, :closeness).should be_nil - end - - it "can delete all of a relationship's properties" do - rel = Neography::Relationship.new(:friends, Neography::Node.new, Neography::Node.new) - Neography::Relationship.set_properties(rel[:rel_id], {:since => '10-1-2010'} ).should be_nil - Neography::Relationship.remove_properties(rel[:rel_id]).should be_nil - Neography::Relationship.properties(rel[:rel_id]).should be_nil - end - - it "can delete a relationship" do - rel = Neography::Relationship.new(:friends, Neography::Node.new, Neography::Node.new) - Neography::Relationship.del(rel[:rel_id]).should be_nil - Neography::Relationship.properties(rel[:rel_id]).should be_nil - end - - it "returns nil if it tries to delete a relationship that does not exist" do - Neography::Relationship.del(9999).should be_nil - end - -end \ No newline at end of file diff --git a/spec/integration/rest_index_spec.rb b/spec/integration/rest_index_spec.rb new file mode 100644 index 0000000..b19f444 --- /dev/null +++ b/spec/integration/rest_index_spec.rb @@ -0,0 +1,52 @@ +require File.join(File.dirname(__FILE__), '..', 'spec_helper') + +describe Neography::Rest do + + describe "list indexes" do + it "can get a listing of indexes" do + Neography::Rest.list_indexes.should_not be_nil + end + end + + describe "add to index" do + it "can add a node to an index" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + key = generate_text(6) + value = generate_text + Neography::Rest.add_to_index(key, value, new_node[:id]) + new_index = Neography::Rest.get_index(key, value) + new_index.should_not be_nil + Neography::Rest.remove_from_index(key, value, new_node[:id]) + end + end + + describe "remove from index" do + it "can remove a node from an index" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + key = generate_text(6) + value = generate_text + Neography::Rest.add_to_index(key, value, new_node[:id]) + new_index = Neography::Rest.get_index(key, value) + new_index.should_not be_nil + Neography::Rest.remove_from_index(key, value, new_node[:id]) + new_index = Neography::Rest.get_index(key, value) + new_index.should be_nil + end + end + + describe "get index" do + it "can get an index" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + key = generate_text(6) + value = generate_text + Neography::Rest.add_to_index(key, value, new_node[:id]) + new_index = Neography::Rest.get_index(key, value) + new_index.should_not be_nil + Neography::Rest.remove_from_index(key, value, new_node[:id]) + end + end + +end \ No newline at end of file diff --git a/spec/integration/rest_node_spec.rb b/spec/integration/rest_node_spec.rb new file mode 100644 index 0000000..b44a967 --- /dev/null +++ b/spec/integration/rest_node_spec.rb @@ -0,0 +1,238 @@ +require File.join(File.dirname(__FILE__), '..', 'spec_helper') + +describe Neography::Rest do + + describe "get_root" do + it "can get the root node" do + root_node = Neography::Rest.get_root + root_node.should have_key("reference_node") + end + end + + describe "create_node" do + it "can create an empty node" do + new_node = Neography::Rest.create_node + new_node.should_not be_nil + end + + it "can create a node with one property" do + new_node = Neography::Rest.create_node("name" => "Max") + new_node["data"]["name"].should == "Max" + end + + it "can create a node with more than one property" do + new_node = Neography::Rest.create_node("age" => 31, "name" => "Max") + new_node["data"]["name"].should == "Max" + new_node["data"]["age"].should == 31 + end + end + + describe "get_node" do + it "can get a node that exists" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + existing_node = Neography::Rest.get_node(new_node[:id]) + existing_node.should_not be_nil + existing_node.should have_key("self") + existing_node["self"].split('/').last.should == new_node[:id] + end + + it "returns nil if it tries to get a node that does not exist" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + existing_node = Neography::Rest.get_node(new_node[:id].to_i + 1000) + existing_node.should be_nil + end + end + + describe "set_node_properties" do + it "can set a node's properties" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.set_node_properties(new_node[:id], {"weight" => 200, "eyes" => "brown"}) + existing_node = Neography::Rest.get_node(new_node[:id]) + 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 = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.set_node_properties(new_node[:id].to_i + 1000, {"weight" => 150, "hair" => "blonde"}) + node_properties = Neography::Rest.get_node_properties(new_node[:id].to_i + 1000) + node_properties.should be_nil + end + end + + describe "reset_node_properties" do + it "can reset a node's properties" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.set_node_properties(new_node[:id], {"weight" => 200, "eyes" => "brown", "hair" => "black"}) + Neography::Rest.reset_node_properties(new_node[:id], {"weight" => 190, "eyes" => "blue"}) + existing_node = Neography::Rest.get_node(new_node[:id]) + existing_node["data"]["weight"].should == 190 + existing_node["data"]["eyes"].should == "blue" + existing_node["data"]["hair"].should be_nil + end + + it "it fails to reset properties on a node that does not exist" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.reset_node_properties(new_node[:id].to_i + 1000, {"weight" => 170, "eyes" => "green"}) + node_properties = Neography::Rest.get_node_properties(new_node[:id].to_i + 1000) + node_properties.should be_nil + end + end + + describe "get_node_properties" do + it "can get all of a node's properties" do + new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown") + new_node[:id] = new_node["self"].split('/').last + node_properties = Neography::Rest.get_node_properties(new_node[:id]) + node_properties["weight"].should == 200 + node_properties["eyes"].should == "brown" + end + + it "can get some of a node's properties" do + new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown", "height" => "2m") + new_node[:id] = new_node["self"].split('/').last + node_properties = Neography::Rest.get_node_properties(new_node[:id], ["weight", "height"]) + node_properties["weight"].should == 200 + node_properties["height"].should == "2m" + node_properties["eyes"].should be_nil + end + + it "returns nil if it gets the properties on a node that does not have any" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.get_node_properties(new_node[:id]).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 = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.get_node_properties(new_node[:id], ["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 = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.get_node_properties(new_node[:id].to_i + 10000).should be_nil + end + end + + describe "remove_node_properties" do + it "can remove a node's properties" do + new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown") + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.remove_node_properties(new_node[:id]) + Neography::Rest.get_node_properties(new_node[:id]).should be_nil + end + + it "returns nil if it fails to remove the properties of a node that does not exist" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.remove_node_properties(new_node[:id].to_i + 10000).should be_nil + end + + it "can remove a specific node property" do + new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown") + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.remove_node_properties(new_node[:id], "weight") + node_properties = Neography::Rest.get_node_properties(new_node[:id]) + node_properties["weight"].should be_nil + node_properties["eyes"].should == "brown" + end + + it "can remove more than one property" do + new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown", "height" => "2m") + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.remove_node_properties(new_node[:id], ["weight", "eyes"]) + node_properties = Neography::Rest.get_node_properties(new_node[:id]) + node_properties["weight"].should be_nil + node_properties["eyes"].should be_nil + end + end + + describe "delete_node" do + it "can delete an unrelated node" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.delete_node(new_node[:id]).should be_nil + existing_node = Neography::Rest.get_node(new_node[:id]) + existing_node.should be_nil + end + + it "cannot delete a node that has relationships" do + new_node1 = Neography::Rest.create_node + new_node1[:id] = new_node1["self"].split('/').last + new_node2 = Neography::Rest.create_node + new_node2[:id] = new_node2["self"].split('/').last + Neography::Rest.create_relationship("friends", new_node1[:id], new_node2[:id]) + Neography::Rest.delete_node(new_node1[:id]).should be_nil + existing_node = Neography::Rest.get_node(new_node1[:id]) + existing_node.should_not be_nil + end + + it "returns nil if it tries to delete a node that does not exist" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.delete_node(new_node[:id].to_i + 1000).should be_nil + existing_node = Neography::Rest.get_node(new_node[:id].to_i + 1000) + existing_node.should be_nil + end + + it "returns nil if it tries to delete a node that has already been deleted" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.delete_node(new_node[:id]).should be_nil + existing_node = Neography::Rest.get_node(new_node[:id]) + existing_node.should be_nil + Neography::Rest.delete_node(new_node[:id]).should be_nil + existing_node = Neography::Rest.get_node(new_node[:id]) + existing_node.should be_nil + end + end + + describe "delete_node!" do + it "can delete an unrelated node" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.delete_node!(new_node[:id]).should be_nil + existing_node = Neography::Rest.get_node(new_node[:id]) + existing_node.should be_nil + end + + it "can delete a node that has relationships" do + new_node1 = Neography::Rest.create_node + new_node1[:id] = new_node1["self"].split('/').last + new_node2 = Neography::Rest.create_node + new_node2[:id] = new_node2["self"].split('/').last + Neography::Rest.create_relationship("friends", new_node1[:id], new_node2[:id]) + Neography::Rest.delete_node!(new_node1[:id]).should be_nil + existing_node = Neography::Rest.get_node(new_node1[:id]) + existing_node.should be_nil + end + + it "returns nil if it tries to delete a node that does not exist" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.delete_node!(new_node[:id].to_i + 1000).should be_nil + existing_node = Neography::Rest.get_node(new_node[:id].to_i + 1000) + existing_node.should be_nil + end + + it "returns nil if it tries to delete a node that has already been deleted" do + new_node = Neography::Rest.create_node + new_node[:id] = new_node["self"].split('/').last + Neography::Rest.delete_node!(new_node[:id]).should be_nil + existing_node = Neography::Rest.get_node(new_node[:id]) + existing_node.should be_nil + Neography::Rest.delete_node!(new_node[:id]).should be_nil + existing_node = Neography::Rest.get_node(new_node[:id]) + existing_node.should be_nil + 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 new file mode 100644 index 0000000..439eb8e --- /dev/null +++ b/spec/integration/rest_path_spec.rb @@ -0,0 +1,59 @@ +require File.join(File.dirname(__FILE__), '..', 'spec_helper') + +describe Neography::Rest do + + describe "get path" do + it "can get a path between two nodes" do + new_node1 = Neography::Rest.create_node + new_node1[:id] = new_node1["self"].split('/').last + new_node2 = Neography::Rest.create_node + new_node2[:id] = new_node2["self"].split('/').last + new_relationship = Neography::Rest.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"}) + path = Neography::Rest.get_path(new_node1[:id], new_node2[:id], {"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"]] + end + + it "can get the shortest path between two nodes" do + pending + end + + it "can get a simple path between two nodes" do + pending + end + + it "can get a path between two nodes of max depth 3" do + pending + end + + it "can get a path between two nodes of a specific relationship" do + pending + end + end + + describe "get paths" do + it "can get the shortest paths between two nodes" do + pending + end + + it "can get all paths between two nodes" do + pending + end + + it "can get all simple paths between two nodes" do + pending + end + + it "can get paths between two nodes of max depth 3" do + pending + end + + it "can get paths between two nodes of a specific relationship" do + pending + end + + end + + +end \ No newline at end of file diff --git a/spec/integration/rest_spec.rb b/spec/integration/rest_relationship_spec.rb similarity index 61% rename from spec/integration/rest_spec.rb rename to spec/integration/rest_relationship_spec.rb index f246b3c..78a5bfc 100644 --- a/spec/integration/rest_spec.rb +++ b/spec/integration/rest_relationship_spec.rb @@ -2,239 +2,6 @@ describe Neography::Rest do - describe "get_root" do - it "can get the root node" do - root_node = Neography::Rest.get_root - root_node.should have_key("reference_node") - end - end - - describe "create_node" do - it "can create an empty node" do - new_node = Neography::Rest.create_node - new_node.should_not be_nil - end - - it "can create a node with one property" do - new_node = Neography::Rest.create_node("name" => "Max") - new_node["data"]["name"].should == "Max" - end - - it "can create a node with more than one property" do - new_node = Neography::Rest.create_node("age" => 31, "name" => "Max") - new_node["data"]["name"].should == "Max" - new_node["data"]["age"].should == 31 - end - end - - describe "get_node" do - it "can get a node that exists" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - existing_node = Neography::Rest.get_node(new_node[:id]) - existing_node.should_not be_nil - existing_node.should have_key("self") - existing_node["self"].split('/').last.should == new_node[:id] - end - - it "returns nil if it tries to get a node that does not exist" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - existing_node = Neography::Rest.get_node(new_node[:id].to_i + 1000) - existing_node.should be_nil - end - end - - describe "set_node_properties" do - it "can set a node's properties" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.set_node_properties(new_node[:id], {"weight" => 200, "eyes" => "brown"}) - existing_node = Neography::Rest.get_node(new_node[:id]) - 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 = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.set_node_properties(new_node[:id].to_i + 1000, {"weight" => 150, "hair" => "blonde"}) - node_properties = Neography::Rest.get_node_properties(new_node[:id].to_i + 1000) - node_properties.should be_nil - end - end - - describe "reset_node_properties" do - it "can reset a node's properties" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.set_node_properties(new_node[:id], {"weight" => 200, "eyes" => "brown", "hair" => "black"}) - Neography::Rest.reset_node_properties(new_node[:id], {"weight" => 190, "eyes" => "blue"}) - existing_node = Neography::Rest.get_node(new_node[:id]) - existing_node["data"]["weight"].should == 190 - existing_node["data"]["eyes"].should == "blue" - existing_node["data"]["hair"].should be_nil - end - - it "it fails to reset properties on a node that does not exist" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.reset_node_properties(new_node[:id].to_i + 1000, {"weight" => 170, "eyes" => "green"}) - node_properties = Neography::Rest.get_node_properties(new_node[:id].to_i + 1000) - node_properties.should be_nil - end - end - - describe "get_node_properties" do - it "can get all of a node's properties" do - new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown") - new_node[:id] = new_node["self"].split('/').last - node_properties = Neography::Rest.get_node_properties(new_node[:id]) - node_properties["weight"].should == 200 - node_properties["eyes"].should == "brown" - end - - it "can get some of a node's properties" do - new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown", "height" => "2m") - new_node[:id] = new_node["self"].split('/').last - node_properties = Neography::Rest.get_node_properties(new_node[:id], ["weight", "height"]) - node_properties["weight"].should == 200 - node_properties["height"].should == "2m" - node_properties["eyes"].should be_nil - end - - it "returns nil if it gets the properties on a node that does not have any" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.get_node_properties(new_node[:id]).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 = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.get_node_properties(new_node[:id], ["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 = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.get_node_properties(new_node[:id].to_i + 10000).should be_nil - end - end - - describe "remove_node_properties" do - it "can remove a node's properties" do - new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown") - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.remove_node_properties(new_node[:id]) - Neography::Rest.get_node_properties(new_node[:id]).should be_nil - end - - it "returns nil if it fails to remove the properties of a node that does not exist" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.remove_node_properties(new_node[:id].to_i + 10000).should be_nil - end - - it "can remove a specific node property" do - new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown") - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.remove_node_properties(new_node[:id], "weight") - node_properties = Neography::Rest.get_node_properties(new_node[:id]) - node_properties["weight"].should be_nil - node_properties["eyes"].should == "brown" - end - - it "can remove more than one property" do - new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown", "height" => "2m") - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.remove_node_properties(new_node[:id], ["weight", "eyes"]) - node_properties = Neography::Rest.get_node_properties(new_node[:id]) - node_properties["weight"].should be_nil - node_properties["eyes"].should be_nil - end - end - - describe "delete_node" do - it "can delete an unrelated node" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.delete_node(new_node[:id]).should be_nil - existing_node = Neography::Rest.get_node(new_node[:id]) - existing_node.should be_nil - end - - it "cannot delete a node that has relationships" do - new_node1 = Neography::Rest.create_node - new_node1[:id] = new_node1["self"].split('/').last - new_node2 = Neography::Rest.create_node - new_node2[:id] = new_node2["self"].split('/').last - Neography::Rest.create_relationship("friends", new_node1[:id], new_node2[:id]) - Neography::Rest.delete_node(new_node1[:id]).should be_nil - existing_node = Neography::Rest.get_node(new_node1[:id]) - existing_node.should_not be_nil - end - - it "returns nil if it tries to delete a node that does not exist" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.delete_node(new_node[:id].to_i + 1000).should be_nil - existing_node = Neography::Rest.get_node(new_node[:id].to_i + 1000) - existing_node.should be_nil - end - - it "returns nil if it tries to delete a node that has already been deleted" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.delete_node(new_node[:id]).should be_nil - existing_node = Neography::Rest.get_node(new_node[:id]) - existing_node.should be_nil - Neography::Rest.delete_node(new_node[:id]).should be_nil - existing_node = Neography::Rest.get_node(new_node[:id]) - existing_node.should be_nil - end - end - - describe "delete_node!" do - it "can delete an unrelated node" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.delete_node!(new_node[:id]).should be_nil - existing_node = Neography::Rest.get_node(new_node[:id]) - existing_node.should be_nil - end - - it "can delete a node that has relationships" do - new_node1 = Neography::Rest.create_node - new_node1[:id] = new_node1["self"].split('/').last - new_node2 = Neography::Rest.create_node - new_node2[:id] = new_node2["self"].split('/').last - Neography::Rest.create_relationship("friends", new_node1[:id], new_node2[:id]) - Neography::Rest.delete_node!(new_node1[:id]).should be_nil - existing_node = Neography::Rest.get_node(new_node1[:id]) - existing_node.should be_nil - end - - it "returns nil if it tries to delete a node that does not exist" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.delete_node!(new_node[:id].to_i + 1000).should be_nil - existing_node = Neography::Rest.get_node(new_node[:id].to_i + 1000) - existing_node.should be_nil - end - - it "returns nil if it tries to delete a node that has already been deleted" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - Neography::Rest.delete_node!(new_node[:id]).should be_nil - existing_node = Neography::Rest.get_node(new_node[:id]) - existing_node.should be_nil - Neography::Rest.delete_node!(new_node[:id]).should be_nil - existing_node = Neography::Rest.get_node(new_node[:id]) - existing_node.should be_nil - end - end - describe "create_relationship" do it "can create an empty relationship" do new_node1 = Neography::Rest.create_node @@ -599,105 +366,4 @@ end end - describe "list indexes" do - it "can get a listing of indexes" do - Neography::Rest.list_indexes.should_not be_nil - end - end - - describe "add to index" do - it "can add a node to an index" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - key = generate_text(6) - value = generate_text - Neography::Rest.add_to_index(key, value, new_node[:id]) - new_index = Neography::Rest.get_index(key, value) - new_index.should_not be_nil - Neography::Rest.remove_from_index(key, value, new_node[:id]) - end - end - - describe "remove from index" do - it "can remove a node from an index" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - key = generate_text(6) - value = generate_text - Neography::Rest.add_to_index(key, value, new_node[:id]) - new_index = Neography::Rest.get_index(key, value) - new_index.should_not be_nil - Neography::Rest.remove_from_index(key, value, new_node[:id]) - new_index = Neography::Rest.get_index(key, value) - new_index.should be_nil - end - end - - describe "get index" do - it "can get an index" do - new_node = Neography::Rest.create_node - new_node[:id] = new_node["self"].split('/').last - key = generate_text(6) - value = generate_text - Neography::Rest.add_to_index(key, value, new_node[:id]) - new_index = Neography::Rest.get_index(key, value) - new_index.should_not be_nil - Neography::Rest.remove_from_index(key, value, new_node[:id]) - end - end - - describe "get path" do - it "can get a path between two nodes" do - new_node1 = Neography::Rest.create_node - new_node1[:id] = new_node1["self"].split('/').last - new_node2 = Neography::Rest.create_node - new_node2[:id] = new_node2["self"].split('/').last - new_relationship = Neography::Rest.create_relationship("friends", new_node1[:id], new_node2[:id], {"since" => '10-1-2005', "met" => "college"}) - path = Neography::Rest.get_path(new_node1[:id], new_node2[:id], {"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"]] - end - - it "can get the shortest path between two nodes" do - pending - end - - it "can get a simple path between two nodes" do - pending - end - - it "can get a path between two nodes of max depth 3" do - pending - end - - it "can get a path between two nodes of a specific relationship" do - pending - end - end - - describe "get paths" do - it "can get the shortest paths between two nodes" do - pending - end - - it "can get all paths between two nodes" do - pending - end - - it "can get all simple paths between two nodes" do - pending - end - - it "can get paths between two nodes of max depth 3" do - pending - end - - it "can get paths between two nodes of a specific relationship" do - pending - end - - end - - end \ No newline at end of file diff --git a/spec/integration/root_spec.rb b/spec/integration/root_spec.rb deleted file mode 100644 index 347c88d..0000000 --- a/spec/integration/root_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require File.join(File.dirname(__FILE__), '..', 'spec_helper') - -describe Neography::Neo do - it "has a root node" do - Neography::Neo.root_node.should include("reference_node") - end -end \ No newline at end of file