diff --git a/lib/database_rewinder.rb b/lib/database_rewinder.rb index 83edaae..fc32afb 100644 --- a/lib/database_rewinder.rb +++ b/lib/database_rewinder.rb @@ -16,11 +16,22 @@ def database_configuration end def create_cleaner(connection_name) - config = database_configuration[connection_name] or raise %Q[Database configuration named "#{connection_name}" is not configured.] + config = get_connection(connection_name) or raise %Q[Database configuration named "#{connection_name}" is not configured.] Cleaner.new(config: config, connection_name: connection_name, only: @only, except: @except).tap {|c| @cleaners << c} end + def get_connection(connection_name) + return database_configuration[connection_name] unless database_configuration.respond_to?(:configs_for) + + config_hash = database_configuration.configs_for(env_name: connection_name).first + if config_hash.respond_to?(:configuration_hash) + config_hash.configuration_hash + else + database_configuration[connection_name] + end + end + def [](connection) @cleaners.detect {|c| c.connection_name == connection} || create_cleaner(connection) end @@ -91,6 +102,7 @@ def get_cache_key(connection_pool) end end + private_class_method :get_connection private_class_method :get_cache_key end diff --git a/lib/database_rewinder/cleaner.rb b/lib/database_rewinder/cleaner.rb index b84b9ef..0336024 100644 --- a/lib/database_rewinder/cleaner.rb +++ b/lib/database_rewinder/cleaner.rb @@ -14,7 +14,7 @@ def initialize(config: nil, connection_name: nil, only: nil, except: nil) end def db - config['database'] + config.fetch('database') { config[:database] } end def clean(multiple: true)