mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Fixed strategy class lookup (#680)
This commit is contained in:
parent
a34c4c3d94
commit
a8cfc85ab2
2 changed files with 10 additions and 2 deletions
|
@ -86,7 +86,7 @@ module DatabaseCleaner
|
|||
end
|
||||
|
||||
def orm_strategy(strategy)
|
||||
strategy_module_name = strategy.to_s.capitalize
|
||||
strategy_module_name = camelize(strategy)
|
||||
orm_module.const_get(strategy_module_name)
|
||||
rescue NameError
|
||||
available_strategies = self.class.available_strategies(orm_module)
|
||||
|
|
|
@ -120,9 +120,12 @@ module DatabaseCleaner
|
|||
let(:strategy_class) { Class.new(DatabaseCleaner::Strategy) }
|
||||
let(:orm_module) { Module.new }
|
||||
|
||||
let(:available_strategies) { DatabaseCleaner::Cleaner.available_strategies(orm_module) }
|
||||
|
||||
before do
|
||||
stub_const "DatabaseCleaner::ActiveRecord", orm_module
|
||||
stub_const "DatabaseCleaner::ActiveRecord::Truncation", strategy_class
|
||||
stub_const "DatabaseCleaner::ActiveRecord::MyStrategy", strategy_class
|
||||
# stub consts that shouldn't show up in strategy list
|
||||
stub_const "DatabaseCleaner::ActiveRecord::VERSION", "2.0.0"
|
||||
stub_const "DatabaseCleaner::ActiveRecord::Helpers", Module.new
|
||||
|
@ -136,6 +139,11 @@ module DatabaseCleaner
|
|||
expect(cleaner.strategy).to be_a(strategy_class)
|
||||
end
|
||||
|
||||
it "should look up and create a custom strategy for the current ORM" do
|
||||
cleaner.strategy = :my_strategy
|
||||
expect(cleaner.strategy).to be_a(strategy_class)
|
||||
end
|
||||
|
||||
it "should proxy params with symbolised strategies" do
|
||||
expect(strategy_class).to receive(:new).with(param: "one")
|
||||
cleaner.strategy = :truncation, { param: "one" }
|
||||
|
@ -161,7 +169,7 @@ module DatabaseCleaner
|
|||
|
||||
it "raises UnknownStrategySpecified on a bad strategy, and lists available strategies" do
|
||||
expect { cleaner.strategy = :horrible_plan }.to \
|
||||
raise_error(UnknownStrategySpecified, "The 'horrible_plan' strategy does not exist for the active_record ORM! Available strategies: truncation")
|
||||
raise_error(UnknownStrategySpecified, "The 'horrible_plan' strategy does not exist for the active_record ORM! Available strategies: #{available_strategies.join(', ')}")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue