mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
add .default_strategy method to all adapters, and move knowledge into it from core.
This commit is contained in:
parent
054404fb37
commit
c0a9610ce9
23 changed files with 124 additions and 12 deletions
|
@ -4,11 +4,14 @@ require 'erb'
|
|||
|
||||
module DatabaseCleaner
|
||||
module ActiveRecord
|
||||
|
||||
def self.available_strategies
|
||||
%w[truncation transaction deletion]
|
||||
end
|
||||
|
||||
def self.default_strategy
|
||||
:transaction
|
||||
end
|
||||
|
||||
def self.config_file_location=(path)
|
||||
@config_file_location = path
|
||||
end
|
||||
|
|
|
@ -11,6 +11,10 @@ end
|
|||
RSpec.describe DatabaseCleaner::ActiveRecord do
|
||||
it { is_expected.to respond_to(:available_strategies) }
|
||||
|
||||
it "has a default_strategy of transaction" do
|
||||
expect(described_class.default_strategy).to eq(:transaction)
|
||||
end
|
||||
|
||||
describe "config_file_location" do
|
||||
after do
|
||||
# prevent global state leakage
|
||||
|
|
|
@ -3,3 +3,9 @@ require "database_cleaner"
|
|||
require "database_cleaner/couch_potato/base"
|
||||
require "database_cleaner/couch_potato/truncation"
|
||||
|
||||
module DatabaseCleaner::CouchPotato
|
||||
def self.default_strategy
|
||||
:truncation
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
require 'database_cleaner/couch_potato'
|
||||
|
||||
RSpec.describe DatabaseCleaner::CouchPotato do
|
||||
it "has a default_strategy of truncation" do
|
||||
expect(described_class.default_strategy).to eq(:truncation)
|
||||
end
|
||||
end
|
||||
|
|
@ -5,6 +5,10 @@ module DatabaseCleaner
|
|||
%w[truncation transaction]
|
||||
end
|
||||
|
||||
def self.default_strategy
|
||||
:transaction
|
||||
end
|
||||
|
||||
module Base
|
||||
include ::DatabaseCleaner::Generic::Base
|
||||
|
||||
|
|
|
@ -4,6 +4,10 @@ require 'database_cleaner/spec'
|
|||
module DatabaseCleaner
|
||||
RSpec.describe DataMapper do
|
||||
it { is_expected.to respond_to(:available_strategies) }
|
||||
|
||||
it "has a default_strategy of transaction" do
|
||||
expect(described_class.default_strategy).to eq(:transaction)
|
||||
end
|
||||
end
|
||||
|
||||
module DataMapper
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
require 'database_cleaner/mongo/version'
|
||||
require 'database_cleaner'
|
||||
require 'database_cleaner/mongo/truncation'
|
||||
|
||||
module DatabaseCleaner::Mongo
|
||||
def self.default_strategy
|
||||
:truncation
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
require 'database_cleaner/mongo'
|
||||
|
||||
RSpec.describe DatabaseCleaner::Mongo do
|
||||
it "has a default_strategy of truncation" do
|
||||
expect(described_class.default_strategy).to eq(:truncation)
|
||||
end
|
||||
end
|
||||
|
|
@ -5,6 +5,10 @@ module DatabaseCleaner
|
|||
%w[truncation]
|
||||
end
|
||||
|
||||
def self.default_strategy
|
||||
:truncation
|
||||
end
|
||||
|
||||
module Base
|
||||
include ::DatabaseCleaner::Generic::Base
|
||||
|
||||
|
|
|
@ -4,6 +4,10 @@ require 'database_cleaner/spec'
|
|||
module DatabaseCleaner
|
||||
RSpec.describe MongoMapper do
|
||||
it { is_expected.to respond_to(:available_strategies) }
|
||||
|
||||
it "has a default_strategy of truncation" do
|
||||
expect(described_class.default_strategy).to eq(:truncation)
|
||||
end
|
||||
end
|
||||
|
||||
module MongoMapper
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
require "database_cleaner/mongoid/version"
|
||||
require "database_cleaner"
|
||||
require "database_cleaner/mongoid/truncation"
|
||||
|
||||
module DatabaseCleaner::Mongoid
|
||||
def self.default_strategy
|
||||
:truncation
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
require 'database_cleaner/mongoid'
|
||||
|
||||
RSpec.describe DatabaseCleaner::Mongoid do
|
||||
it "has a default_strategy of truncation" do
|
||||
expect(described_class.default_strategy).to eq(:truncation)
|
||||
end
|
||||
end
|
||||
|
|
@ -2,3 +2,9 @@ require "database_cleaner/moped/version"
|
|||
require "database_cleaner"
|
||||
require "database_cleaner/moped/truncation"
|
||||
|
||||
module DatabaseCleaner::Moped
|
||||
def self.default_strategy
|
||||
:truncation
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
require 'database_cleaner/moped'
|
||||
|
||||
RSpec.describe DatabaseCleaner::Moped do
|
||||
it "has a default_strategy of truncation" do
|
||||
expect(described_class.default_strategy).to eq(:truncation)
|
||||
end
|
||||
end
|
||||
|
|
@ -5,6 +5,10 @@ module DatabaseCleaner
|
|||
%w[transaction truncation deletion]
|
||||
end
|
||||
|
||||
def self.default_strategy
|
||||
:transaction
|
||||
end
|
||||
|
||||
module Base
|
||||
include ::DatabaseCleaner::Generic::Base
|
||||
|
||||
|
|
|
@ -4,6 +4,10 @@ require 'database_cleaner/spec'
|
|||
module DatabaseCleaner
|
||||
RSpec.describe Neo4j do
|
||||
it { is_expected.to respond_to(:available_strategies) }
|
||||
|
||||
it "has a default_strategy of transaction" do
|
||||
expect(described_class.default_strategy).to eq(:transaction)
|
||||
end
|
||||
end
|
||||
|
||||
module Neo4j
|
||||
|
|
|
@ -2,3 +2,9 @@ require "database_cleaner/ohm/version"
|
|||
require "database_cleaner"
|
||||
require "database_cleaner/ohm/truncation"
|
||||
|
||||
module DatabaseCleaner::Ohm
|
||||
def self.default_strategy
|
||||
:truncation
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
require 'database_cleaner/ohm'
|
||||
|
||||
RSpec.describe DatabaseCleaner::Ohm do
|
||||
it "has a default_strategy of truncation" do
|
||||
expect(described_class.default_strategy).to eq(:truncation)
|
||||
end
|
||||
end
|
||||
|
|
@ -6,6 +6,10 @@ module DatabaseCleaner
|
|||
%w{truncation}
|
||||
end
|
||||
|
||||
def self.default_strategy
|
||||
:truncation
|
||||
end
|
||||
|
||||
module Base
|
||||
include ::DatabaseCleaner::Generic::Base
|
||||
|
||||
|
|
|
@ -5,6 +5,10 @@ require 'database_cleaner/spec'
|
|||
module DatabaseCleaner
|
||||
RSpec.describe Redis do
|
||||
it { is_expected.to respond_to(:available_strategies) }
|
||||
|
||||
it "has a default_strategy of truncation" do
|
||||
expect(described_class.default_strategy).to eq(:truncation)
|
||||
end
|
||||
end
|
||||
|
||||
module Redis
|
||||
|
|
|
@ -5,6 +5,10 @@ module DatabaseCleaner
|
|||
%w(truncation transaction deletion)
|
||||
end
|
||||
|
||||
def self.default_strategy
|
||||
:transaction
|
||||
end
|
||||
|
||||
module Base
|
||||
include ::DatabaseCleaner::Generic::Base
|
||||
|
||||
|
|
|
@ -5,6 +5,10 @@ require 'sequel'
|
|||
module DatabaseCleaner
|
||||
RSpec.describe Sequel do
|
||||
it { is_expected.to respond_to(:available_strategies) }
|
||||
|
||||
it "has a default_strategy of transaction" do
|
||||
expect(described_class.default_strategy).to eq(:transaction)
|
||||
end
|
||||
end
|
||||
|
||||
module Sequel
|
||||
|
|
|
@ -15,7 +15,7 @@ module DatabaseCleaner
|
|||
@orm_autodetector = ORMAutodetector.new
|
||||
self.orm = desired_orm
|
||||
self.db = opts[:connection] || opts[:model] if opts.has_key?(:connection) || opts.has_key?(:model)
|
||||
self.strategy = default_orm_strategy
|
||||
self.strategy = orm_module && orm_module.default_strategy
|
||||
Safeguard.new.run
|
||||
end
|
||||
|
||||
|
@ -103,6 +103,8 @@ module DatabaseCleaner
|
|||
|
||||
def orm_module
|
||||
return unless [:active_record, :data_mapper, :mongo, :mongoid, :mongo_mapper, :moped, :couch_potato, :sequel, :ohm, :redis, :neo4j].include?(orm)
|
||||
$LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../../adapters/database_cleaner-#{orm}/lib")
|
||||
require "database_cleaner/#{orm}"
|
||||
DatabaseCleaner.const_get(orm.to_s.camelize)
|
||||
end
|
||||
|
||||
|
@ -118,19 +120,10 @@ module DatabaseCleaner
|
|||
end
|
||||
|
||||
def require_orm_strategy(orm, strategy)
|
||||
$LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../../adapters/database_cleaner-#{orm}/lib/database_cleaner/#{orm}")
|
||||
$LOAD_PATH.unshift File.expand_path("#{File.dirname(__FILE__)}/../../adapters/database_cleaner-#{orm}/lib")
|
||||
require "database_cleaner/#{orm}/#{strategy}"
|
||||
rescue LoadError
|
||||
raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM! Available strategies: #{orm_module.available_strategies.join(', ')}"
|
||||
end
|
||||
|
||||
def default_orm_strategy
|
||||
case orm
|
||||
when :active_record, :data_mapper, :sequel, :neo4j
|
||||
:transaction
|
||||
when :mongo_mapper, :mongoid, :couch_potato, :moped, :ohm, :redis
|
||||
:truncation
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue