diff --git a/lib/database_cleaner/cleaner.rb b/lib/database_cleaner/cleaner.rb index 303bb13..bf83761 100644 --- a/lib/database_cleaner/cleaner.rb +++ b/lib/database_cleaner/cleaner.rb @@ -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) diff --git a/spec/database_cleaner/cleaner_spec.rb b/spec/database_cleaner/cleaner_spec.rb index 0d80528..aa5b373 100644 --- a/spec/database_cleaner/cleaner_spec.rb +++ b/spec/database_cleaner/cleaner_spec.rb @@ -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