diff --git a/lib/database_rewinder.rb b/lib/database_rewinder.rb index 83edaae..e114c42 100644 --- a/lib/database_rewinder.rb +++ b/lib/database_rewinder.rb @@ -16,7 +16,7 @@ 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_config_from(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 @@ -82,16 +82,28 @@ def all_table_names(connection) end end + def get_config_from(connection_name) + if Gem::Version.new(Rails.version) >= Gem::Version.new("6.0.0") + database_configuration.configs_for(env_name: connection_name).first.configuration_hash + else + database_configuration[connection_name] + end + end + def get_cache_key(connection_pool) if connection_pool.respond_to?(:db_config) # ActiveRecord >= 6.1 - connection_pool.db_config.config + if Gem::Version.new(Rails.version) >= Gem::Version.new("6.0.0") + connection_pool.db_config.configuration_hash + else + connection_pool.db_config.config + end else connection_pool.spec.config end end end - private_class_method :get_cache_key + private_class_method :get_config_from, :get_cache_key end begin 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)