mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
move strategy= and orm= over to Cleaners.
This commit is contained in:
parent
47fb64a8a9
commit
054404fb37
2 changed files with 31 additions and 21 deletions
|
@ -13,10 +13,30 @@ module DatabaseCleaner
|
|||
fetch([orm, opts]) { add_cleaner(orm, opts) }
|
||||
end
|
||||
|
||||
# TODO privatize in 2.0
|
||||
def strategy=(strategy)
|
||||
add_cleaner(:autodetect) if none?
|
||||
values.each { |cleaner| cleaner.strategy = strategy }
|
||||
remove_duplicates
|
||||
end
|
||||
|
||||
def orm=(orm)
|
||||
add_cleaner(:autodetect) if none?
|
||||
values.each { |cleaner| cleaner.orm = orm }
|
||||
remove_duplicates
|
||||
end
|
||||
|
||||
# TODO privatize the following methods in 2.0
|
||||
|
||||
def add_cleaner(orm, opts = {})
|
||||
self[[orm, opts]] = ::DatabaseCleaner::Base.new(orm, opts)
|
||||
end
|
||||
|
||||
def remove_duplicates
|
||||
replace(reduce(Cleaners.new) do |cleaners, (key, value)|
|
||||
cleaners[key] = value unless cleaners.values.include?(value)
|
||||
cleaners
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
class Configuration
|
||||
|
@ -25,7 +45,14 @@ module DatabaseCleaner
|
|||
end
|
||||
|
||||
extend Forwardable
|
||||
delegate [:[], :add_cleaner] => :cleaners
|
||||
delegate [
|
||||
:[],
|
||||
:strategy=,
|
||||
:orm=,
|
||||
|
||||
:add_cleaner,
|
||||
:remove_duplicates,
|
||||
] => :cleaners
|
||||
|
||||
attr_accessor :app_root, :logger, :cleaners
|
||||
|
||||
|
@ -37,16 +64,6 @@ module DatabaseCleaner
|
|||
@logger ||= Logger.new(STDOUT).tap { |l| l.level = Logger::ERROR }
|
||||
end
|
||||
|
||||
def strategy=(stratagem)
|
||||
connections.each { |connect| connect.strategy = stratagem }
|
||||
remove_duplicates
|
||||
end
|
||||
|
||||
def orm=(orm)
|
||||
connections.each { |connect| connect.orm = orm }
|
||||
remove_duplicates
|
||||
end
|
||||
|
||||
def start
|
||||
connections.each { |connection| connection.start }
|
||||
end
|
||||
|
@ -84,13 +101,6 @@ module DatabaseCleaner
|
|||
@cleaners.values
|
||||
end
|
||||
|
||||
def remove_duplicates
|
||||
@cleaners = @cleaners.reduce({}) do |cleaners, (key, value)|
|
||||
cleaners[key] = value unless cleaners.values.include?(value)
|
||||
cleaners
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def called_externally?(caller)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module DatabaseCleaner
|
||||
class Configuration
|
||||
def stub_cleaners(array)
|
||||
@cleaners = array.each.with_index.reduce({}) do |hash, (cleaner, index)|
|
||||
hash.merge index => cleaner
|
||||
@cleaners = array.each.with_index.reduce(Cleaners.new) do |cleaners, (cleaner, index)|
|
||||
cleaners.merge index => cleaner
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue