extract database_cleaner-mongo_mapper adapter.

This commit is contained in:
Micah Geisel 2018-05-25 23:48:30 -07:00
parent 07f84e9b72
commit 3c9b4c1a41
26 changed files with 374 additions and 0 deletions

View File

@ -6,4 +6,5 @@ path "./adapters" do
gem "database_cleaner-data_mapper"
gem "database_cleaner-mongo"
gem "database_cleaner-mongoid"
gem "database_cleaner-mongo_mapper"
end

View File

@ -18,6 +18,9 @@ PATH
database_cleaner-mongo (1.8.0)
database_cleaner (~> 1.8.0)
mongo
database_cleaner-mongo_mapper (0.1.0)
database_cleaner (~> 1.8.0)
mongo_mapper
database_cleaner-mongoid (1.8.0)
database_cleaner (~> 1.8.0)
database_cleaner-mongo (~> 1.8.0)
@ -271,6 +274,7 @@ DEPENDENCIES
database_cleaner-couch_potato!
database_cleaner-data_mapper!
database_cleaner-mongo!
database_cleaner-mongo_mapper!
database_cleaner-mongoid!
datamapper
dm-migrations

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-mongo_mapper.gemspec
gemspec
gem "database_cleaner", path: "../.."

View File

@ -0,0 +1,59 @@
PATH
remote: ../..
specs:
database_cleaner (1.8.0)
PATH
remote: .
specs:
database_cleaner-mongo_mapper (0.1.0)
database_cleaner (~> 1.8.0)
mongo_mapper
GEM
remote: https://rubygems.org/
specs:
activemodel (3.0.0)
activesupport (= 3.0.0)
builder (~> 2.1.2)
i18n (~> 0.4.1)
activesupport (3.0.0)
bson (1.12.5)
builder (2.1.2)
diff-lcs (1.3)
i18n (0.4.2)
mongo (1.12.5)
bson (= 1.12.5)
mongo_mapper (0.12.0)
activemodel (~> 3.0)
activesupport (~> 3.0)
plucky (~> 0.5.2)
plucky (0.5.2)
mongo (~> 1.5)
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)
PLATFORMS
ruby
DEPENDENCIES
bundler (~> 1.16)
database_cleaner!
database_cleaner-mongo_mapper!
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::MongoMapper
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/mongo_mapper`. 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-mongo_mapper'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install database_cleaner-mongo_mapper
## 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-mongo_mapper.
## 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/mongo_mapper"
# 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/mongo_mapper/version"
Gem::Specification.new do |spec|
spec.name = "database_cleaner-mongo_mapper"
spec.version = DatabaseCleaner::MongoMapper::VERSION
spec.authors = ["Ernesto Tagwerker"]
spec.email = ["ernesto@ombulabs.com"]
spec.summary = "Strategies for cleaning databases using MongoMapper. Can be used to ensure a clean state for testing."
spec.description = "Strategies for cleaning databases using MongoMapper. Can be used to ensure a clean state for testing."
spec.homepage = "https://github.com/DatabaseCleaner/database_cleaner-mongo_mapper"
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 "mongo_mapper"
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/mongo_mapper"

View File

@ -0,0 +1,4 @@
require "database_cleaner/mongo_mapper/version"
require "database_cleaner"
require "database_cleaner/mongo_mapper/truncation"

View File

@ -0,0 +1,20 @@
require 'database_cleaner/generic/base'
module DatabaseCleaner
module MongoMapper
def self.available_strategies
%w[truncation]
end
module Base
include ::DatabaseCleaner::Generic::Base
def db=(desired_db)
@db = desired_db
end
def db
@db ||= :default
end
end
end
end

View File

@ -0,0 +1,19 @@
require 'database_cleaner/mongo_mapper/base'
require 'database_cleaner/generic/truncation'
require 'database_cleaner/mongo/truncation_mixin'
module DatabaseCleaner
module MongoMapper
class Truncation
include ::DatabaseCleaner::MongoMapper::Base
include ::DatabaseCleaner::Generic::Truncation
include ::DatabaseCleaner::Mongo::TruncationMixin
private
def database
::MongoMapper.database
end
end
end
end

View File

@ -0,0 +1,5 @@
module DatabaseCleaner
module MongoMapper
VERSION = "0.1.0"
end
end

View File

@ -0,0 +1,32 @@
require 'database_cleaner/mongo_mapper/base'
require 'database_cleaner/spec'
module DatabaseCleaner
RSpec.describe MongoMapper do
it { is_expected.to respond_to(:available_strategies) }
end
module MongoMapper
class ExampleStrategy
include ::DatabaseCleaner::MongoMapper::Base
end
RSpec.describe ExampleStrategy do
it_should_behave_like "a generic strategy"
describe "db" do
it { is_expected.to respond_to(:db=) }
it "should store my desired db" do
subject.db = :my_db
expect(subject.db).to eq :my_db
end
it "should default to :default" do
expect(subject.db).to eq :default
end
end
end
end
end

View File

@ -0,0 +1,10 @@
module MongoMapperTest
class Widget
include ::MongoMapper::Document
key :name, String
end
class Gadget
include ::MongoMapper::Document
key :name, String
end
end

View File

@ -0,0 +1,49 @@
require 'mongo_mapper'
require 'database_cleaner/mongo_mapper/truncation'
require File.dirname(__FILE__) + '/mongo_examples'
RSpec.describe DatabaseCleaner::MongoMapper::Truncation do
around do |example|
MongoMapper.connection = Mongo::Connection.new('127.0.0.1')
db_name = 'database_cleaner_specs'
MongoMapper.database = db_name
example.run
MongoMapper.connection.drop_database(db_name)
end
before do
MongoMapperTest::Widget.new(name: 'some widget').save!
MongoMapperTest::Gadget.new(name: 'some gadget').save!
end
context "by default" do
it "truncates all collections" do
expect { subject.clean }.to change {
[MongoMapperTest::Widget.count, MongoMapperTest::Gadget.count]
}.from([1,1]).to([0,0])
end
end
context "when collections are provided to the :only option" do
subject { described_class.new(only: ['mongo_mapper_test.widgets']) }
it "only truncates the specified collections" do
expect { subject.clean }.to change {
[MongoMapperTest::Widget.count, MongoMapperTest::Gadget.count]
}.from([1,1]).to([0,1])
end
end
context "when collections are provided to the :except option" do
subject { described_class.new(except: ['mongo_mapper_test.widgets']) }
it "truncates all but the specified collections" do
expect { subject.clean }.to change {
[MongoMapperTest::Widget.count, MongoMapperTest::Gadget.count]
}.from([1,1]).to([1,0])
end
end
end

View File

@ -0,0 +1,14 @@
require "bundler/setup"
require "database_cleaner/mongo_mapper"
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

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

View File

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

View File

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

View File

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