delay running safeguards until right before cleaning begins. this allows for time to configure safeguards.

This commit is contained in:
Micah Geisel 2021-02-03 12:48:33 -08:00 committed by Micah Geisel
parent 44bbfe5386
commit f8b7e052e6
3 changed files with 6 additions and 3 deletions

View file

@ -1,5 +1,4 @@
require 'database_cleaner/null_strategy'
require 'database_cleaner/safeguard'
require 'database_cleaner/strategy'
require 'forwardable'
@ -28,7 +27,6 @@ module DatabaseCleaner
def initialize(orm, db: nil)
@orm = orm
self.db = db
Safeguard.new.run
end
attr_reader :orm

View file

@ -1,4 +1,5 @@
require 'database_cleaner/cleaner'
require 'database_cleaner/safeguard'
module DatabaseCleaner
class Cleaners < Hash
@ -18,20 +19,24 @@ module DatabaseCleaner
end
def start
Safeguard.new.run
values.each { |cleaner| cleaner.start }
end
def clean
Safeguard.new.run
values.each { |cleaner| cleaner.clean }
end
def cleaning(&inner_block)
Safeguard.new.run
values.inject(inner_block) do |curr_block, cleaner|
proc { cleaner.cleaning(&curr_block) }
end.call
end
def clean_with(*args)
Safeguard.new.run
values.each { |cleaner| cleaner.clean_with(*args) }
end

View file

@ -1,6 +1,6 @@
module DatabaseCleaner
RSpec.describe Safeguard do
let(:cleaner) { Cleaner.new(:null) }
let(:cleaner) { Cleaners.new }
describe 'DATABASE_URL is set' do
before { stub_const('ENV', 'DATABASE_URL' => database_url) }