Skip to content

Commit

Permalink
Add UniquePathNotUniqueException.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdvdijk committed Jan 18, 2013
1 parent a1e0459 commit 525ff47
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/neography/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def handle_4xx_500_response(code, body)
when /NoSuchPropertyException/ ; raise NoSuchPropertyException.new(message, code, stacktrace)
when /RelationshipNotFoundException/ ; raise RelationshipNotFoundException.new(message, code, stacktrace)
when /NotFoundException/ ; raise NotFoundException.new(message, code, stacktrace)
when /UniquePathNotUniqueException/ ; raise UniquePathNotUniqueException.new(message, code, stacktrace)
else
raise NeographyError.new(message, code, stacktrace)
end
Expand Down
3 changes: 3 additions & 0 deletions lib/neography/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ class SyntaxException < NeographyError; end
# A path could not be found by node traversal
class NotFoundException < NeographyError; end

# Thrown when CREATE UNIQUE matches multiple paths.
class UniquePathNotUniqueException < NeographyError; end

end
20 changes: 18 additions & 2 deletions spec/integration/rest_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,35 @@

it "can delete everything but start node" do
@neo.execute_query("START n=node(*) MATCH n-[r?]-() WHERE ID(n) <> 0 DELETE n,r")
expect {
expect {
@neo.execute_query("start n=node({id}) return n", {:id => 1})
}.to raise_error(Neography::BadInputException)
root_node = @neo.execute_query("start n=node({id}) return n", {:id => 0})
root_node.should_not be_nil
end
end

it "throws an error for an invalid query" do
expect {
@neo.execute_query("this is not a query")
}.to raise_error(Neography::SyntaxException)
end

it "throws an error for not unique paths in unique path creation" do
node1 = @neo.create_node
node2 = @neo.create_node

id1 = node1["self"].split('/').last.to_i
id2 = node2["self"].split('/').last.to_i

# create two 'FOO' relationships
@neo.execute_query("START a=node({id1}), b=node({id2}) CREATE a-[r:FOO]->b RETURN r", { :id1 => id1, :id2 => id2 })
@neo.execute_query("START a=node({id1}), b=node({id2}) CREATE a-[r:FOO]->b RETURN r", { :id1 => id1, :id2 => id2 })

expect {
@neo.execute_query("START a=node({id1}), b=node({id2}) CREATE UNIQUE a-[r:FOO]->b RETURN r", { :id1 => id1, :id2 => id2 })
}.to raise_error(Neography::UniquePathNotUniqueException)
end

end

end

0 comments on commit 525ff47

Please sign in to comment.