diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index acf08b4..1886d53 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -299,6 +299,10 @@ def find_node_index(index, key_or_query, value = nil) @node_indexes.find(index, key_or_query, value) end + def drop_node_index(index) + @node_indexes.drop(index) + end + # auto node indexes def get_node_auto_index(key, value) @@ -362,6 +366,10 @@ def get_relationship_index(index, key, value) def find_relationship_index(index, key_or_query, value = nil) @relationship_indexes.find(index, key_or_query, value) end + + def drop_relationship_index(index) + @relationship_indexes.drop(index) + end # relationship auto indexes diff --git a/lib/neography/rest/indexes.rb b/lib/neography/rest/indexes.rb index 3f35137..a0e5535 100644 --- a/lib/neography/rest/indexes.rb +++ b/lib/neography/rest/indexes.rb @@ -92,6 +92,9 @@ def remove_by_value(index, id, key, value) @connection.delete(value_path(:index => index, :id => get_id(id), :key => key, :value => value)) end + def drop(index) + @connection.delete(base_path(:index => index)) + end end end end diff --git a/spec/integration/rest_index_spec.rb b/spec/integration/rest_index_spec.rb index 6e70797..2d50a83 100644 --- a/spec/integration/rest_index_spec.rb +++ b/spec/integration/rest_index_spec.rb @@ -439,4 +439,30 @@ end + describe "drop index" do + it "can drop a node index" do + new_node = @neo.create_node + key = generate_text(6) + value = generate_text + @neo.add_node_to_index("test_node_index", key, value, new_node) + new_index = @neo.get_node_index("test_node_index", key, value) + new_index.should_not be_nil + @neo.drop_node_index("test_node_index") + expect { @neo.get_node_index("test_node_index", key, value) }.to raise_error Neography::NotFoundException + end + + it "can get a relationship index" do + new_node1 = @neo.create_node + new_node2 = @neo.create_node + new_relationship = @neo.create_relationship("friends", new_node1, new_node2) + key = generate_text(6) + value = generate_text + @neo.add_relationship_to_index("test_relationship_index", key, value, new_relationship) + new_index = @neo.get_relationship_index("test_relationship_index", key, value) + new_index.should_not be_nil + @neo.drop_relationship_index("test_relationship_index") + expect { @neo.get_relationship_index("test_relationship_index", key, value) }.to raise_error Neography::NotFoundException + end + end + end diff --git a/spec/unit/rest/node_indexes_spec.rb b/spec/unit/rest/node_indexes_spec.rb index 28503f7..bff4bba 100644 --- a/spec/unit/rest/node_indexes_spec.rb +++ b/spec/unit/rest/node_indexes_spec.rb @@ -4,7 +4,7 @@ module Neography class Rest describe NodeIndexes do - let(:connection) { stub(:configuration => "http://configuration") } + let(:connection) { double(:configuration => "http://configuration") } subject { NodeIndexes.new(connection) } it "lists all indexes" do @@ -131,6 +131,11 @@ class Rest subject.remove_by_value("some_index", "42", "some_key", "some_value") end + it "drops an index" do + connection.should_receive(:delete).with("/index/node/some_index") + subject.drop("some_index") + end + end end end diff --git a/spec/unit/rest/relationship_indexes_spec.rb b/spec/unit/rest/relationship_indexes_spec.rb index 2cfb548..085e3a7 100644 --- a/spec/unit/rest/relationship_indexes_spec.rb +++ b/spec/unit/rest/relationship_indexes_spec.rb @@ -4,7 +4,7 @@ module Neography class Rest describe RelationshipIndexes do - let(:connection) { stub(:configuration => "http://configuration") } + let(:connection) { double(:configuration => "http://configuration") } subject { RelationshipIndexes.new(connection) } it "lists all indexes" do @@ -123,6 +123,10 @@ class Rest subject.remove_by_value("some_index", "42", "some_key", "some_value") end + it "drops an index" do + connection.should_receive(:delete).with("/index/relationship/some_index") + subject.drop("some_index") + end end end end