mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
extract database_cleaner-data_mapper adapter.
This commit is contained in:
parent
84d4c23bc2
commit
95619b2e74
32 changed files with 673 additions and 2 deletions
1
Gemfile
1
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
|
||||
|
|
|
@ -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
|
||||
|
|
13
adapters/database_cleaner-data_mapper/.gitignore
vendored
Normal file
13
adapters/database_cleaner-data_mapper/.gitignore
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
/.bundle/
|
||||
/.yardoc
|
||||
/_yardoc/
|
||||
/coverage/
|
||||
/doc/
|
||||
/pkg/
|
||||
/spec/reports/
|
||||
/spec/support/config.yml
|
||||
/tmp/
|
||||
!/tmp/.keep
|
||||
|
||||
# rspec failure tracking
|
||||
.rspec_status
|
3
adapters/database_cleaner-data_mapper/.rspec
Normal file
3
adapters/database_cleaner-data_mapper/.rspec
Normal file
|
@ -0,0 +1,3 @@
|
|||
--format documentation
|
||||
--color
|
||||
--require spec_helper
|
5
adapters/database_cleaner-data_mapper/.travis.yml
Normal file
5
adapters/database_cleaner-data_mapper/.travis.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
sudo: false
|
||||
language: ruby
|
||||
rvm:
|
||||
- 2.2.9
|
||||
before_install: gem install bundler -v 1.16.1
|
8
adapters/database_cleaner-data_mapper/Gemfile
Normal file
8
adapters/database_cleaner-data_mapper/Gemfile
Normal 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-data_mapper.gemspec
|
||||
gemspec
|
||||
|
||||
gem "database_cleaner", path: "../.."
|
103
adapters/database_cleaner-data_mapper/Gemfile.lock
Normal file
103
adapters/database_cleaner-data_mapper/Gemfile.lock
Normal file
|
@ -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
|
21
adapters/database_cleaner-data_mapper/LICENSE.txt
Normal file
21
adapters/database_cleaner-data_mapper/LICENSE.txt
Normal 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.
|
39
adapters/database_cleaner-data_mapper/README.md
Normal file
39
adapters/database_cleaner-data_mapper/README.md
Normal file
|
@ -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).
|
6
adapters/database_cleaner-data_mapper/Rakefile
Normal file
6
adapters/database_cleaner-data_mapper/Rakefile
Normal file
|
@ -0,0 +1,6 @@
|
|||
require "bundler/gem_tasks"
|
||||
require "rspec/core/rake_task"
|
||||
|
||||
RSpec::Core::RakeTask.new(:spec)
|
||||
|
||||
task :default => :spec
|
14
adapters/database_cleaner-data_mapper/bin/console
Executable file
14
adapters/database_cleaner-data_mapper/bin/console
Executable file
|
@ -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__)
|
8
adapters/database_cleaner-data_mapper/bin/setup
Executable file
8
adapters/database_cleaner-data_mapper/bin/setup
Executable 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
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
require "database_cleaner/data_mapper"
|
|
@ -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"
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,5 @@
|
|||
module DatabaseCleaner
|
||||
module DataMapper
|
||||
VERSION = "1.8.0"
|
||||
end
|
||||
end
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
15
adapters/database_cleaner-data_mapper/spec/spec_helper.rb
Normal file
15
adapters/database_cleaner-data_mapper/spec/spec_helper.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
0
adapters/database_cleaner-data_mapper/tmp/.keep
Normal file
0
adapters/database_cleaner-data_mapper/tmp/.keep
Normal file
|
@ -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'
|
||||
|
|
|
@ -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 <ORM>
|
||||
|
|
|
@ -14,6 +14,7 @@ Feature: database cleaning
|
|||
| ORM |
|
||||
| ActiveRecord |
|
||||
| CouchPotato |
|
||||
| DataMapper |
|
||||
|
||||
Scenario Outline: ruby app
|
||||
Given I am using <ORM>
|
||||
|
|
|
@ -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 <ORM>
|
||||
|
|
|
@ -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 <ORM1> and <ORM2>
|
||||
|
|
Loading…
Add table
Reference in a new issue