added clean_with shortcut method

This commit is contained in:
Ben Mabey 2009-03-04 22:16:04 -07:00
parent 43ad34fc2b
commit 3fc800e17a
2 changed files with 16 additions and 1 deletions

View file

@ -23,6 +23,12 @@ module DatabaseCleaner
orm_strategy(strategy).new(*strategy_args)
end
def clean_with(*args)
strategy = create_strategy(*args)
strategy.clean
strategy
end
def strategy=(args)
strategy, *strategy_args = args
if strategy.is_a?(Symbol)

View file

@ -22,7 +22,7 @@ describe DatabaseCleaner do
end
describe ".create_strategy ( DatabaseCleaner() )" do
it "should initialize and return the appropirate strategy based on the ORM adapter detected" do
it "should initialize and return the appropirate strategy" do
DatabaseCleaner::ActiveRecord::Transaction.should_receive(:new).with('options' => 'hash')
result = DatabaseCleaner(:transaction, {'options' => 'hash'})
@ -30,6 +30,15 @@ describe DatabaseCleaner do
end
end
describe ".clean_with" do
it "should initialize the appropirate strategy and clean with it" do
DatabaseCleaner::ActiveRecord::Transaction.should_receive(:new).with('options' => 'hash')
@strategy.should_receive(:clean)
DatabaseCleaner.clean_with(:transaction, 'options' => 'hash')
end
end
describe ".strategy=" do
it "should initialize the appropirate strategy based on the ORM adapter detected" do
DatabaseCleaner::ActiveRecord::Transaction.should_receive(:new).with('options' => 'hash')