diff --git a/lib/neography/node_relationship.rb b/lib/neography/node_relationship.rb index 71fbc3a..217557a 100644 --- a/lib/neography/node_relationship.rb +++ b/lib/neography/node_relationship.rb @@ -21,15 +21,15 @@ def rels(*types) def rel(dir, type) rel = Neography::RelationshipTraverser.new(self, type, dir) - rel = rel.first unless rel.nil? + rel = rel.first unless rel.empty? rel end def rel?(dir=nil, type=nil) if DIRECTIONS.include?(dir.to_s) - !self.neo_server.get_node_relationships(self, dir, type).nil? + !self.neo_server.get_node_relationships(self, dir, type).empty? else - !self.neo_server.get_node_relationships(self, type, dir).nil? + !self.neo_server.get_node_relationships(self, type, dir).empty? end end diff --git a/lib/neography/rest/node_relationships.rb b/lib/neography/rest/node_relationships.rb index 33fa68a..a819438 100644 --- a/lib/neography/rest/node_relationships.rb +++ b/lib/neography/rest/node_relationships.rb @@ -33,7 +33,7 @@ def get(id, direction = nil, types = nil) node_relationships = @connection.get(type_path(:id => get_id(id), :direction => direction, :types => Array(types).join('&'))) || [] end - return nil if node_relationships.empty? + return [] if node_relationships.empty? node_relationships end diff --git a/lib/neography/rest/other_node_relationships.rb b/lib/neography/rest/other_node_relationships.rb index a2d8c8d..d52e438 100644 --- a/lib/neography/rest/other_node_relationships.rb +++ b/lib/neography/rest/other_node_relationships.rb @@ -39,7 +39,7 @@ def get(id, other_id, direction = "all", types = [nil]) node_relationships = @connection.post(base_path(:id => get_id(id)), options) || [] - return nil if node_relationships.empty? + return [] if node_relationships.empty? node_relationships end diff --git a/spec/integration/node_relationship_spec.rb b/spec/integration/node_relationship_spec.rb index 3fef3b1..258f1e7 100644 --- a/spec/integration/node_relationship_spec.rb +++ b/spec/integration/node_relationship_spec.rb @@ -331,7 +331,7 @@ def create_nodes it "#rel returns nil if there is no relationship" do a = Neography::Node.create b = Neography::Node.create - a.rel(:outgoing, :friend).should be_nil + a.rel(:outgoing, :friend).should be_empty end it "#rel should only return one relationship even if there are more" do diff --git a/spec/integration/rest_other_node_relationship_spec.rb b/spec/integration/rest_other_node_relationship_spec.rb index fa2364f..27c127e 100644 --- a/spec/integration/rest_other_node_relationship_spec.rb +++ b/spec/integration/rest_other_node_relationship_spec.rb @@ -16,13 +16,13 @@ existing_relationships[0]["self"].should == new_relationship["self"] end - it "returns nil if it tries to get a relationship that does not exist" do + it "returns empty array if it tries to get a relationship that does not exist" do new_node1 = @neo.create_node new_node2 = @neo.create_node new_node3 = @neo.create_node new_relationship = @neo.create_relationship("friends", new_node1, new_node2) existing_relationship = @neo.get_node_relationships_to(new_node1, new_node3) - existing_relationship.should be_nil + existing_relationship.should be_empty end end @@ -130,7 +130,7 @@ new_node1 = @neo.create_node new_node2 = @neo.create_node relationships = @neo.get_node_relationships_to(new_node1, new_node2) - relationships.should be_nil + relationships.should be_empty end end diff --git a/spec/integration/rest_relationship_spec.rb b/spec/integration/rest_relationship_spec.rb index fa90edd..42be9ee 100644 --- a/spec/integration/rest_relationship_spec.rb +++ b/spec/integration/rest_relationship_spec.rb @@ -219,7 +219,7 @@ 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 + relationships.should be_empty end it "raises error if it tries to delete a relationship that does not exist" do @@ -347,7 +347,7 @@ it "returns nil if there are no relationships" do new_node1 = @neo.create_node relationships = @neo.get_node_relationships(new_node1) - relationships.should be_nil + relationships.should be_empty end end diff --git a/spec/unit/rest/node_relationships_spec.rb b/spec/unit/rest/node_relationships_spec.rb index 06d8af4..d11d700 100644 --- a/spec/unit/rest/node_relationships_spec.rb +++ b/spec/unit/rest/node_relationships_spec.rb @@ -43,13 +43,13 @@ class Rest subject.get("42", :in, ["foo", "bar"]) end - it "returns nil if no relationships were found" do - connection.stub(:get).and_return(nil) - subject.get("42", :in).should be_nil + it "returns empty array if no relationships were found" do + connection.stub(:get).and_return([]) + subject.get("42", :in).should be_empty end - it "returns nil if no relationships were found by type" do - connection.stub(:get).and_return(nil) + it "returns empty array if no relationships were found by type" do + connection.stub(:get).and_return([]) subject.get("42", :in, "foo") end