Skip to content

Commit

Permalink
Merge pull request #32 from nickflux/master
Browse files Browse the repository at this point in the history
Added clean_database method for testing purposes
  • Loading branch information
maxdemarzi committed Mar 27, 2012
2 parents 1f217fb + 7fddfc9 commit 6e9fe11
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
20 changes: 20 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,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

Expand Down
13 changes: 12 additions & 1 deletion lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,17 @@ def batch(*args)
options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json'} }
post("/batch", options)
end

# 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")
true
else
false
end
end

private

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6e9fe11

Please sign in to comment.