From f4b31eb7a1db1d5b79c8737c5472bcfe884a7ab3 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Tue, 6 Mar 2012 05:46:38 +0000 Subject: [PATCH] adding get_node_index and get_relationship_index to batch --- README.rdoc | 3 ++ lib/neography/rest.rb | 4 +++ spec/integration/rest_batch_spec.rb | 43 ++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/README.rdoc b/README.rdoc index 6ed2eee..81f9a35 100644 --- a/README.rdoc +++ b/README.rdoc @@ -192,6 +192,9 @@ To Use: node1, node3, {:since => "college"}] # Creates two relationships in a batch @neo.batch [:create_unique_relationship, index_name, key, value, "friends", node1, node2] # Creates a unique relationship + @neo.batch [:get_node_index, index_name, key, value] # Get node index + @neo.batch [:get_relationship_index, index_name, key, value] # Get relationship index + @neo.batch [:create_node, {"name" => "Max"}], [:create_node, {"name" => "Marc"}], # Creates two nodes and index them [:add_node_to_index, "test_node_index", key, value, "{0}"], diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index a52749e..de698ea 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -402,6 +402,10 @@ def get_batch(args) {:method => "POST", :to => "/index/node/#{args[1]}", :body => {:uri => (args[4].is_a?(String) && args[4].start_with?("{") ? "" : "/node/") + "#{get_id(args[4])}", :key => args[2], :value => args[3] } } when :add_relationship_to_index {:method => "POST", :to => "/index/relationship/#{args[1]}", :body => {:uri => (args[4].is_a?(String) && args[4].start_with?("{") ? "" : "/relationship/") + "#{get_id(args[4])}", :key => args[2], :value => args[3] } } + when :get_node_index + {:method => "GET", :to => "/index/node/#{args[1]}/#{args[2]}/#{args[3]}"} + when :get_relationship_index + {:method => "GET", :to => "/index/relationship/#{args[1]}/#{args[2]}/#{args[3]}"} end end diff --git a/spec/integration/rest_batch_spec.rb b/spec/integration/rest_batch_spec.rb index 460d516..184f88f 100644 --- a/spec/integration/rest_batch_spec.rb +++ b/spec/integration/rest_batch_spec.rb @@ -189,20 +189,55 @@ end it "can add a node to an index" do + index_name = generate_text(6) new_node = @neo.create_node key = generate_text(6) value = generate_text - new_index = @neo.get_node_index("test_node_index", key, value) - batch_result = @neo.batch [:add_node_to_index, "test_node_index", key, value, new_node] + new_index = @neo.get_node_index(index_name, key, value) + batch_result = @neo.batch [:add_node_to_index, index_name, key, value, new_node] batch_result.first.should have_key("id") batch_result.first.should have_key("from") - existing_index = @neo.find_node_index("test_node_index", key, value) + existing_index = @neo.find_node_index(index_name, key, value) existing_index.should_not be_nil existing_index.first["self"].should == new_node["self"] - @neo.remove_node_from_index("test_node_index", key, value, new_node) + @neo.remove_node_from_index(index_name, key, value, new_node) end end + it "can get a node index" do + index_name = generate_text(6) + key = generate_text(6) + value = generate_text + @neo.create_node_index(index_name) + new_node = @neo.create_node + @neo.add_node_to_index(index_name, key, value, new_node) + batch_result = @neo.batch [:get_node_index, index_name, key, value] + batch_result.first.should have_key("id") + batch_result.first.should have_key("from") + batch_result.first["body"].first["self"].should == new_node["self"] + @neo.remove_node_from_index(index_name, key, value, new_node) + end + + it "can get a relationship index" do + index_name = generate_text(6) + key = generate_text(6) + value = generate_text + @neo.create_relationship_index(index_name) + node1 = @neo.create_node + node2 = @neo.create_node + new_relationship = @neo.create_relationship("friends", node1, node2, {:since => "high school"}) + @neo.add_relationship_to_index(index_name, key, value, new_relationship) + batch_result = @neo.batch [:get_relationship_index, index_name, key, value] + batch_result.first.should have_key("id") + batch_result.first.should have_key("from") + batch_result.first["body"].first["type"].should == "friends" + batch_result.first["body"].first["start"].split('/').last.should == node1["self"].split('/').last + batch_result.first["body"].first["end"].split('/').last.should == node2["self"].split('/').last + end + + + + describe "referenced batch" do it "can create a relationship from two newly created nodes" do batch_result = @neo.batch [:create_node, {"name" => "Max"}], [:create_node, {"name" => "Marc"}], [:create_relationship, "friends", "{0}", "{1}", {:since => "high school"}]