Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return empty array if no relationships are found #156

Merged
merged 1 commit into from
Mar 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just replace this entire section by @connection.post(base_path(:id => get_id(id)), options) || [].

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