Skip to content
Tyrone edited this page Nov 14, 2016 · 5 revisions

Testing

Install a Neo4j test server

rake neo4j:install[community-2.1.3,test]

Configure it using a different server port e.g. 7475

rake neo4j:config[test,7475]

Edit the test configuration `config/environments/test'

config.neo4j.session_type = :server_db
config.neo4j.session_path = 'http://localhost:7475'

See example: Rails Blog Example

How to clear the database

Method 1

Faster, but does not do a complete clean of the database

Neo4j::Session.current._query('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r')

Works also in the embedded db.

Method 2

Slower, Completely delete the database,

Include the require 'neo4j/tasks/neo4j_server' in your Rakefile.

rake neo4j:reset_yes_i_am_sure[test] 

Make sure you have installed a separate neo4j server test installation

Method 3

Only for the embedded neo4j: stop embedded db, delete the db folder, start embedded db.

Method 4 (RSpec)

If you are using RSpec you can perform tests in a transaction as you would using active record. Just add the following to your rspec configuration in spec/rails_helper.rb or spec/spec_helper.rb

config.around do |example|
  Neo4j::Transaction.run do |tx|
    example.run
    tx.mark_failed
  end
end
Clone this wiki locally