Skip to content

Commit

Permalink
Fix db object to not return deprecated variable
Browse files Browse the repository at this point in the history
Calling `db_config.config` was deprecated in rails#37185 in favor of
`db_config.configuration_hash`. When returning the objects from
`configurations` we should ensure the object returns the non-deprecated
method.

Before:

```
<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007ff0f61696a0
@env_name="development", @name="primary", @config={:adapter=>"mysql2",
:database=>"recipes_development"}>
```

After:

```
<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007ff0f61696a0
@env_name="development", @name="primary", @configuration_hash={:adapter=>"mysql2",
:database=>"recipes_development"}>
```

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
  • Loading branch information
eileencodes and seejohnrun committed Apr 10, 2020
1 parent c1ccc6a commit 2291d4a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Expand Up @@ -25,20 +25,17 @@ class DatabaseConfigurations
# database adapter, name, and other important information for database
# connections.
class HashConfig < DatabaseConfig
def initialize(env_name, name, config)
attr_reader :configuration_hash
def initialize(env_name, name, configuration_hash)
super(env_name, name)
@config = config.symbolize_keys
@configuration_hash = configuration_hash.symbolize_keys.freeze
end

def config
ActiveSupport::Deprecation.warn("DatabaseConfig#config will be removed in 6.2.0 in favor of DatabaseConfigurations#configuration_hash which returns a hash with symbol keys")
configuration_hash.stringify_keys
end

def configuration_hash
@config.freeze
end

# Determines whether a database configuration is for a replica / readonly
# connection. If the +replica+ key is present in the config, +replica?+ will
# return +true+.
Expand All @@ -62,7 +59,7 @@ def database
end

def _database=(database) # :nodoc:
@config = configuration_hash.dup.merge(database: database).freeze
@configuration_hash = configuration_hash.merge(database: database).freeze
end

def pool
Expand Down
Expand Up @@ -31,11 +31,11 @@ class DatabaseConfigurations
class UrlConfig < HashConfig
attr_reader :url

def initialize(env_name, name, url, config = {})
super(env_name, name, config)
def initialize(env_name, name, url, configuration_hash = {})
super(env_name, name, configuration_hash)

@url = url
@config.merge!(build_url_hash)
@configuration_hash = @configuration_hash.merge(build_url_hash).freeze
end

private
Expand Down

0 comments on commit 2291d4a

Please sign in to comment.