Skip to content

Commit

Permalink
return empty array if no relationships are found
Browse files Browse the repository at this point in the history
  • Loading branch information
jazminschroeder committed Mar 8, 2014
1 parent c77c38f commit 5058e23
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/neography/node_relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/neography/rest/node_relationships.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/neography/rest/other_node_relationships.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/node_relationship_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/integration/rest_other_node_relationship_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions spec/integration/rest_relationship_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions spec/unit/rest/node_relationships_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5058e23

Please sign in to comment.