mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
added clean_with shortcut method
This commit is contained in:
parent
43ad34fc2b
commit
3fc800e17a
2 changed files with 16 additions and 1 deletions
|
@ -23,6 +23,12 @@ module DatabaseCleaner
|
||||||
orm_strategy(strategy).new(*strategy_args)
|
orm_strategy(strategy).new(*strategy_args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def clean_with(*args)
|
||||||
|
strategy = create_strategy(*args)
|
||||||
|
strategy.clean
|
||||||
|
strategy
|
||||||
|
end
|
||||||
|
|
||||||
def strategy=(args)
|
def strategy=(args)
|
||||||
strategy, *strategy_args = args
|
strategy, *strategy_args = args
|
||||||
if strategy.is_a?(Symbol)
|
if strategy.is_a?(Symbol)
|
||||||
|
|
|
@ -22,7 +22,7 @@ describe DatabaseCleaner do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".create_strategy ( DatabaseCleaner() )" do
|
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')
|
DatabaseCleaner::ActiveRecord::Transaction.should_receive(:new).with('options' => 'hash')
|
||||||
result = DatabaseCleaner(:transaction, {'options' => 'hash'})
|
result = DatabaseCleaner(:transaction, {'options' => 'hash'})
|
||||||
|
|
||||||
|
@ -30,6 +30,15 @@ describe DatabaseCleaner do
|
||||||
end
|
end
|
||||||
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
|
describe ".strategy=" do
|
||||||
it "should initialize the appropirate strategy based on the ORM adapter detected" do
|
it "should initialize the appropirate strategy based on the ORM adapter detected" do
|
||||||
DatabaseCleaner::ActiveRecord::Transaction.should_receive(:new).with('options' => 'hash')
|
DatabaseCleaner::ActiveRecord::Transaction.should_receive(:new).with('options' => 'hash')
|
||||||
|
|
Loading…
Add table
Reference in a new issue