Skip to content

Commit

Permalink
Merge branch 'master' of github.com:maxdemarzi/neography
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Sep 6, 2012
2 parents 3f52df5 + 8c115ca commit 30d85ea
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ Contributors:
* Pablo Fernandez
* Nick Reavill
* Marcel Sherf
* David Pitman
* David Pitman
* Garrett Heaver
8 changes: 7 additions & 1 deletion lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def find_node_auto_index(*args)

def find_node_index(*args)
case args.size
when 3 then index = get("/index/node/#{args[0]}/#{args[1]}?query=#{args[2]}") || Array.new
when 3 then index = get("/index/node/#{args[0]}/#{args[1]}?query=\"#{args[2]}\"") || Array.new
when 2 then index = get("/index/node/#{args[0]}?query=#{args[1]}") || Array.new
end
return nil if index.empty?
Expand Down Expand Up @@ -547,6 +547,12 @@ def get_batch(args)
when 4 then {:method => "DELETE", :to => "/index/node/#{args[1]}/#{args[2]}/#{get_id(args[3])}" }
when 3 then {:method => "DELETE", :to => "/index/node/#{args[1]}/#{get_id(args[2])}" }
end
when :remove_relationship_from_index
case args.size
when 5 then {:method => "DELETE", :to => "/index/relationship/#{args[1]}/#{args[2]}/#{args[3]}/#{get_id(args[4])}" }
when 4 then {:method => "DELETE", :to => "/index/relationship/#{args[1]}/#{args[2]}/#{get_id(args[3])}" }
when 3 then {:method => "DELETE", :to => "/index/relationship/#{args[1]}/#{get_id(args[2])}" }
end
when :delete_node
{:method => "DELETE", :to => "/node/#{get_id(args[1])}"}
else
Expand Down
18 changes: 18 additions & 0 deletions spec/integration/rest_batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,24 @@
@neo.get_node_index(index, key, value3).should be_nil
end

it "can remove a relationship from an index in batch" do
index = generate_text(6)
key = generate_text(6)
value1 = generate_text
value2 = generate_text

node1 = @neo.create_node
node2 = @neo.create_node
relationship1 = @neo.create_unique_relationship(index, key, value1, "friends", node1, node2)
relationship2 = @neo.create_unique_relationship(index, key, value2, "friends", node2, node1)

batch_result = @neo.batch [:remove_relationship_from_index, index, key, relationship1],
[:remove_relationship_from_index, index, key, relationship2]

@neo.get_relationship_index(index, key, value1).should be_nil
@neo.get_relationship_index(index, key, value2).should be_nil
end

end

describe "referenced batch" do
Expand Down
24 changes: 23 additions & 1 deletion spec/integration/rest_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,28 @@
@neo.remove_node_from_index("test_node_index", key, value, new_node)
end

it "can find a node index with spaces in the value" do
new_node = @neo.create_node
key = generate_text(6)
value = generate_text + ' ' + generate_text
@neo.add_node_to_index("test_node_index", key, value, new_node)
new_index = @neo.find_node_index("test_node_index", key, value)
new_index.should_not be_nil
new_index.first["self"].should == new_node["self"]
@neo.remove_node_from_index("test_node_index", key, value, new_node)
end

it "can find a node index with slashes in the value" do
new_node = @neo.create_node
key = generate_text(6)
value = generate_text + '/' + generate_text
@neo.add_node_to_index("test_node_index", key, value, new_node)
new_index = @neo.find_node_index("test_node_index", key, value)
new_index.should_not be_nil
new_index.first["self"].should == new_node["self"]
@neo.remove_node_from_index("test_node_index", key, value, new_node)
end

it "can get a relationship index" do
new_node1 = @neo.create_node
new_node2 = @neo.create_node
Expand Down Expand Up @@ -387,4 +409,4 @@

end

end
end

0 comments on commit 30d85ea

Please sign in to comment.