Skip to content

Commit

Permalink
add ability to drop indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Aug 30, 2013
1 parent fe61741 commit 1e1a432
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions lib/neography/rest/indexes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 26 additions & 0 deletions spec/integration/rest_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion spec/unit/rest/node_indexes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 5 additions & 1 deletion spec/unit/rest/relationship_indexes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 1e1a432

Please sign in to comment.