diff --git a/Gemfile b/Gemfile index 6d16371..2416d81 100644 --- a/Gemfile +++ b/Gemfile @@ -3,4 +3,5 @@ gemspec path "./adapters" do gem "database_cleaner-active_record" gem "database_cleaner-couch_potato" + gem "database_cleaner-data_mapper" end diff --git a/Gemfile.lock b/Gemfile.lock index ad08d6a..0da4202 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,6 +12,9 @@ PATH database_cleaner-couch_potato (1.8.0) couch_potato database_cleaner (~> 1.8.0) + database_cleaner-data_mapper (1.8.0) + database_cleaner (~> 1.8.0) + datamapper GEM remote: https://rubygems.org/ @@ -259,6 +262,7 @@ DEPENDENCIES database_cleaner! database_cleaner-active_record! database_cleaner-couch_potato! + database_cleaner-data_mapper! datamapper dm-migrations dm-sqlite-adapter diff --git a/adapters/database_cleaner-data_mapper/.gitignore b/adapters/database_cleaner-data_mapper/.gitignore new file mode 100644 index 0000000..a2164d5 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/.gitignore @@ -0,0 +1,13 @@ +/.bundle/ +/.yardoc +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/spec/support/config.yml +/tmp/ +!/tmp/.keep + +# rspec failure tracking +.rspec_status diff --git a/adapters/database_cleaner-data_mapper/.rspec b/adapters/database_cleaner-data_mapper/.rspec new file mode 100644 index 0000000..34c5164 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/.rspec @@ -0,0 +1,3 @@ +--format documentation +--color +--require spec_helper diff --git a/adapters/database_cleaner-data_mapper/.travis.yml b/adapters/database_cleaner-data_mapper/.travis.yml new file mode 100644 index 0000000..0dc6355 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/.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-data_mapper/Gemfile b/adapters/database_cleaner-data_mapper/Gemfile new file mode 100644 index 0000000..10d5f58 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/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-data_mapper.gemspec +gemspec + +gem "database_cleaner", path: "../.." diff --git a/adapters/database_cleaner-data_mapper/Gemfile.lock b/adapters/database_cleaner-data_mapper/Gemfile.lock new file mode 100644 index 0000000..b5ba80d --- /dev/null +++ b/adapters/database_cleaner-data_mapper/Gemfile.lock @@ -0,0 +1,103 @@ +PATH + remote: ../.. + specs: + database_cleaner (1.8.0) + +PATH + remote: . + specs: + database_cleaner-data_mapper (1.8.0) + database_cleaner (~> 1.8.0) + datamapper + +GEM + remote: https://rubygems.org/ + specs: + addressable (2.3.6) + bcrypt (3.1.7) + bcrypt-ruby (3.1.5) + bcrypt (>= 3.1.3) + data_objects (0.10.14) + addressable (~> 2.1) + datamapper (1.2.0) + dm-aggregates (~> 1.2.0) + dm-constraints (~> 1.2.0) + dm-core (~> 1.2.0) + dm-migrations (~> 1.2.0) + dm-serializer (~> 1.2.0) + dm-timestamps (~> 1.2.0) + dm-transactions (~> 1.2.0) + dm-types (~> 1.2.0) + dm-validations (~> 1.2.0) + diff-lcs (1.3) + dm-aggregates (1.2.0) + dm-core (~> 1.2.0) + dm-constraints (1.2.0) + dm-core (~> 1.2.0) + dm-core (1.2.1) + addressable (~> 2.3) + dm-do-adapter (1.2.0) + data_objects (~> 0.10.6) + dm-core (~> 1.2.0) + dm-migrations (1.2.0) + dm-core (~> 1.2.0) + dm-serializer (1.2.2) + dm-core (~> 1.2.0) + fastercsv (~> 1.5) + json (~> 1.6) + json_pure (~> 1.6) + multi_json (~> 1.0) + dm-sqlite-adapter (1.2.0) + dm-do-adapter (~> 1.2.0) + do_sqlite3 (~> 0.10.6) + dm-timestamps (1.2.0) + dm-core (~> 1.2.0) + dm-transactions (1.2.0) + dm-core (~> 1.2.0) + dm-types (1.2.2) + bcrypt-ruby (~> 3.0) + dm-core (~> 1.2.0) + fastercsv (~> 1.5) + json (~> 1.6) + multi_json (~> 1.0) + stringex (~> 1.4) + uuidtools (~> 2.1) + dm-validations (1.2.0) + dm-core (~> 1.2.0) + do_sqlite3 (0.10.14) + data_objects (= 0.10.14) + fastercsv (1.5.5) + json (1.8.6) + json_pure (1.8.1) + multi_json (1.2.0) + 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) + stringex (1.5.1) + uuidtools (2.1.5) + +PLATFORMS + ruby + +DEPENDENCIES + bundler (~> 1.16) + database_cleaner! + database_cleaner-data_mapper! + dm-migrations + dm-sqlite-adapter + rake (~> 10.0) + rspec (~> 3.0) + +BUNDLED WITH + 1.16.1 diff --git a/adapters/database_cleaner-data_mapper/LICENSE.txt b/adapters/database_cleaner-data_mapper/LICENSE.txt new file mode 100644 index 0000000..392bc0d --- /dev/null +++ b/adapters/database_cleaner-data_mapper/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-data_mapper/README.md b/adapters/database_cleaner-data_mapper/README.md new file mode 100644 index 0000000..f25366f --- /dev/null +++ b/adapters/database_cleaner-data_mapper/README.md @@ -0,0 +1,39 @@ +# DatabaseCleaner::DataMapper + +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/data_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-data_mapper' +``` + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install database_cleaner-data_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-data_mapper. + +## 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-data_mapper/Rakefile b/adapters/database_cleaner-data_mapper/Rakefile new file mode 100644 index 0000000..b7e9ed5 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/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-data_mapper/bin/console b/adapters/database_cleaner-data_mapper/bin/console new file mode 100755 index 0000000..66190aa --- /dev/null +++ b/adapters/database_cleaner-data_mapper/bin/console @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby + +require "bundler/setup" +require "database_cleaner/data_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__) diff --git a/adapters/database_cleaner-data_mapper/bin/setup b/adapters/database_cleaner-data_mapper/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/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-data_mapper/database_cleaner-data_mapper.gemspec b/adapters/database_cleaner-data_mapper/database_cleaner-data_mapper.gemspec new file mode 100644 index 0000000..55dceac --- /dev/null +++ b/adapters/database_cleaner-data_mapper/database_cleaner-data_mapper.gemspec @@ -0,0 +1,33 @@ + +lib = File.expand_path("../lib", __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require "database_cleaner/data_mapper/version" + +Gem::Specification.new do |spec| + spec.name = "database_cleaner-data_mapper" + spec.version = DatabaseCleaner::DataMapper::VERSION + spec.authors = ["Ernesto Tagwerker"] + spec.email = ["ernesto@ombulabs.com"] + + spec.summary = "Strategies for cleaning databases using DataMapper. Can be used to ensure a clean state for testing." + spec.description = "Strategies for cleaning databases using DataMapper. Can be used to ensure a clean state for testing." + spec.homepage = "https://github.com/DatabaseCleaner/database_cleaner-data_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 "datamapper" + + 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 "dm-sqlite-adapter" + # spec.add_development_dependency "dm-migrations" +end diff --git a/adapters/database_cleaner-data_mapper/lib/database_cleaner-data_mapper.rb b/adapters/database_cleaner-data_mapper/lib/database_cleaner-data_mapper.rb new file mode 100644 index 0000000..0be5186 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/lib/database_cleaner-data_mapper.rb @@ -0,0 +1 @@ +require "database_cleaner/data_mapper" diff --git a/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper.rb b/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper.rb new file mode 100644 index 0000000..26af40e --- /dev/null +++ b/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper.rb @@ -0,0 +1,4 @@ +require "database_cleaner/data_mapper/version" +require "database_cleaner" +require "database_cleaner/data_mapper/transaction" +require "database_cleaner/data_mapper/truncation" diff --git a/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/base.rb b/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/base.rb new file mode 100644 index 0000000..64a303c --- /dev/null +++ b/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/base.rb @@ -0,0 +1,21 @@ +require 'database_cleaner/generic/base' +module DatabaseCleaner + module DataMapper + def self.available_strategies + %w[truncation transaction] + end + + module Base + include ::DatabaseCleaner::Generic::Base + + def db=(desired_db) + @db = desired_db + end + + def db + @db ||= :default + end + + end + end +end diff --git a/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/transaction.rb b/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/transaction.rb new file mode 100644 index 0000000..31b3287 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/transaction.rb @@ -0,0 +1,28 @@ +require 'database_cleaner/data_mapper/base' +require 'database_cleaner/generic/transaction' + +module DatabaseCleaner::DataMapper + class Transaction + include ::DatabaseCleaner::DataMapper::Base + include ::DatabaseCleaner::Generic::Transaction + + def start(repository = self.db) + ::DataMapper.repository(repository) do |r| + transaction = DataMapper::Transaction.new(r) + transaction.begin + r.adapter.push_transaction(transaction) + end + end + + def clean(repository = self.db) + ::DataMapper.repository(repository) do |r| + adapter = r.adapter + while adapter.current_transaction + adapter.current_transaction.rollback + adapter.pop_transaction + end + end + end + + end +end diff --git a/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/truncation.rb b/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/truncation.rb new file mode 100644 index 0000000..06a7439 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/truncation.rb @@ -0,0 +1,173 @@ +require "database_cleaner/generic/truncation" +require 'database_cleaner/data_mapper/base' +require 'data_mapper' + +module DataMapper + module Adapters + + class DataObjectsAdapter + + def storage_names(repository = :default) + raise NotImplementedError + end + + def truncate_tables(table_names) + table_names.each do |table_name| + truncate_table table_name + end + end + + end + + class MysqlAdapter < DataObjectsAdapter + + # taken from http://github.com/godfat/dm-mapping/tree/master + def storage_names(repository = :default) + select 'SHOW TABLES' + end + + def truncate_table(table_name) + execute("TRUNCATE TABLE #{quote_name(table_name)};") + end + + # copied from activerecord + def disable_referential_integrity + old = select("SELECT @@FOREIGN_KEY_CHECKS;") + begin + execute("SET FOREIGN_KEY_CHECKS = 0;") + yield + ensure + execute("SET FOREIGN_KEY_CHECKS = ?", *old) + end + end + + end + + module SqliteAdapterMethods + + # taken from http://github.com/godfat/dm-mapping/tree/master + def storage_names(repository = :default) + # activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 177 + sql = <<-SQL + SELECT name + FROM sqlite_master + WHERE type = 'table' AND NOT name = 'sqlite_sequence' + SQL + # activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 181 + select(sql) + end + + def truncate_table(table_name) + execute("DELETE FROM #{quote_name(table_name)};") + if uses_sequence? + execute("DELETE FROM sqlite_sequence where name = '#{table_name}';") + end + end + + # this is a no-op copied from activerecord + # i didn't find out if/how this is possible + # activerecord also doesn't do more here + def disable_referential_integrity + yield + end + + private + + # Returns a boolean indicating if the SQLite database is using the sqlite_sequence table. + def uses_sequence? + sql = <<-SQL + SELECT name FROM sqlite_master + WHERE type='table' AND name='sqlite_sequence' + SQL + select(sql).first + end + end + + class SqliteAdapter; include SqliteAdapterMethods; end + class Sqlite3Adapter; include SqliteAdapterMethods; end + + # FIXME + # i don't know if this works + # i basically just copied activerecord code to get a rough idea what they do. + # i don't have postgres available, so i won't be the one to write this. + # maybe codes below gets some postgres/datamapper user going, though. + class PostgresAdapter < DataObjectsAdapter + + # taken from http://github.com/godfat/dm-mapping/tree/master + def storage_names(repository = :default) + sql = <<-SQL + SELECT table_name FROM "information_schema"."tables" + WHERE table_schema = current_schema() and table_type = 'BASE TABLE' + SQL + select(sql) + end + + def truncate_table(table_name) + execute("TRUNCATE TABLE #{quote_name(table_name)} RESTART IDENTITY CASCADE;") + end + + # override to use a single statement + def truncate_tables(table_names) + quoted_names = table_names.collect { |n| quote_name(n) }.join(', ') + execute("TRUNCATE TABLE #{quoted_names} RESTART IDENTITY;") + end + + # FIXME + # copied from activerecord + def supports_disable_referential_integrity? + version = select("SHOW server_version")[0][0].split('.') + (version[0].to_i >= 8 && version[1].to_i >= 1) ? true : false + rescue + return false + end + + # FIXME + # copied unchanged from activerecord + def disable_referential_integrity(repository = :default) + if supports_disable_referential_integrity? then + execute(storage_names(repository).collect do |name| + "ALTER TABLE #{quote_name(name)} DISABLE TRIGGER ALL" + end.join(";")) + end + yield + ensure + if supports_disable_referential_integrity? then + execute(storage_names(repository).collect do |name| + "ALTER TABLE #{quote_name(name)} ENABLE TRIGGER ALL" + end.join(";")) + end + end + + end + + end +end + + +module DatabaseCleaner + module DataMapper + class Truncation + include ::DatabaseCleaner::DataMapper::Base + include ::DatabaseCleaner::Generic::Truncation + + def clean(repository = self.db) + adapter = ::DataMapper.repository(repository).adapter + adapter.disable_referential_integrity do + adapter.truncate_tables(tables_to_truncate(repository)) + end + end + + private + + def tables_to_truncate(repository = self.db) + (@only || ::DataMapper.repository(repository).adapter.storage_names(repository)) - @tables_to_exclude + end + + # overwritten + def migration_storage_names + %w[migration_info] + end + + end + end +end diff --git a/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/version.rb b/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/version.rb new file mode 100644 index 0000000..222e161 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/lib/database_cleaner/data_mapper/version.rb @@ -0,0 +1,5 @@ +module DatabaseCleaner + module DataMapper + VERSION = "1.8.0" + end +end diff --git a/adapters/database_cleaner-data_mapper/spec/database_cleaner/data_mapper/base_spec.rb b/adapters/database_cleaner-data_mapper/spec/database_cleaner/data_mapper/base_spec.rb new file mode 100644 index 0000000..9996763 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/spec/database_cleaner/data_mapper/base_spec.rb @@ -0,0 +1,29 @@ +require 'database_cleaner/data_mapper/base' +require 'database_cleaner/spec' + +module DatabaseCleaner + RSpec.describe DataMapper do + it { is_expected.to respond_to(:available_strategies) } + end + + module DataMapper + class ExampleStrategy + include ::DatabaseCleaner::DataMapper::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 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 diff --git a/adapters/database_cleaner-data_mapper/spec/database_cleaner/data_mapper/transaction_spec.rb b/adapters/database_cleaner-data_mapper/spec/database_cleaner/data_mapper/transaction_spec.rb new file mode 100644 index 0000000..61e0431 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/spec/database_cleaner/data_mapper/transaction_spec.rb @@ -0,0 +1,22 @@ +require 'database_cleaner/data_mapper/transaction' +require 'database_cleaner/spec' +#require 'data_mapper' + +module DatabaseCleaner + module DataMapper + + RSpec.describe Transaction do + 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 diff --git a/adapters/database_cleaner-data_mapper/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb b/adapters/database_cleaner-data_mapper/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb new file mode 100644 index 0000000..49975ff --- /dev/null +++ b/adapters/database_cleaner-data_mapper/spec/database_cleaner/data_mapper/truncation/sqlite3_spec.rb @@ -0,0 +1,25 @@ +require 'database_cleaner/data_mapper/truncation' + +RSpec.describe DatabaseCleaner::DataMapper::Truncation do + let(:helper) { DataMapperHelper.new(:sqlite3) } + + let(:connection) { helper.connection } + + around do |example| + helper.setup + example.run + helper.teardown + end + + describe "DM connection adapter monkeypatches" do + before { 2.times { User.create } } + + describe "#truncate_table" do + it "truncates the table and resets AUTO_INCREMENT index of table" do + connection.truncate_table(User.storage_names[:default]) + expect(User.count).to eq 0 + expect(User.create.id).to eq 1 + end + end + end +end diff --git a/adapters/database_cleaner-data_mapper/spec/database_cleaner/data_mapper/truncation_spec.rb b/adapters/database_cleaner-data_mapper/spec/database_cleaner/data_mapper/truncation_spec.rb new file mode 100644 index 0000000..b879b90 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/spec/database_cleaner/data_mapper/truncation_spec.rb @@ -0,0 +1,11 @@ +require 'database_cleaner/data_mapper/truncation' +require 'database_cleaner/spec' + +module DatabaseCleaner + module DataMapper + RSpec.describe Truncation do + it_should_behave_like "a generic strategy" + it_should_behave_like "a generic truncation strategy" + end + end +end diff --git a/adapters/database_cleaner-data_mapper/spec/spec_helper.rb b/adapters/database_cleaner-data_mapper/spec/spec_helper.rb new file mode 100644 index 0000000..4ea635d --- /dev/null +++ b/adapters/database_cleaner-data_mapper/spec/spec_helper.rb @@ -0,0 +1,15 @@ +require "bundler/setup" +require 'support/data_mapper_helper' +require "database_cleaner/data_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 diff --git a/adapters/database_cleaner-data_mapper/spec/support/data_mapper_helper.rb b/adapters/database_cleaner-data_mapper/spec/support/data_mapper_helper.rb new file mode 100644 index 0000000..3734828 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/spec/support/data_mapper_helper.rb @@ -0,0 +1,36 @@ +require 'database_cleaner/spec/database_helper' +require "data_mapper" +require "dm-sqlite-adapter" + +class DataMapperHelper < DatabaseCleaner::Spec::DatabaseHelper + def setup + super + + Kernel.const_set "User", Class.new + User.instance_eval do + include DataMapper::Resource + + storage_names[:default] = 'users' + + property :id, User::Serial + property :name, String + end + end + + def teardown + Kernel.send :remove_const, "User" if defined?(User) + + super + end + + def connection + DataMapper.repository.adapter + end + + private + + def establish_connection(config = default_config) + DataMapper.setup(:default, config) + end +end + diff --git a/adapters/database_cleaner-data_mapper/spec/support/sample.config.yml b/adapters/database_cleaner-data_mapper/spec/support/sample.config.yml new file mode 100644 index 0000000..90132c0 --- /dev/null +++ b/adapters/database_cleaner-data_mapper/spec/support/sample.config.yml @@ -0,0 +1,34 @@ +mysql: + adapter: mysql + database: database_cleaner_test + username: root + password: + host: 127.0.0.1 + port: 3306 + encoding: utf8 + +mysql2: + adapter: mysql2 + database: database_cleaner_test + username: root + password: + host: 127.0.0.1 + port: 3306 + encoding: utf8 + +postgres: + adapter: postgresql + database: database_cleaner_test + username: postgres + password: + host: 127.0.0.1 + encoding: unicode + template: template0 + +sqlite3: + adapter: sqlite3 + database: tmp/database_cleaner_test.sqlite3 + pool: 5 + timeout: 5000 + encoding: utf8 + diff --git a/adapters/database_cleaner-data_mapper/tmp/.keep b/adapters/database_cleaner-data_mapper/tmp/.keep new file mode 100644 index 0000000..e69de29 diff --git a/examples/features/support/env.rb b/examples/features/support/env.rb index 739f1ed..2ca27d5 100644 --- a/examples/features/support/env.rb +++ b/examples/features/support/env.rb @@ -24,19 +24,19 @@ ENV['REDIS_URL_TWO'] = config['two']['url'] require "active_support/core_ext/string/inflections" if orm && strategy + require "#{File.dirname(__FILE__)}/../../lib/#{orm.downcase}_models" if use_gems require "database_cleaner-#{orm.underscore}" else $:.unshift(File.dirname(__FILE__) + '/../../../lib') require "database_cleaner" end - require "#{File.dirname(__FILE__)}/../../lib/#{orm.downcase}_models" if another_orm + require "#{File.dirname(__FILE__)}/../../lib/#{another_orm.downcase}_models" if use_gems require "database_cleaner-#{another_orm.underscore}" end - require "#{File.dirname(__FILE__)}/../../lib/#{another_orm.downcase}_models" end require 'database_cleaner/cucumber' diff --git a/features/cleaning.feature b/features/cleaning.feature index b3ed9c1..e04a839 100644 --- a/features/cleaning.feature +++ b/features/cleaning.feature @@ -16,6 +16,8 @@ Feature: database cleaning | ActiveRecord | truncation | | ActiveRecord | deletion | | CouchPotato | truncation | + | DataMapper | transaction | + | DataMapper | truncation | Scenario Outline: ruby app Given I am using diff --git a/features/cleaning_default_strategy.feature b/features/cleaning_default_strategy.feature index 3e63964..8eac054 100644 --- a/features/cleaning_default_strategy.feature +++ b/features/cleaning_default_strategy.feature @@ -14,6 +14,7 @@ Feature: database cleaning | ORM | | ActiveRecord | | CouchPotato | + | DataMapper | Scenario Outline: ruby app Given I am using diff --git a/features/cleaning_multiple_dbs.feature b/features/cleaning_multiple_dbs.feature index 442f9a1..7129814 100644 --- a/features/cleaning_multiple_dbs.feature +++ b/features/cleaning_multiple_dbs.feature @@ -15,6 +15,8 @@ Feature: multiple database cleaning | ActiveRecord | truncation | | ActiveRecord | deletion | | ActiveRecord | transaction | + | DataMapper | truncation | + | DataMapper | transaction | Scenario Outline: ruby app Given I am using diff --git a/features/cleaning_multiple_orms.feature b/features/cleaning_multiple_orms.feature index 4900a8c..6e11c21 100644 --- a/features/cleaning_multiple_orms.feature +++ b/features/cleaning_multiple_orms.feature @@ -12,7 +12,11 @@ Feature: database cleaning using multiple ORMs Examples: | ORM1 | ORM2 | | ActiveRecord | CouchPotato | + | ActiveRecord | DataMapper | | CouchPotato | ActiveRecord | + | CouchPotato | DataMapper | + | DataMapper | ActiveRecord | + | DataMapper | CouchPotato | Scenario Outline: ruby app Given I am using and