Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added clean_database method for testing purposes #32

Merged
merged 2 commits into from
Mar 27, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

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