Skip to content

Commit

Permalink
ActiveRecord::Base.configurations in edge returns Symbol key
Browse files Browse the repository at this point in the history
`ActiveRecord::Base.configurations` in edge rails returns Symbol key.
And I watched the following discussion.
amatsuda#70 (comment)
I was referring to this comment as well.
  • Loading branch information
takkanm committed Oct 17, 2020
1 parent f3701a5 commit 2c29d36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/database_rewinder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -91,6 +102,7 @@ def get_cache_key(connection_pool)
end
end

private_class_method :get_connection
private_class_method :get_cache_key
end

Expand Down
2 changes: 1 addition & 1 deletion lib/database_rewinder/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2c29d36

Please sign in to comment.