Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactor our common code

  • Loading branch information...
commit 4448362416c3524382782d0fbb757ea9bec21631 1 parent 52b6f9f
@johnf johnf authored
Showing with 11 additions and 7 deletions.
  1. +10 −6 lib/database_cleaner/base.rb
  2. +1 −1  spec/database_cleaner/base_spec.rb
View
16 lib/database_cleaner/base.rb
@@ -36,11 +36,7 @@ def create_strategy(*args)
def clean_with(*args)
strategy = create_strategy(*args)
- if strategy.respond_to? :db=
- strategy.db = self.db
- elsif self.db != :default
- raise ArgumentError, "You must provide a strategy object that supports non default databases when you specify a database"
- end
+ set_strategy_db strategy, self.db
strategy.clean
strategy
@@ -48,6 +44,14 @@ def clean_with(*args)
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)
@@ -58,7 +62,7 @@ def strategy=(args)
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
View
2  spec/database_cleaner/base_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.