mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
delay running safeguards until right before cleaning begins. this allows for time to configure safeguards.
This commit is contained in:
parent
44bbfe5386
commit
f8b7e052e6
3 changed files with 6 additions and 3 deletions
|
@ -1,5 +1,4 @@
|
||||||
require 'database_cleaner/null_strategy'
|
require 'database_cleaner/null_strategy'
|
||||||
require 'database_cleaner/safeguard'
|
|
||||||
require 'database_cleaner/strategy'
|
require 'database_cleaner/strategy'
|
||||||
require 'forwardable'
|
require 'forwardable'
|
||||||
|
|
||||||
|
@ -28,7 +27,6 @@ module DatabaseCleaner
|
||||||
def initialize(orm, db: nil)
|
def initialize(orm, db: nil)
|
||||||
@orm = orm
|
@orm = orm
|
||||||
self.db = db
|
self.db = db
|
||||||
Safeguard.new.run
|
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :orm
|
attr_reader :orm
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
require 'database_cleaner/cleaner'
|
require 'database_cleaner/cleaner'
|
||||||
|
require 'database_cleaner/safeguard'
|
||||||
|
|
||||||
module DatabaseCleaner
|
module DatabaseCleaner
|
||||||
class Cleaners < Hash
|
class Cleaners < Hash
|
||||||
|
@ -18,20 +19,24 @@ module DatabaseCleaner
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
|
Safeguard.new.run
|
||||||
values.each { |cleaner| cleaner.start }
|
values.each { |cleaner| cleaner.start }
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean
|
def clean
|
||||||
|
Safeguard.new.run
|
||||||
values.each { |cleaner| cleaner.clean }
|
values.each { |cleaner| cleaner.clean }
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleaning(&inner_block)
|
def cleaning(&inner_block)
|
||||||
|
Safeguard.new.run
|
||||||
values.inject(inner_block) do |curr_block, cleaner|
|
values.inject(inner_block) do |curr_block, cleaner|
|
||||||
proc { cleaner.cleaning(&curr_block) }
|
proc { cleaner.cleaning(&curr_block) }
|
||||||
end.call
|
end.call
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_with(*args)
|
def clean_with(*args)
|
||||||
|
Safeguard.new.run
|
||||||
values.each { |cleaner| cleaner.clean_with(*args) }
|
values.each { |cleaner| cleaner.clean_with(*args) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module DatabaseCleaner
|
module DatabaseCleaner
|
||||||
RSpec.describe Safeguard do
|
RSpec.describe Safeguard do
|
||||||
let(:cleaner) { Cleaner.new(:null) }
|
let(:cleaner) { Cleaners.new }
|
||||||
|
|
||||||
describe 'DATABASE_URL is set' do
|
describe 'DATABASE_URL is set' do
|
||||||
before { stub_const('ENV', 'DATABASE_URL' => database_url) }
|
before { stub_const('ENV', 'DATABASE_URL' => database_url) }
|
||||||
|
|
Loading…
Reference in a new issue