From f8b7e052e6c39980ce063affbcffc8e765e27b07 Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Wed, 3 Feb 2021 12:48:33 -0800 Subject: [PATCH] delay running safeguards until right before cleaning begins. this allows for time to configure safeguards. --- lib/database_cleaner/cleaner.rb | 2 -- lib/database_cleaner/cleaners.rb | 5 +++++ spec/database_cleaner/safeguard_spec.rb | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/database_cleaner/cleaner.rb b/lib/database_cleaner/cleaner.rb index ab8f399..303bb13 100644 --- a/lib/database_cleaner/cleaner.rb +++ b/lib/database_cleaner/cleaner.rb @@ -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 diff --git a/lib/database_cleaner/cleaners.rb b/lib/database_cleaner/cleaners.rb index d6f6cce..f875665 100644 --- a/lib/database_cleaner/cleaners.rb +++ b/lib/database_cleaner/cleaners.rb @@ -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 diff --git a/spec/database_cleaner/safeguard_spec.rb b/spec/database_cleaner/safeguard_spec.rb index c933c0e..8c9be54 100644 --- a/spec/database_cleaner/safeguard_spec.rb +++ b/spec/database_cleaner/safeguard_spec.rb @@ -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) }