mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Merge pull request #195 from johnf/clean_with_multidb
Make clean_with work for multiple db connections
This commit is contained in:
commit
466ccfdbd7
2 changed files with 12 additions and 2 deletions
|
@ -36,12 +36,22 @@ module DatabaseCleaner
|
|||
|
||||
def clean_with(*args)
|
||||
strategy = create_strategy(*args)
|
||||
set_strategy_db strategy, self.db
|
||||
|
||||
strategy.clean
|
||||
strategy
|
||||
end
|
||||
|
||||
alias clean_with! clean_with
|
||||
|
||||
def set_strategy_db(strategy, desired_db)
|
||||
if strategy.respond_to? :db=
|
||||
strategy.db = desired_db
|
||||
elsif desired_db != :default
|
||||
raise ArgumentError, "You must provide a strategy object that supports non default databases when you specify a database"
|
||||
end
|
||||
end
|
||||
|
||||
def strategy=(args)
|
||||
strategy, *strategy_args = args
|
||||
if strategy.is_a?(Symbol)
|
||||
|
@ -52,7 +62,7 @@ module DatabaseCleaner
|
|||
raise ArgumentError, "You must provide a strategy object, or a symbol for a known strategy along with initialization params."
|
||||
end
|
||||
|
||||
self.strategy_db = self.db
|
||||
set_strategy_db @strategy, self.db
|
||||
|
||||
@strategy
|
||||
end
|
||||
|
|
|
@ -334,7 +334,7 @@ module DatabaseCleaner
|
|||
|
||||
it "should attempt to set strategy db" do
|
||||
subject.stub(:db).and_return(:my_db)
|
||||
subject.should_receive(:strategy_db=).with(:my_db)
|
||||
subject.should_receive(:set_strategy_db).with(mock_strategy, :my_db)
|
||||
subject.strategy = mock_strategy
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue