deprecate loading adapters from database_cleaner core gem.

This commit is contained in:
Micah Geisel 2018-05-23 01:23:40 -07:00
parent e65c63c939
commit 29b444cec4
2 changed files with 14 additions and 7 deletions

View file

@ -159,14 +159,22 @@ module DatabaseCleaner
end
def orm_strategy(strategy)
require "database_cleaner/#{orm.to_s}/#{strategy.to_s}"
orm_module.const_get(strategy.to_s.capitalize)
rescue LoadError
if orm_module.respond_to? :available_strategies
raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM! Available strategies: #{orm_module.available_strategies.join(', ')}"
else
raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM!"
rescue NameError
$stderr.puts <<-TEXT
Requiring the `database_cleaner` gem directly is deprecated, and will raise an error in database_cleaner 2.0. Instead, please require the specific gem (or gems) for your ORM.
For example, replace `gem "database_cleaner"` with `gem "database_cleaner-active_record"` in your Gemfile. See ### for more information.
TEXT
begin
require "database_cleaner/#{orm.to_s}/#{strategy.to_s}"
rescue LoadError
if orm_module.respond_to?(:available_strategies)
raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM! Available strategies: #{orm_module.available_strategies.join(', ')}"
else
raise UnknownStrategySpecified, "The '#{strategy}' strategy does not exist for the #{orm} ORM!"
end
end
retry
end
def autodetect

View file

@ -314,7 +314,6 @@ module DatabaseCleaner
it "loads and instantiates the described strategy" do
stub_const "DatabaseCleaner::ActiveRecord::Cunningplan", strategy_class
expect(subject).to receive(:require).with("database_cleaner/active_record/cunningplan")
subject.strategy = :cunningplan
expect(subject.strategy).to be_a strategy_class