mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Neo4j support
This commit is contained in:
parent
84cabcaa4f
commit
6288ee1b79
17 changed files with 237 additions and 1 deletions
1
Gemfile
1
Gemfile
|
@ -24,6 +24,7 @@ group :development, :test do
|
||||||
|
|
||||||
gem "mongo_mapper"
|
gem "mongo_mapper"
|
||||||
gem "moped"
|
gem "moped"
|
||||||
|
gem "neo4j-core"
|
||||||
gem "couch_potato"
|
gem "couch_potato"
|
||||||
|
|
||||||
gem "sequel", "~>3.21.0"
|
gem "sequel", "~>3.21.0"
|
||||||
|
|
42
Gemfile.lock
42
Gemfile.lock
|
@ -29,9 +29,13 @@ GEM
|
||||||
arel (1.0.1)
|
arel (1.0.1)
|
||||||
activesupport (~> 3.0.0)
|
activesupport (~> 3.0.0)
|
||||||
bcrypt (3.1.7)
|
bcrypt (3.1.7)
|
||||||
|
bcrypt (3.1.7-java)
|
||||||
bcrypt-ruby (3.1.5)
|
bcrypt-ruby (3.1.5)
|
||||||
bcrypt (>= 3.1.3)
|
bcrypt (>= 3.1.3)
|
||||||
|
bcrypt-ruby (3.1.5-java)
|
||||||
|
bcrypt (>= 3.1.3)
|
||||||
bson (1.11.1)
|
bson (1.11.1)
|
||||||
|
bson (1.11.1-java)
|
||||||
bson_ext (1.11.1)
|
bson_ext (1.11.1)
|
||||||
bson (~> 1.11.1)
|
bson (~> 1.11.1)
|
||||||
builder (2.1.2)
|
builder (2.1.2)
|
||||||
|
@ -190,11 +194,18 @@ GEM
|
||||||
data_objects (= 0.10.14)
|
data_objects (= 0.10.14)
|
||||||
erubis (2.6.6)
|
erubis (2.6.6)
|
||||||
abstract (>= 1.0.0)
|
abstract (>= 1.0.0)
|
||||||
|
faraday (0.9.0)
|
||||||
|
multipart-post (>= 1.2, < 3)
|
||||||
|
faraday_middleware (0.9.1)
|
||||||
|
faraday (>= 0.7.4, < 0.10)
|
||||||
fastercsv (1.5.5)
|
fastercsv (1.5.5)
|
||||||
ffi (1.9.6)
|
ffi (1.9.6)
|
||||||
|
ffi (1.9.6-java)
|
||||||
formatador (0.2.5)
|
formatador (0.2.5)
|
||||||
gherkin (2.11.6)
|
gherkin (2.11.6)
|
||||||
json (>= 1.7.6)
|
json (>= 1.7.6)
|
||||||
|
gherkin (2.11.6-java)
|
||||||
|
json (>= 1.7.6)
|
||||||
git (1.2.8)
|
git (1.2.8)
|
||||||
guard (1.8.3)
|
guard (1.8.3)
|
||||||
formatador (>= 0.2.4)
|
formatador (>= 0.2.4)
|
||||||
|
@ -205,6 +216,10 @@ GEM
|
||||||
guard-rspec (2.5.4)
|
guard-rspec (2.5.4)
|
||||||
guard (>= 1.1)
|
guard (>= 1.1)
|
||||||
rspec (~> 2.11)
|
rspec (~> 2.11)
|
||||||
|
httparty (0.13.3)
|
||||||
|
json (~> 1.8)
|
||||||
|
multi_xml (>= 0.5.2)
|
||||||
|
httpclient (2.5.3.3)
|
||||||
i18n (0.4.2)
|
i18n (0.4.2)
|
||||||
jeweler (1.8.4)
|
jeweler (1.8.4)
|
||||||
bundler (~> 1.0)
|
bundler (~> 1.0)
|
||||||
|
@ -212,6 +227,7 @@ GEM
|
||||||
rake
|
rake
|
||||||
rdoc
|
rdoc
|
||||||
json (1.8.1)
|
json (1.8.1)
|
||||||
|
json (1.8.1-java)
|
||||||
json_pure (1.8.1)
|
json_pure (1.8.1)
|
||||||
linecache (0.46)
|
linecache (0.46)
|
||||||
rbx-require-relative (> 0.0.4)
|
rbx-require-relative (> 0.0.4)
|
||||||
|
@ -239,12 +255,28 @@ GEM
|
||||||
mongoid (~> 2.0)
|
mongoid (~> 2.0)
|
||||||
moped (1.5.2)
|
moped (1.5.2)
|
||||||
multi_json (1.2.0)
|
multi_json (1.2.0)
|
||||||
|
multi_xml (0.5.5)
|
||||||
|
multipart-post (2.0.0)
|
||||||
mysql (2.8.1)
|
mysql (2.8.1)
|
||||||
mysql2 (0.3.16)
|
mysql2 (0.3.16)
|
||||||
|
neo4j-community (2.1.5)
|
||||||
|
neo4j-core (3.0.8)
|
||||||
|
activesupport
|
||||||
|
faraday (~> 0.9.0)
|
||||||
|
faraday_middleware (~> 0.9.1)
|
||||||
|
httparty
|
||||||
|
httpclient
|
||||||
|
json
|
||||||
|
neo4j-community (~> 2.1.1)
|
||||||
|
net-http-persistent
|
||||||
|
os
|
||||||
|
zip
|
||||||
nest (1.1.2)
|
nest (1.1.2)
|
||||||
redis
|
redis
|
||||||
|
net-http-persistent (2.9.4)
|
||||||
ohm (0.1.5)
|
ohm (0.1.5)
|
||||||
nest (~> 1.0)
|
nest (~> 1.0)
|
||||||
|
os (0.9.6)
|
||||||
pg (0.17.1)
|
pg (0.17.1)
|
||||||
plucky (0.5.2)
|
plucky (0.5.2)
|
||||||
mongo (~> 1.5)
|
mongo (~> 1.5)
|
||||||
|
@ -252,6 +284,11 @@ GEM
|
||||||
coderay (~> 1.1.0)
|
coderay (~> 1.1.0)
|
||||||
method_source (~> 0.8.1)
|
method_source (~> 0.8.1)
|
||||||
slop (~> 3.4)
|
slop (~> 3.4)
|
||||||
|
pry (0.10.1-java)
|
||||||
|
coderay (~> 1.1.0)
|
||||||
|
method_source (~> 0.8.1)
|
||||||
|
slop (~> 3.4)
|
||||||
|
spoon (~> 0.0)
|
||||||
rack (1.2.8)
|
rack (1.2.8)
|
||||||
rack-mount (0.6.14)
|
rack-mount (0.6.14)
|
||||||
rack (>= 1.0.0)
|
rack (>= 1.0.0)
|
||||||
|
@ -305,6 +342,8 @@ GEM
|
||||||
archive-tar-minitar (>= 0.5.2)
|
archive-tar-minitar (>= 0.5.2)
|
||||||
sequel (3.21.0)
|
sequel (3.21.0)
|
||||||
slop (3.6.0)
|
slop (3.6.0)
|
||||||
|
spoon (0.0.4)
|
||||||
|
ffi
|
||||||
sqlite3 (1.3.9)
|
sqlite3 (1.3.9)
|
||||||
sqlite3-ruby (1.3.3)
|
sqlite3-ruby (1.3.3)
|
||||||
sqlite3 (>= 1.3.3)
|
sqlite3 (>= 1.3.3)
|
||||||
|
@ -312,8 +351,10 @@ GEM
|
||||||
thor (0.14.6)
|
thor (0.14.6)
|
||||||
tzinfo (0.3.41)
|
tzinfo (0.3.41)
|
||||||
uuidtools (2.1.5)
|
uuidtools (2.1.5)
|
||||||
|
zip (2.0.2)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
|
java
|
||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
@ -336,6 +377,7 @@ DEPENDENCIES
|
||||||
moped
|
moped
|
||||||
mysql (~> 2.8.1)
|
mysql (~> 2.8.1)
|
||||||
mysql2
|
mysql2
|
||||||
|
neo4j-core
|
||||||
ohm (~> 0.1.3)
|
ohm (~> 0.1.3)
|
||||||
pg
|
pg
|
||||||
rake
|
rake
|
||||||
|
|
|
@ -67,9 +67,17 @@ Here is an overview of the strategies supported for each library:
|
||||||
<td>No</td>
|
<td>No</td>
|
||||||
<td>No</td>
|
<td>No</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Neo4j</td>
|
||||||
|
<td>Yes</td>
|
||||||
|
<td>Yes*</td>
|
||||||
|
<td>Yes*</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
* Truncation and Deletion strategies for Neo4j will just delete all nodes and relationships from the database.
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
31
examples/features/step_definitions/neo4j_steps.rb
Normal file
31
examples/features/step_definitions/neo4j_steps.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
Given /^I have setup database cleaner to clean multiple databases using neo4j$/ do
|
||||||
|
#DatabaseCleaner
|
||||||
|
# require "#{File.dirname(__FILE__)}/../../../lib/neo4j_models"
|
||||||
|
#
|
||||||
|
# DatabaseCleaner[:neo4j, :connection => {:type => :server_db, :path => 'http://localhost:7475'} ]
|
||||||
|
# DatabaseCleaner[:neo4j, :connection => {:type => :server_db, :path => 'http://localhost:7476'} ]
|
||||||
|
end
|
||||||
|
|
||||||
|
When /^I create a widget using neo4j$/ do
|
||||||
|
Neo4jWidget.create!
|
||||||
|
end
|
||||||
|
|
||||||
|
Then /^I should see ([\d]+) widget using neo4j$/ do |widget_count|
|
||||||
|
Neo4jWidget.count.should == widget_count.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
When /^I create a widget in one db using neo4j$/ do
|
||||||
|
Neo4jWidgetUsingDatabaseOne.create!
|
||||||
|
end
|
||||||
|
|
||||||
|
When /^I create a widget in another db using neo4j$/ do
|
||||||
|
Neo4jWidgetUsingDatabaseTwo.create!
|
||||||
|
end
|
||||||
|
|
||||||
|
Then /^I should see ([\d]+) widget in one db using neo4j$/ do |widget_count|
|
||||||
|
Neo4jWidgetUsingDatabaseOne.count.should == widget_count.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
Then /^I should see ([\d]+) widget in another db using neo4j$/ do |widget_count|
|
||||||
|
Neo4jWidgetUsingDatabaseTwo.count.should == widget_count.to_i
|
||||||
|
end
|
|
@ -47,6 +47,9 @@ if orm && strategy
|
||||||
when :active_record
|
when :active_record
|
||||||
DatabaseCleaner[:active_record, {:model => ActiveRecordWidgetUsingDatabaseOne} ].strategy = strategy.to_sym
|
DatabaseCleaner[:active_record, {:model => ActiveRecordWidgetUsingDatabaseOne} ].strategy = strategy.to_sym
|
||||||
DatabaseCleaner[:active_record, {:model => ActiveRecordWidgetUsingDatabaseTwo} ].strategy = strategy.to_sym
|
DatabaseCleaner[:active_record, {:model => ActiveRecordWidgetUsingDatabaseTwo} ].strategy = strategy.to_sym
|
||||||
|
when :neo4j
|
||||||
|
DatabaseCleaner[:neo4j, {:connection => {:type => :server_db, :path => 'http://localhost:7475/'}} ].strategy = strategy.to_sym
|
||||||
|
DatabaseCleaner[:neo4j, {:connection => {:type => :server_db, :path => 'http://localhost:7476/'}} ].strategy = strategy.to_sym
|
||||||
else
|
else
|
||||||
DatabaseCleaner[ orm_sym, {:connection => :one} ].strategy = strategy.to_sym
|
DatabaseCleaner[ orm_sym, {:connection => :one} ].strategy = strategy.to_sym
|
||||||
DatabaseCleaner[ orm_sym, {:connection => :two} ].strategy = strategy.to_sym
|
DatabaseCleaner[ orm_sym, {:connection => :two} ].strategy = strategy.to_sym
|
||||||
|
|
17
examples/lib/neo4j_models.rb
Normal file
17
examples/lib/neo4j_models.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
require 'neo4j-core'
|
||||||
|
|
||||||
|
class Neo4jWidget < Neo4j::Node
|
||||||
|
def self.create!(*args)
|
||||||
|
create(*args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.count
|
||||||
|
Neo4j::Session.query.pluck('count(*) AS result').first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Neo4jWidgetUsingDatabaseOne < Neo4jWidget
|
||||||
|
end
|
||||||
|
|
||||||
|
class Neo4jWidgetUsingDatabaseTwo < Neo4jWidget
|
||||||
|
end
|
|
@ -22,3 +22,6 @@ Feature: database cleaning
|
||||||
| CouchPotato | truncation |
|
| CouchPotato | truncation |
|
||||||
| Redis | truncation |
|
| Redis | truncation |
|
||||||
| Ohm | truncation |
|
| Ohm | truncation |
|
||||||
|
| Neo4j | deletion |
|
||||||
|
| Neo4j | truncation |
|
||||||
|
| Neo4j | transaction |
|
||||||
|
|
|
@ -19,3 +19,4 @@ Feature: database cleaning
|
||||||
| CouchPotato |
|
| CouchPotato |
|
||||||
| Redis |
|
| Redis |
|
||||||
| Ohm |
|
| Ohm |
|
||||||
|
| Neo4j |
|
||||||
|
|
|
@ -18,3 +18,6 @@ Feature: multiple database cleaning
|
||||||
| MongoMapper | truncation |
|
| MongoMapper | truncation |
|
||||||
| DataMapper | transaction |
|
| DataMapper | transaction |
|
||||||
| ActiveRecord | transaction |
|
| ActiveRecord | transaction |
|
||||||
|
| Neo4j | deletion |
|
||||||
|
| Neo4j | truncation |
|
||||||
|
| Neo4j | transaction |
|
||||||
|
|
|
@ -46,3 +46,7 @@ Feature: database cleaning using multiple ORMs
|
||||||
| Redis | Mongoid |
|
| Redis | Mongoid |
|
||||||
| Redis | CouchPotato |
|
| Redis | CouchPotato |
|
||||||
| Redis | Ohm |
|
| Redis | Ohm |
|
||||||
|
| Neo4j | ActiveRecord |
|
||||||
|
| Neo4j | Redis |
|
||||||
|
| Neo4j | Ohm |
|
||||||
|
| Neo4j | MongoMapper |
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
orms_pattern = /(ActiveRecord|DataMapper|MongoMapper|Mongoid|CouchPotato|Redis|Ohm)/
|
orms_pattern = /(ActiveRecord|DataMapper|MongoMapper|Mongoid|CouchPotato|Redis|Ohm|Neo4j)/
|
||||||
|
|
||||||
Given /^I am using #{orms_pattern}$/ do |orm|
|
Given /^I am using #{orms_pattern}$/ do |orm|
|
||||||
@feature_runner = FeatureRunner.new
|
@feature_runner = FeatureRunner.new
|
||||||
|
|
|
@ -120,6 +120,8 @@ module DatabaseCleaner
|
||||||
:ohm
|
:ohm
|
||||||
elsif defined? ::Redis
|
elsif defined? ::Redis
|
||||||
:redis
|
:redis
|
||||||
|
elsif defined? ::Neo4j
|
||||||
|
:neo4j
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -153,6 +155,8 @@ module DatabaseCleaner
|
||||||
self.strategy = :transaction
|
self.strategy = :transaction
|
||||||
when :mongo_mapper, :mongoid, :couch_potato, :moped, :ohm, :redis
|
when :mongo_mapper, :mongoid, :couch_potato, :moped, :ohm, :redis
|
||||||
self.strategy = :truncation
|
self.strategy = :truncation
|
||||||
|
when :neo4j
|
||||||
|
self.strategy = :transaction
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -123,6 +123,8 @@ module DatabaseCleaner
|
||||||
DatabaseCleaner::Ohm
|
DatabaseCleaner::Ohm
|
||||||
when :redis
|
when :redis
|
||||||
DatabaseCleaner::Redis
|
DatabaseCleaner::Redis
|
||||||
|
when :neo4j
|
||||||
|
DatabaseCleaner::Neo4j
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
58
lib/database_cleaner/neo4j/base.rb
Normal file
58
lib/database_cleaner/neo4j/base.rb
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
require 'database_cleaner/generic/base'
|
||||||
|
module DatabaseCleaner
|
||||||
|
module Neo4j
|
||||||
|
def self.available_strategies
|
||||||
|
%w[transaction truncation deletion]
|
||||||
|
end
|
||||||
|
|
||||||
|
module Base
|
||||||
|
include ::DatabaseCleaner::Generic::Base
|
||||||
|
|
||||||
|
def db=(desired_db)
|
||||||
|
@db = desired_db == :default ? nil : desired_db
|
||||||
|
end
|
||||||
|
|
||||||
|
def db
|
||||||
|
@db ||= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def start
|
||||||
|
if db_type == :embedded_db and not session.running?
|
||||||
|
session.start
|
||||||
|
else
|
||||||
|
session
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def database
|
||||||
|
db && default_db.merge(db) || default_db
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def default_db
|
||||||
|
{type: default_db_type, path: default_db_path}
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_db_type
|
||||||
|
:server_db
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_db_path(type = default_db_type)
|
||||||
|
type == :server_db ? 'http://localhost:7475/' : './db/test'
|
||||||
|
end
|
||||||
|
|
||||||
|
def db_type
|
||||||
|
database[:type]
|
||||||
|
end
|
||||||
|
|
||||||
|
def db_path
|
||||||
|
database[:path]
|
||||||
|
end
|
||||||
|
|
||||||
|
def session
|
||||||
|
@session ||= ::Neo4j::Session.open(db_type, db_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
16
lib/database_cleaner/neo4j/deletion.rb
Normal file
16
lib/database_cleaner/neo4j/deletion.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
require 'database_cleaner/neo4j/base'
|
||||||
|
require 'neo4j-core'
|
||||||
|
|
||||||
|
module DatabaseCleaner
|
||||||
|
module Neo4j
|
||||||
|
class Deletion
|
||||||
|
include ::DatabaseCleaner::Neo4j::Base
|
||||||
|
|
||||||
|
def clean
|
||||||
|
::Neo4j::Transaction.run do
|
||||||
|
session._query('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
34
lib/database_cleaner/neo4j/transaction.rb
Normal file
34
lib/database_cleaner/neo4j/transaction.rb
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
require 'database_cleaner/neo4j/base'
|
||||||
|
require 'database_cleaner/generic/transaction'
|
||||||
|
require 'neo4j-core'
|
||||||
|
|
||||||
|
module DatabaseCleaner
|
||||||
|
module Neo4j
|
||||||
|
class Transaction
|
||||||
|
include ::DatabaseCleaner::Generic::Transaction
|
||||||
|
include ::DatabaseCleaner::Neo4j::Base
|
||||||
|
|
||||||
|
attr_accessor :tx
|
||||||
|
|
||||||
|
def start
|
||||||
|
super
|
||||||
|
rollback
|
||||||
|
self.tx = ::Neo4j::Transaction.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def clean
|
||||||
|
rollback
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def rollback
|
||||||
|
return unless tx
|
||||||
|
tx.failure
|
||||||
|
tx.close
|
||||||
|
self.tx = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
9
lib/database_cleaner/neo4j/truncation.rb
Normal file
9
lib/database_cleaner/neo4j/truncation.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
require 'database_cleaner/neo4j/base'
|
||||||
|
require 'database_cleaner/neo4j/deletion'
|
||||||
|
|
||||||
|
module DatabaseCleaner
|
||||||
|
module Neo4j
|
||||||
|
class Truncation < DatabaseCleaner::Neo4j::Deletion
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue