From 2c29d36b17e927d00cbd5ef75425bb520d223b04 Mon Sep 17 00:00:00 2001 From: Mitsutaka Mimura Date: Sat, 17 Oct 2020 23:08:18 +0900 Subject: [PATCH] `ActiveRecord::Base.configurations` in edge returns Symbol key `ActiveRecord::Base.configurations` in edge rails returns Symbol key. And I watched the following discussion. https://github.com/amatsuda/database_rewinder/pull/70#discussion_r392863164 I was referring to this comment as well. --- lib/database_rewinder.rb | 14 +++++++++++++- lib/database_rewinder/cleaner.rb | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) 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)