From 3fc800e17af4a154058ba033931f5b9bc38c596e Mon Sep 17 00:00:00 2001 From: Ben Mabey <ben@benmabey.com> Date: Wed, 4 Mar 2009 22:16:04 -0700 Subject: [PATCH] added clean_with shortcut method --- lib/database_cleaner/configuration.rb | 6 ++++++ spec/database_cleaner/configuration_spec.rb | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/database_cleaner/configuration.rb b/lib/database_cleaner/configuration.rb index 1ce180b..6e1e136 100644 --- a/lib/database_cleaner/configuration.rb +++ b/lib/database_cleaner/configuration.rb @@ -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) diff --git a/spec/database_cleaner/configuration_spec.rb b/spec/database_cleaner/configuration_spec.rb index cfb54df..cecae80 100644 --- a/spec/database_cleaner/configuration_spec.rb +++ b/spec/database_cleaner/configuration_spec.rb @@ -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')