From 80c863df1ede8a5094349d327f41b10cba0ed569 Mon Sep 17 00:00:00 2001 From: Javad Karabi Date: Thu, 28 Nov 2013 16:18:02 -0600 Subject: [PATCH 1/5] allow for Neography::Relationship.create_unique --- lib/neography/relationship.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/neography/relationship.rb b/lib/neography/relationship.rb index 383fac4..3f4f3a9 100644 --- a/lib/neography/relationship.rb +++ b/lib/neography/relationship.rb @@ -16,6 +16,14 @@ def create(type, from_node, to_node, props = nil) rel end + def create_unique(index, key, value, type, from_node, to_node, props = nil) + rel = Neography::Relationship.new(from_node.neo_server.create_unique_relationship(index, key, value, type, from_node, to_node, props)) + rel.start_node = from_node + rel.end_node = to_node + rel.rel_type = type + rel + end + def load(rel, db = Neography::Rest.new) raise ArgumentError.new("syntax deprecated") if rel.is_a?(Neography::Rest) From e851d5f5d0b0457b8812b79ce2363ea18506044b Mon Sep 17 00:00:00 2001 From: Javad Karabi Date: Thu, 28 Nov 2013 16:58:05 -0600 Subject: [PATCH 2/5] pass properties to unique relationship creation --- lib/neography/rest.rb | 4 ++-- lib/neography/rest/relationship_indexes.rb | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 1886d53..4ed60f8 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -347,8 +347,8 @@ def create_relationship_auto_index(type = "exact", provider = "lucene") @relationship_indexes.create_auto(type, provider) end - def create_unique_relationship(index, key, value, type, from, to) - @relationship_indexes.create_unique(index, key, value, type, from, to) + def create_unique_relationship(index, key, value, type, from, to, props) + @relationship_indexes.create_unique(index, key, value, type, from, to, props) end def add_relationship_to_index(index, key, value, id) diff --git a/lib/neography/rest/relationship_indexes.rb b/lib/neography/rest/relationship_indexes.rb index b0a2aa6..7d0fb4a 100644 --- a/lib/neography/rest/relationship_indexes.rb +++ b/lib/neography/rest/relationship_indexes.rb @@ -17,13 +17,14 @@ def initialize(connection) super(connection, :relationship) end - def create_unique(index, key, value, type, from, to) + def create_unique(index, key, value, type, from, to, props) body = { :key => key, :value => value, :type => type, :start => @connection.configuration + "/node/#{get_id(from)}", - :end => @connection.configuration + "/node/#{get_id(to)}" + :end => @connection.configuration + "/node/#{get_id(to)}", + :properties => props } options = { :body => body.to_json, :headers => json_content_type } From bd06cc5f0b15edc920f8004f1f7a6df4eeb955ab Mon Sep 17 00:00:00 2001 From: Javad Karabi Date: Thu, 28 Nov 2013 21:47:56 -0600 Subject: [PATCH 3/5] TravisCI builds were failing due to the missing props arg. --- lib/neography/rest.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 4ed60f8..69f5cf1 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -347,7 +347,7 @@ def create_relationship_auto_index(type = "exact", provider = "lucene") @relationship_indexes.create_auto(type, provider) end - def create_unique_relationship(index, key, value, type, from, to, props) + def create_unique_relationship(index, key, value, type, from, to, props = nil) @relationship_indexes.create_unique(index, key, value, type, from, to, props) end From 64566404b8f58b97f39ebafa5b32d9ca6b45ae0c Mon Sep 17 00:00:00 2001 From: Javad Karabi Date: Thu, 28 Nov 2013 21:52:51 -0600 Subject: [PATCH 4/5] again... --- lib/neography/rest/relationship_indexes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/neography/rest/relationship_indexes.rb b/lib/neography/rest/relationship_indexes.rb index 7d0fb4a..9657b43 100644 --- a/lib/neography/rest/relationship_indexes.rb +++ b/lib/neography/rest/relationship_indexes.rb @@ -17,7 +17,7 @@ def initialize(connection) super(connection, :relationship) end - def create_unique(index, key, value, type, from, to, props) + def create_unique(index, key, value, type, from, to, props = nil) body = { :key => key, :value => value, From 77ef235866962f5c95255d8899063b794cf865fe Mon Sep 17 00:00:00 2001 From: Javad Karabi Date: Thu, 28 Nov 2013 22:09:36 -0600 Subject: [PATCH 5/5] rspec fix --- spec/unit/rest/relationship_indexes_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/unit/rest/relationship_indexes_spec.rb b/spec/unit/rest/relationship_indexes_spec.rb index 085e3a7..d98e2ce 100644 --- a/spec/unit/rest/relationship_indexes_spec.rb +++ b/spec/unit/rest/relationship_indexes_spec.rb @@ -47,10 +47,11 @@ class Rest "value" => "value", "type" => "type", "start" => "http://configuration/node/42", - "end" => "http://configuration/node/43" + "end" => "http://configuration/node/43", + "properties" => "properties" } connection.should_receive(:post).with("/index/relationship/some_index?unique", json_match(:body, expected_body)) - subject.create_unique("some_index", "key", "value", "type", "42", "43") + subject.create_unique("some_index", "key", "value", "type", "42", "43", "properties") end it "adds a relationship to an index" do