From 7990f3c4213b85bfe18bf10b4253cd03b3958b55 Mon Sep 17 00:00:00 2001 From: nickflux Date: Fri, 23 Mar 2012 14:50:43 +0000 Subject: [PATCH 1/2] add clean database method for testing --- lib/neography/rest.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index f81fe87..9c9a3f7 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -382,6 +382,17 @@ def batch(*args) options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json'} } post("/batch", options) end + + ### + # FOR TESTING + def clean_database(sanity_check = "not_really") + if sanity_check == "yes_i_really_want_to_clean_the_database" + delete("/cleandb/secret-key") + true + else + false + end + end private @@ -435,7 +446,7 @@ def evaluate_response(response) @logger.error "Invalid data sent #{body}" if @log_enabled nil when 404 - @logger.error "#{body}" if @log_enabled + @logger.error "Not Found #{body}" if @log_enabled nil when 409 @logger.error "Node could not be deleted (still has relationships?)" if @log_enabled From 7fddfc91617b48df6d8bc7798674aff3ebf6f626 Mon Sep 17 00:00:00 2001 From: nickflux Date: Mon, 26 Mar 2012 16:32:06 +0100 Subject: [PATCH 2/2] Added clean_database to Rest module to use test-delete-db-extension plugin --- README.rdoc | 20 ++++++++++++++++++++ lib/neography/rest.rb | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.rdoc b/README.rdoc index c647d16..d3012e4 100644 --- a/README.rdoc +++ b/README.rdoc @@ -341,6 +341,26 @@ Phase 2 way of doing these: * {Facebook}[https://github.com/maxdemarzi/neography/blob/master/examples/facebook_v2.rb] * {Linked In}[https://github.com/maxdemarzi/neography/blob/master/examples/linkedin_v2.rb] +=== Testing + +To run testing locally you will need to have two instances of the server running. There is some +good advice on how to set up the a second instance on the +{neo4j site}[http://docs.neo4j.org/chunked/stable/server-installation.html#_multiple_server_instances_on_one_machine]. +Connect to the second instance in your testing environment, for example: + + if Rails.env.development? + @neo = Neography::Rest.new({:port => 7474}) + elsif Rails.env.test? + @neo = Neography::Rest.new({:port => 7475}) + end + +Install the test-delete-db-extension plugin, as mentioned in the neo4j.org docs, if you want to use +the Rest clean_database method to empty your database between tests. In Rspec, for example, +put this in your spec_helper.rb: + + config.before(:each) do + @neo.clean_database("yes_i_really_want_to_clean_the_database") + end === To Do diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 9c9a3f7..d08baba 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -383,8 +383,8 @@ def batch(*args) post("/batch", options) end - ### - # FOR TESTING + # 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" delete("/cleandb/secret-key")