Skip to content

Commit

Permalink
Refactor Clean
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Mar 27, 2014
1 parent 72d12d2 commit eecc51a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
15 changes: 1 addition & 14 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Rest
include NodePaths
include Cypher
include Gremlin
include Clean
extend Forwardable

attr_reader :connection
Expand All @@ -66,7 +67,6 @@ def initialize(options = ENV['NEO4J_URL'] || {})

@extensions ||= Extensions.new(@connection)
@batch ||= Batch.new(@connection)
@clean ||= Clean.new(@connection)
@spatial ||= Spatial.new(@connection)
end

Expand Down Expand Up @@ -167,18 +167,5 @@ def add_node_to_spatial_index(index, id)
@spatial.add_node_to_spatial_index(index, id)
end

# clean database

# For testing (use a separate neo4j instance)
# call this before each test or spec
def clean_database(sanity_check = "not_really")
if sanity_check == "yes_i_really_want_to_clean_the_database"
@clean.execute
true
else
false
end
end

end
end
18 changes: 8 additions & 10 deletions lib/neography/rest/clean.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
module Neography
class Rest
class Clean
extend Neography::Rest::Paths
module Clean
include Neography::Rest::Helpers

add_path :clean, "/cleandb/secret-key"

def initialize(connection)
@connection ||= connection
end

def execute
@connection.delete(clean_path)
def clean_database(sanity_check = "not_really")
if sanity_check == "yes_i_really_want_to_clean_the_database"
@connection.delete("/cleandb/secret-key")
true
else
false
end
end

end
Expand Down
7 changes: 3 additions & 4 deletions spec/unit/rest/clean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ module Neography
class Rest
describe Clean do

let(:connection) { double }
subject { Clean.new(connection) }
subject { Neography::Rest.new }

it "cleans the database" do
connection.should_receive(:delete).with("/cleandb/secret-key")
subject.execute
subject.connection.should_receive(:delete).with("/cleandb/secret-key")
subject.clean_database("yes_i_really_want_to_clean_the_database")
end

end
Expand Down

0 comments on commit eecc51a

Please sign in to comment.