diff --git a/Gemfile b/Gemfile index 1602505..6d16371 100644 --- a/Gemfile +++ b/Gemfile @@ -2,4 +2,5 @@ gemspec path "./adapters" do gem "database_cleaner-active_record" + gem "database_cleaner-couch_potato" end diff --git a/Gemfile.lock b/Gemfile.lock index 0348df4..ad08d6a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/adapters/database_cleaner-active_record/database_cleaner-active_record.gemspec b/adapters/database_cleaner-active_record/database_cleaner-active_record.gemspec index 78bb872..2b0d6d7 100644 --- a/adapters/database_cleaner-active_record/database_cleaner-active_record.gemspec +++ b/adapters/database_cleaner-active_record/database_cleaner-active_record.gemspec @@ -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 diff --git a/adapters/database_cleaner-couch_potato/.gitignore b/adapters/database_cleaner-couch_potato/.gitignore new file mode 100644 index 0000000..b04a8c8 --- /dev/null +++ b/adapters/database_cleaner-couch_potato/.gitignore @@ -0,0 +1,11 @@ +/.bundle/ +/.yardoc +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ + +# rspec failure tracking +.rspec_status diff --git a/adapters/database_cleaner-couch_potato/.rspec b/adapters/database_cleaner-couch_potato/.rspec new file mode 100644 index 0000000..34c5164 --- /dev/null +++ b/adapters/database_cleaner-couch_potato/.rspec @@ -0,0 +1,3 @@ +--format documentation +--color +--require spec_helper diff --git a/adapters/database_cleaner-couch_potato/.travis.yml b/adapters/database_cleaner-couch_potato/.travis.yml new file mode 100644 index 0000000..0dc6355 --- /dev/null +++ b/adapters/database_cleaner-couch_potato/.travis.yml @@ -0,0 +1,5 @@ +sudo: false +language: ruby +rvm: + - 2.2.9 +before_install: gem install bundler -v 1.16.1 diff --git a/adapters/database_cleaner-couch_potato/Gemfile b/adapters/database_cleaner-couch_potato/Gemfile new file mode 100644 index 0000000..c426b92 --- /dev/null +++ b/adapters/database_cleaner-couch_potato/Gemfile @@ -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: "../.." diff --git a/adapters/database_cleaner-couch_potato/Gemfile.lock b/adapters/database_cleaner-couch_potato/Gemfile.lock new file mode 100644 index 0000000..e6b05ed --- /dev/null +++ b/adapters/database_cleaner-couch_potato/Gemfile.lock @@ -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 diff --git a/adapters/database_cleaner-couch_potato/LICENSE.txt b/adapters/database_cleaner-couch_potato/LICENSE.txt new file mode 100644 index 0000000..392bc0d --- /dev/null +++ b/adapters/database_cleaner-couch_potato/LICENSE.txt @@ -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. diff --git a/adapters/database_cleaner-couch_potato/README.md b/adapters/database_cleaner-couch_potato/README.md new file mode 100644 index 0000000..0337074 --- /dev/null +++ b/adapters/database_cleaner-couch_potato/README.md @@ -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). diff --git a/adapters/database_cleaner-couch_potato/Rakefile b/adapters/database_cleaner-couch_potato/Rakefile new file mode 100644 index 0000000..b7e9ed5 --- /dev/null +++ b/adapters/database_cleaner-couch_potato/Rakefile @@ -0,0 +1,6 @@ +require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) + +task :default => :spec diff --git a/adapters/database_cleaner-couch_potato/bin/console b/adapters/database_cleaner-couch_potato/bin/console new file mode 100755 index 0000000..5f181ad --- /dev/null +++ b/adapters/database_cleaner-couch_potato/bin/console @@ -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__) diff --git a/adapters/database_cleaner-couch_potato/bin/setup b/adapters/database_cleaner-couch_potato/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/adapters/database_cleaner-couch_potato/bin/setup @@ -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 diff --git a/adapters/database_cleaner-couch_potato/database_cleaner-couch_potato.gemspec b/adapters/database_cleaner-couch_potato/database_cleaner-couch_potato.gemspec new file mode 100644 index 0000000..1b2f132 --- /dev/null +++ b/adapters/database_cleaner-couch_potato/database_cleaner-couch_potato.gemspec @@ -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 diff --git a/adapters/database_cleaner-couch_potato/lib/database_cleaner-couch_potato.rb b/adapters/database_cleaner-couch_potato/lib/database_cleaner-couch_potato.rb new file mode 100644 index 0000000..c407d56 --- /dev/null +++ b/adapters/database_cleaner-couch_potato/lib/database_cleaner-couch_potato.rb @@ -0,0 +1 @@ +require "database_cleaner/couch_potato" diff --git a/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato.rb b/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato.rb new file mode 100644 index 0000000..92c3c81 --- /dev/null +++ b/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato.rb @@ -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" + diff --git a/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/base.rb b/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/base.rb new file mode 100644 index 0000000..b53a52a --- /dev/null +++ b/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/base.rb @@ -0,0 +1,7 @@ +module DatabaseCleaner + module CouchPotato + def self.available_strategies + %w[truncation] + end + end +end diff --git a/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/truncation.rb b/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/truncation.rb new file mode 100644 index 0000000..5a163aa --- /dev/null +++ b/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/truncation.rb @@ -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 diff --git a/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/version.rb b/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/version.rb new file mode 100644 index 0000000..03a54d8 --- /dev/null +++ b/adapters/database_cleaner-couch_potato/lib/database_cleaner/couch_potato/version.rb @@ -0,0 +1,5 @@ +module DatabaseCleaner + module CouchPotato + VERSION = "1.8.0" + end +end diff --git a/adapters/database_cleaner-couch_potato/spec/database_cleaner/couch_potato/truncation_spec.rb b/adapters/database_cleaner-couch_potato/spec/database_cleaner/couch_potato/truncation_spec.rb new file mode 100644 index 0000000..8f4360a --- /dev/null +++ b/adapters/database_cleaner-couch_potato/spec/database_cleaner/couch_potato/truncation_spec.rb @@ -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 diff --git a/adapters/database_cleaner-couch_potato/spec/spec_helper.rb b/adapters/database_cleaner-couch_potato/spec/spec_helper.rb new file mode 100644 index 0000000..1cd4ded --- /dev/null +++ b/adapters/database_cleaner-couch_potato/spec/spec_helper.rb @@ -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 diff --git a/features/cleaning.feature b/features/cleaning.feature index 6402d52..b3ed9c1 100644 --- a/features/cleaning.feature +++ b/features/cleaning.feature @@ -15,6 +15,7 @@ Feature: database cleaning | ActiveRecord | transaction | | ActiveRecord | truncation | | ActiveRecord | deletion | + | CouchPotato | truncation | Scenario Outline: ruby app Given I am using diff --git a/features/cleaning_default_strategy.feature b/features/cleaning_default_strategy.feature index 4389d50..3e63964 100644 --- a/features/cleaning_default_strategy.feature +++ b/features/cleaning_default_strategy.feature @@ -13,6 +13,7 @@ Feature: database cleaning Examples: | ORM | | ActiveRecord | + | CouchPotato | Scenario Outline: ruby app Given I am using diff --git a/features/cleaning_multiple_orms.feature b/features/cleaning_multiple_orms.feature index 1c8375b..4900a8c 100644 --- a/features/cleaning_multiple_orms.feature +++ b/features/cleaning_multiple_orms.feature @@ -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 and from their adapter gems + Scenario Outline: ruby app with adapter gems + Given I am using and 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 and