diff --git a/lib/neography/connection.rb b/lib/neography/connection.rb index 5dbb14f..3805451 100644 --- a/lib/neography/connection.rb +++ b/lib/neography/connection.rb @@ -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 diff --git a/lib/neography/errors.rb b/lib/neography/errors.rb index 31192ee..d03a785 100644 --- a/lib/neography/errors.rb +++ b/lib/neography/errors.rb @@ -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 diff --git a/spec/integration/rest_plugin_spec.rb b/spec/integration/rest_plugin_spec.rb index 04794b8..68e2882 100644 --- a/spec/integration/rest_plugin_spec.rb +++ b/spec/integration/rest_plugin_spec.rb @@ -64,12 +64,12 @@ 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 { @@ -77,6 +77,22 @@ }.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