extract database_cleaner-couch_potato adapter.

This commit is contained in:
Micah Geisel 2018-05-25 20:12:59 -07:00
parent 50d19efd25
commit 84d4c23bc2
24 changed files with 327 additions and 7 deletions

View File

@ -2,4 +2,5 @@ gemspec
path "./adapters" do
gem "database_cleaner-active_record"
gem "database_cleaner-couch_potato"
end

View File

@ -9,6 +9,9 @@ PATH
database_cleaner-active_record (1.8.0)
activerecord
database_cleaner (~> 1.8.0)
database_cleaner-couch_potato (1.8.0)
couch_potato
database_cleaner (~> 1.8.0)
GEM
remote: https://rubygems.org/
@ -255,6 +258,7 @@ DEPENDENCIES
cucumber
database_cleaner!
database_cleaner-active_record!
database_cleaner-couch_potato!
datamapper
dm-migrations
dm-sqlite-adapter

View File

@ -27,15 +27,13 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "cucumber"
unless RUBY_PLATFORM =~ /java/
spec.add_development_dependency 'mysql', '~> 2.9.1'
spec.add_development_dependency 'mysql2'
spec.add_development_dependency "activerecord-mysql2-adapter"
spec.add_development_dependency 'pg'
spec.add_development_dependency "sqlite3-ruby" if RUBY_VERSION < "1.9"
spec.add_development_dependency "sqlite3" if RUBY_VERSION >= "1.9"
spec.add_development_dependency "sqlite3"
else
spec.add_development_dependency "activerecord-jdbc-adapter"
end

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

View File

@ -0,0 +1,65 @@
PATH
remote: ../..
specs:
database_cleaner (1.8.0)
PATH
remote: .
specs:
database_cleaner-couch_potato (1.8.0)
couch_potato
database_cleaner (~> 1.8.0)
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)
builder (2.1.2)
couch_potato (1.3.0)
activemodel
couchrest (~> 1.2.0)
json (~> 1.6)
couchrest (1.2.0)
mime-types (~> 1.15)
multi_json (~> 1.0)
rest-client (~> 1.6.1)
diff-lcs (1.3)
i18n (0.4.2)
json (1.8.6)
mime-types (1.25.1)
multi_json (1.2.0)
rake (10.4.2)
rdoc (4.2.0)
rest-client (1.6.8)
mime-types (~> 1.16)
rdoc (>= 2.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-couch_potato!
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::CouchPotato
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/couch_potato`. 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-couch_potato'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install database_cleaner-couch_potato
## 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-couch_potato.
## 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/couch_potato"
# 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/couch_potato/version"
Gem::Specification.new do |spec|
spec.name = "database_cleaner-couch_potato"
spec.version = DatabaseCleaner::CouchPotato::VERSION
spec.authors = ["Ernesto Tagwerker"]
spec.email = ["ernesto@ombulabs.com"]
spec.summary = "Strategies for cleaning databases using CouchPotato. Can be used to ensure a clean state for testing."
spec.description = "Strategies for cleaning databases using CouchPotato. Can be used to ensure a clean state for testing."
spec.homepage = "https://github.com/DatabaseCleaner/database_cleaner-couch_potato"
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 "couch_potato"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "rspec", "~> 3.0"
end

View File

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

View File

@ -0,0 +1,5 @@
require "database_cleaner/couch_potato/version"
require "database_cleaner"
require "database_cleaner/couch_potato/base"
require "database_cleaner/couch_potato/truncation"

View File

@ -0,0 +1,7 @@
module DatabaseCleaner
module CouchPotato
def self.available_strategies
%w[truncation]
end
end
end

View File

@ -0,0 +1,28 @@
require 'database_cleaner/generic/truncation'
module DatabaseCleaner
module CouchPotato
class Truncation
include ::DatabaseCleaner::Generic::Truncation
def initialize(options = {})
if options.has_key?(:only) || options.has_key?(:except)
raise ArgumentError, "The :only and :except options are not available for use with CouchPotato/CouchDB."
elsif !options.empty?
raise ArgumentError, "Unsupported option. You specified #{options.keys.join(',')}."
end
super
end
def clean
database.recreate!
end
private
def database
::CouchPotato.couchrest_database
end
end
end
end

View File

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

View File

@ -0,0 +1,40 @@
require 'database_cleaner/couch_potato/truncation'
require 'couch_potato'
module DatabaseCleaner
module CouchPotato
RSpec.describe Truncation do
let(:database) { double('database') }
before(:each) do
allow(::CouchPotato).to receive(:couchrest_database).and_return(database)
end
it "should re-create the database" do
expect(database).to receive(:recreate!)
Truncation.new.clean
end
it "should raise an error when the :only option is used" do
expect {
Truncation.new(:only => ['document-type'])
}.to raise_error(ArgumentError)
end
it "should raise an error when the :except option is used" do
expect {
Truncation.new(:except => ['document-type'])
}.to raise_error(ArgumentError)
end
it "should raise an error when invalid options are provided" do
expect {
Truncation.new(:foo => 'bar')
}.to raise_error(ArgumentError)
end
end
end
end

View File

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

@ -15,6 +15,7 @@ Feature: database cleaning
| ActiveRecord | transaction |
| ActiveRecord | truncation |
| ActiveRecord | deletion |
| CouchPotato | truncation |
Scenario Outline: ruby app
Given I am using <ORM>

View File

@ -13,6 +13,7 @@ Feature: database cleaning
Examples:
| ORM |
| ActiveRecord |
| CouchPotato |
Scenario Outline: ruby app
Given I am using <ORM>

View File

@ -3,11 +3,16 @@ Feature: database cleaning using multiple ORMs
As a developer
I want to have my database in a clean state
# Scenario Outline: ruby app with adapter gems
# Given I am using <ORM1> and <ORM2> from their adapter gems
Scenario Outline: ruby app with adapter gems
Given I am using <ORM1> and <ORM2> from their adapter gems
# When I run my scenarios that rely on clean databases using multiple orms
# Then I should see all green
When I run my scenarios that rely on clean databases using multiple orms
Then I should see all green
Examples:
| ORM1 | ORM2 |
| ActiveRecord | CouchPotato |
| CouchPotato | ActiveRecord |
Scenario Outline: ruby app
Given I am using <ORM1> and <ORM2>