Skip to content

Commit

Permalink
adding get_node_index and get_relationship_index to batch
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Mar 6, 2012
1 parent 4ffc2e2 commit f4b31eb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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}"],
Expand Down
4 changes: 4 additions & 0 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
43 changes: 39 additions & 4 deletions spec/integration/rest_batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]
Expand Down

0 comments on commit f4b31eb

Please sign in to comment.