diff --git a/Gemfile b/Gemfile index 968ed28..329ed8a 100644 --- a/Gemfile +++ b/Gemfile @@ -9,4 +9,5 @@ path "./adapters" do gem "database_cleaner-mongo_mapper" gem "database_cleaner-moped" gem "database_cleaner-neo4j" + gem "database_cleaner-ohm" end diff --git a/Gemfile.lock b/Gemfile.lock index 2f428c0..0efc4f1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -31,6 +31,10 @@ PATH database_cleaner-neo4j (1.8.0) database_cleaner (~> 1.8.0) neo4j-core + database_cleaner-ohm (1.8.0) + database_cleaner (~> 1.8.0) + database_cleaner-redis (~> 1.8.0) + ohm GEM remote: https://rubygems.org/ @@ -284,6 +288,7 @@ DEPENDENCIES database_cleaner-mongoid! database_cleaner-moped! database_cleaner-neo4j! + database_cleaner-ohm! datamapper dm-migrations dm-sqlite-adapter diff --git a/adapters/database_cleaner-ohm/.gitignore b/adapters/database_cleaner-ohm/.gitignore new file mode 100644 index 0000000..b04a8c8 --- /dev/null +++ b/adapters/database_cleaner-ohm/.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-ohm/.rspec b/adapters/database_cleaner-ohm/.rspec new file mode 100644 index 0000000..34c5164 --- /dev/null +++ b/adapters/database_cleaner-ohm/.rspec @@ -0,0 +1,3 @@ +--format documentation +--color +--require spec_helper diff --git a/adapters/database_cleaner-ohm/.travis.yml b/adapters/database_cleaner-ohm/.travis.yml new file mode 100644 index 0000000..0dc6355 --- /dev/null +++ b/adapters/database_cleaner-ohm/.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-ohm/Gemfile b/adapters/database_cleaner-ohm/Gemfile new file mode 100644 index 0000000..45f8ad4 --- /dev/null +++ b/adapters/database_cleaner-ohm/Gemfile @@ -0,0 +1,9 @@ +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +# Specify your gem's dependencies in database_cleaner-ohm.gemspec +gemspec + +gem "database_cleaner", path: "../.." +gem "database_cleaner-redis", path: ".." diff --git a/adapters/database_cleaner-ohm/Gemfile.lock b/adapters/database_cleaner-ohm/Gemfile.lock new file mode 100644 index 0000000..e806d80 --- /dev/null +++ b/adapters/database_cleaner-ohm/Gemfile.lock @@ -0,0 +1,57 @@ +PATH + remote: ../.. + specs: + database_cleaner (1.8.0) + +PATH + remote: .. + specs: + database_cleaner-redis (1.8.0) + database_cleaner (~> 1.8.0) + redis + +PATH + remote: . + specs: + database_cleaner-ohm (1.8.0) + database_cleaner (~> 1.8.0) + database_cleaner-redis (~> 1.8.0) + ohm + +GEM + remote: https://rubygems.org/ + specs: + diff-lcs (1.3) + nest (1.1.2) + redis + ohm (0.1.5) + nest (~> 1.0) + rake (10.4.2) + redis (3.1.0) + 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-ohm! + database_cleaner-redis! + rake (~> 10.0) + rspec (~> 3.0) + +BUNDLED WITH + 1.16.1 diff --git a/adapters/database_cleaner-ohm/LICENSE.txt b/adapters/database_cleaner-ohm/LICENSE.txt new file mode 100644 index 0000000..392bc0d --- /dev/null +++ b/adapters/database_cleaner-ohm/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-ohm/README.md b/adapters/database_cleaner-ohm/README.md new file mode 100644 index 0000000..a62b7c7 --- /dev/null +++ b/adapters/database_cleaner-ohm/README.md @@ -0,0 +1,39 @@ +# DatabaseCleaner::Ohm + +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/ohm`. 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-ohm' +``` + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install database_cleaner-ohm + +## 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-ohm. + +## 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-ohm/Rakefile b/adapters/database_cleaner-ohm/Rakefile new file mode 100644 index 0000000..b7e9ed5 --- /dev/null +++ b/adapters/database_cleaner-ohm/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-ohm/bin/console b/adapters/database_cleaner-ohm/bin/console new file mode 100755 index 0000000..fc6cccb --- /dev/null +++ b/adapters/database_cleaner-ohm/bin/console @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby + +require "bundler/setup" +require "database_cleaner/ohm" + +# 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-ohm/bin/setup b/adapters/database_cleaner-ohm/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/adapters/database_cleaner-ohm/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-ohm/database_cleaner-ohm.gemspec b/adapters/database_cleaner-ohm/database_cleaner-ohm.gemspec new file mode 100644 index 0000000..ad32c72 --- /dev/null +++ b/adapters/database_cleaner-ohm/database_cleaner-ohm.gemspec @@ -0,0 +1,31 @@ + +lib = File.expand_path("../lib", __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require "database_cleaner/ohm/version" + +Gem::Specification.new do |spec| + spec.name = "database_cleaner-ohm" + spec.version = DatabaseCleaner::Ohm::VERSION + spec.authors = ["Ernesto Tagwerker"] + spec.email = ["ernesto@ombulabs.com"] + + spec.summary = "Strategies for cleaning databases using Ohm. Can be used to ensure a clean state for testing." + spec.description = "Strategies for cleaning databases using Ohm. Can be used to ensure a clean state for testing." + spec.homepage = "https://github.com/DatabaseCleaner/database_cleaner-ohm" + 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 "database_cleaner-redis", "~> 1.8.0" + spec.add_dependency "ohm" + + spec.add_development_dependency "bundler", "~> 1.16" + spec.add_development_dependency "rake", "~> 10.0" + spec.add_development_dependency "rspec", "~> 3.0" +end diff --git a/adapters/database_cleaner-ohm/lib/database_cleaner-ohm.rb b/adapters/database_cleaner-ohm/lib/database_cleaner-ohm.rb new file mode 100644 index 0000000..59abca2 --- /dev/null +++ b/adapters/database_cleaner-ohm/lib/database_cleaner-ohm.rb @@ -0,0 +1 @@ +require "database_cleaner/ohm" diff --git a/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb b/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb new file mode 100644 index 0000000..e6fabce --- /dev/null +++ b/adapters/database_cleaner-ohm/lib/database_cleaner/ohm.rb @@ -0,0 +1,4 @@ +require "database_cleaner/ohm/version" +require "database_cleaner" +require "database_cleaner/ohm/truncation" + diff --git a/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/truncation.rb b/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/truncation.rb new file mode 100644 index 0000000..a0d0adf --- /dev/null +++ b/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/truncation.rb @@ -0,0 +1,19 @@ +require 'database_cleaner/redis/truncation' + +module DatabaseCleaner + module Ohm + def self.available_strategies + %w(truncation) + end + + class Truncation < ::DatabaseCleaner::Redis::Truncation + + private + + def default_redis + ::Ohm.redis + end + + end + end +end diff --git a/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb b/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb new file mode 100644 index 0000000..816dfd2 --- /dev/null +++ b/adapters/database_cleaner-ohm/lib/database_cleaner/ohm/version.rb @@ -0,0 +1,5 @@ +module DatabaseCleaner + module Ohm + VERSION = "1.8.0" + end +end diff --git a/adapters/database_cleaner-ohm/spec/database_cleaner/ohm/truncation_spec.rb b/adapters/database_cleaner-ohm/spec/database_cleaner/ohm/truncation_spec.rb new file mode 100644 index 0000000..32d4f17 --- /dev/null +++ b/adapters/database_cleaner-ohm/spec/database_cleaner/ohm/truncation_spec.rb @@ -0,0 +1,54 @@ +require 'ohm' +require 'database_cleaner/ohm/truncation' + +module OhmTests + class Widget < ::Ohm::Model + attribute :name + end + + class Gadget < ::Ohm::Model + attribute :name + end +end + +RSpec.describe DatabaseCleaner::Ohm::Truncation do + around do |example| + config = YAML::load(File.open("spec/support/redis.yml")) + Ohm.connect url: config['test']['url'] + @redis = Ohm.redis + + example.run + + @redis.flushdb + end + + before do + OhmTests::Widget.new(name: 'some widget').save + OhmTests::Gadget.new(name: 'some gadget').save + end + + context "by default" do + it "truncates all keys" do + expect { subject.clean }.to change { @redis.keys.size }.from(6).to(0) + end + end + + context "when keys are provided to the :only option" do + subject { described_class.new(only: ['*Widget*']) } + + it "only truncates the specified keys" do + expect { subject.clean }.to change { @redis.keys.size }.from(6).to(3) + expect(@redis.get('OhmTests::Gadget:id')).to eq '1' + end + end + + context "when keys are provided to the :except option" do + subject { described_class.new(except: ['*Widget*']) } + + it "truncates all but the specified keys" do + expect { subject.clean }.to change { @redis.keys.size }.from(6).to(3) + expect(@redis.get('OhmTests::Widget:id')).to eq '1' + end + end +end + diff --git a/adapters/database_cleaner-ohm/spec/spec_helper.rb b/adapters/database_cleaner-ohm/spec/spec_helper.rb new file mode 100644 index 0000000..d5af979 --- /dev/null +++ b/adapters/database_cleaner-ohm/spec/spec_helper.rb @@ -0,0 +1,14 @@ +require "bundler/setup" +require "database_cleaner/ohm" + +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/adapters/database_cleaner-ohm/spec/support/redis.yml b/adapters/database_cleaner-ohm/spec/support/redis.yml new file mode 100644 index 0000000..a3b6cba --- /dev/null +++ b/adapters/database_cleaner-ohm/spec/support/redis.yml @@ -0,0 +1,8 @@ +test: + url: 'redis://localhost:6379/0' + +one: + url: 'redis://localhost:6379/1' + +two: + url: 'redis://localhost:6379/2' diff --git a/features/cleaning.feature b/features/cleaning.feature index c81b745..2e0a4d7 100644 --- a/features/cleaning.feature +++ b/features/cleaning.feature @@ -23,6 +23,7 @@ Feature: database cleaning | Neo4j | deletion | | Neo4j | truncation | | Neo4j | transaction | + | Ohm | truncation | Scenario Outline: ruby app Given I am using diff --git a/features/cleaning_default_strategy.feature b/features/cleaning_default_strategy.feature index e75ba5a..c42c731 100644 --- a/features/cleaning_default_strategy.feature +++ b/features/cleaning_default_strategy.feature @@ -18,6 +18,7 @@ Feature: database cleaning | Mongoid | | MongoMapper | | Neo4j | + | Ohm | Scenario Outline: ruby app Given I am using diff --git a/features/cleaning_multiple_orms.feature b/features/cleaning_multiple_orms.feature index e34d632..2e5d944 100644 --- a/features/cleaning_multiple_orms.feature +++ b/features/cleaning_multiple_orms.feature @@ -16,31 +16,43 @@ Feature: database cleaning using multiple ORMs | ActiveRecord | Mongoid | | ActiveRecord | MongoMapper | | ActiveRecord | Neo4j | + | ActiveRecord | Ohm | | CouchPotato | ActiveRecord | | CouchPotato | DataMapper | | CouchPotato | Mongoid | | CouchPotato | MongoMapper | | CouchPotato | Neo4j | + | CouchPotato | Ohm | | DataMapper | ActiveRecord | | DataMapper | CouchPotato | | DataMapper | Mongoid | | DataMapper | MongoMapper | | DataMapper | Neo4j | + | DataMapper | Ohm | | Mongoid | ActiveRecord | | Mongoid | CouchPotato | | Mongoid | DataMapper | | Mongoid | MongoMapper | | Mongoid | Neo4j | + | Mongoid | Ohm | | MongoMapper | ActiveRecord | | MongoMapper | CouchPotato | | MongoMapper | DataMapper | | MongoMapper | Mongoid | | MongoMapper | Neo4j | + | MongoMapper | Ohm | | Neo4j | ActiveRecord | | Neo4j | CouchPotato | | Neo4j | DataMapper | | Neo4j | Mongoid | | Neo4j | MongoMapper | + | Neo4j | Ohm | + | Ohm | ActiveRecord | + | Ohm | CouchPotato | + | Ohm | DataMapper | + | Ohm | Mongoid | + | Ohm | MongoMapper | + | Ohm | Neo4j | Scenario Outline: ruby app Given I am using and