extract database_cleaner-neo4j adapter.

This commit is contained in:
Micah Geisel 2018-05-26 00:00:18 -07:00
parent 7aca1791d0
commit 2998bd43a1
26 changed files with 449 additions and 0 deletions

View File

@ -8,4 +8,5 @@ path "./adapters" do
gem "database_cleaner-mongoid"
gem "database_cleaner-mongo_mapper"
gem "database_cleaner-moped"
gem "database_cleaner-neo4j"
end

View File

@ -28,6 +28,9 @@ PATH
database_cleaner-moped (1.8.0)
database_cleaner (~> 1.8.0)
moped
database_cleaner-neo4j (1.8.0)
database_cleaner (~> 1.8.0)
neo4j-core
GEM
remote: https://rubygems.org/
@ -280,6 +283,7 @@ DEPENDENCIES
database_cleaner-mongo_mapper!
database_cleaner-mongoid!
database_cleaner-moped!
database_cleaner-neo4j!
datamapper
dm-migrations
dm-sqlite-adapter

View File

@ -0,0 +1,11 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
# rspec failure tracking
.rspec_status

View File

@ -0,0 +1,3 @@
--format documentation
--color
--require spec_helper

View File

@ -0,0 +1,5 @@
sudo: false
language: ruby
rvm:
- 2.2.9
before_install: gem install bundler -v 1.16.1

View File

@ -0,0 +1,8 @@
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
# Specify your gem's dependencies in database_cleaner-neo4j.gemspec
gemspec
gem "database_cleaner", path: "../.."

View File

@ -0,0 +1,70 @@
PATH
remote: ../..
specs:
database_cleaner (1.8.0)
PATH
remote: .
specs:
database_cleaner-neo4j (1.8.0)
database_cleaner (~> 1.8.0)
neo4j-core
GEM
remote: https://rubygems.org/
specs:
activesupport (3.0.0)
diff-lcs (1.3)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.9.1)
faraday (>= 0.7.4, < 0.10)
httparty (0.13.3)
json (~> 1.8)
multi_xml (>= 0.5.2)
httpclient (2.5.3.3)
json (1.8.6)
multi_xml (0.5.5)
multipart-post (2.0.0)
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
net-http-persistent (2.9.4)
os (0.9.6)
rake (10.4.2)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
zip (2.0.2)
PLATFORMS
ruby
DEPENDENCIES
bundler (~> 1.16)
database_cleaner!
database_cleaner-neo4j!
rake (~> 10.0)
rspec (~> 3.0)
BUNDLED WITH
1.16.1

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2009 Ben Mabey
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,39 @@
# DatabaseCleaner::Neo4j
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/database_cleaner/neo4j`. To experiment with that code, run `bin/console` for an interactive prompt.
TODO: Delete this and the text above, and describe your gem
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'database_cleaner-neo4j'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install database_cleaner-neo4j
## Usage
TODO: Write usage instructions here
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/database_cleaner-neo4j.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

View File

@ -0,0 +1,6 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task :default => :spec

View File

@ -0,0 +1,14 @@
#!/usr/bin/env ruby
require "bundler/setup"
require "database_cleaner/neo4j"
# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start
require "irb"
IRB.start(__FILE__)

View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx
bundle install
# Do any other automated setup that you need to do here

View File

@ -0,0 +1,30 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "database_cleaner/neo4j/version"
Gem::Specification.new do |spec|
spec.name = "database_cleaner-neo4j"
spec.version = DatabaseCleaner::Neo4j::VERSION
spec.authors = ["Ernesto Tagwerker"]
spec.email = ["ernesto@ombulabs.com"]
spec.summary = "Strategies for cleaning databases using Neo4j. Can be used to ensure a clean state for testing."
spec.description = "Strategies for cleaning databases using Neo4j. Can be used to ensure a clean state for testing."
spec.homepage = "https://github.com/DatabaseCleaner/database_cleaner-neo4j"
spec.license = "MIT"
spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_dependency "database_cleaner", "~> 1.8.0"
spec.add_dependency "neo4j-core"
spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
end

View File

@ -0,0 +1 @@
require "database_cleaner/neo4j"

View File

@ -0,0 +1,6 @@
require "database_cleaner/neo4j/version"
require "database_cleaner"
require "database_cleaner/neo4j/transaction"
require "database_cleaner/neo4j/truncation"
require "database_cleaner/neo4j/deletion"

View File

@ -0,0 +1,62 @@
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 db_params
database.reject!{|key, value| [:type, :path].include? key }
end
def session
@session ||= ::Neo4j::Session.open(db_type, db_path, db_params)
end
end
end
end

View 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

View File

@ -0,0 +1,35 @@
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
if tx
tx.failure
tx.close
end
ensure
self.tx = nil
end
end
end
end

View 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

View File

@ -0,0 +1,5 @@
module DatabaseCleaner
module Neo4j
VERSION = "1.8.0"
end
end

View File

@ -0,0 +1,42 @@
require 'database_cleaner/neo4j/base'
require 'database_cleaner/spec'
module DatabaseCleaner
RSpec.describe Neo4j do
it { is_expected.to respond_to(:available_strategies) }
end
module Neo4j
class ExampleStrategy
include ::DatabaseCleaner::Neo4j::Base
end
RSpec.describe ExampleStrategy do
it_should_behave_like "a generic strategy"
it { is_expected.to respond_to(:db) }
it { is_expected.to respond_to(:db=) }
it "should store my describe db" do
db_conf = {:connection => {:type => :server_db, :path => 'http://localhost:7474'}}
subject.db = db_conf
expect(subject.db).to eq db_conf
end
it "should respect additional connection parameters" do
db_conf = {:type => :server_db, :path => 'http://localhost:7474', basic_auth: {username: 'user', password: 'pass'}}
subject.db = db_conf
expect(stub_const("Neo4j::Session", double())).to receive(:open).with(:server_db, 'http://localhost:7474', {basic_auth: {username: 'user', password: 'pass'}}) { true }
subject.start
end
it "should default to nil" do
expect(subject.db).to be_nil
end
it "should return default configuration" do
expect(subject.database).to eq(:type => :server_db, :path => 'http://localhost:7475/')
end
end
end
end

View File

@ -0,0 +1,25 @@
require 'neo4j-core'
require 'database_cleaner/neo4j/transaction'
require 'database_cleaner/spec'
module DatabaseCleaner
module Neo4j
RSpec.describe Transaction do
before(:all) do
DatabaseCleaner[:neo4j, :connection => {:type => :server_db, :path => 'http://localhost:7474'}]
end
it_should_behave_like "a generic strategy"
it_should_behave_like "a generic transaction strategy"
describe "start" do
it "should start a transaction"
end
describe "clean" do
it "should finish a transaction"
end
end
end
end

View File

@ -0,0 +1,14 @@
require "bundler/setup"
require "database_cleaner/neo4j"
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
config.expect_with :rspec do |c|
c.syntax = :expect
end
end

View File

@ -20,6 +20,9 @@ Feature: database cleaning
| DataMapper | truncation |
| Mongoid | truncation |
| MongoMapper | truncation |
| Neo4j | deletion |
| Neo4j | truncation |
| Neo4j | transaction |
Scenario Outline: ruby app
Given I am using <ORM>

View File

@ -17,6 +17,7 @@ Feature: database cleaning
| DataMapper |
| Mongoid |
| MongoMapper |
| Neo4j |
Scenario Outline: ruby app
Given I am using <ORM>

View File

@ -15,22 +15,32 @@ Feature: database cleaning using multiple ORMs
| ActiveRecord | DataMapper |
| ActiveRecord | Mongoid |
| ActiveRecord | MongoMapper |
| ActiveRecord | Neo4j |
| CouchPotato | ActiveRecord |
| CouchPotato | DataMapper |
| CouchPotato | Mongoid |
| CouchPotato | MongoMapper |
| CouchPotato | Neo4j |
| DataMapper | ActiveRecord |
| DataMapper | CouchPotato |
| DataMapper | Mongoid |
| DataMapper | MongoMapper |
| DataMapper | Neo4j |
| Mongoid | ActiveRecord |
| Mongoid | CouchPotato |
| Mongoid | DataMapper |
| Mongoid | MongoMapper |
| Mongoid | Neo4j |
| MongoMapper | ActiveRecord |
| MongoMapper | CouchPotato |
| MongoMapper | DataMapper |
| MongoMapper | Mongoid |
| MongoMapper | Neo4j |
| Neo4j | ActiveRecord |
| Neo4j | CouchPotato |
| Neo4j | DataMapper |
| Neo4j | Mongoid |
| Neo4j | MongoMapper |
Scenario Outline: ruby app
Given I am using <ORM1> and <ORM2>