Skip to content

Commit

Permalink
delay running safeguards until right before cleaning begins. this all…
Browse files Browse the repository at this point in the history
…ows for time to configure safeguards.
  • Loading branch information
botandrose-machine authored and botandrose committed Feb 4, 2021
1 parent 44bbfe5 commit f8b7e05
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 0 additions & 2 deletions lib/database_cleaner/cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'database_cleaner/null_strategy'
require 'database_cleaner/safeguard'
require 'database_cleaner/strategy'
require 'forwardable'

Expand Down Expand Up @@ -28,7 +27,6 @@ def <=>(other)
def initialize(orm, db: nil)
@orm = orm
self.db = db
Safeguard.new.run
end

attr_reader :orm
Expand Down
5 changes: 5 additions & 0 deletions lib/database_cleaner/cleaners.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'database_cleaner/cleaner'
require 'database_cleaner/safeguard'

module DatabaseCleaner
class Cleaners < Hash
Expand All @@ -18,20 +19,24 @@ def strategy=(strategy)
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

Expand Down
2 changes: 1 addition & 1 deletion spec/database_cleaner/safeguard_spec.rb
Original file line number Diff line number Diff line change
@@ -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) }
Expand Down

0 comments on commit f8b7e05

Please sign in to comment.