Skip to content

Commit

Permalink
Merge pull request #37963 from eileencodes/deprecate-config-in-dbconsole
Browse files Browse the repository at this point in the history
Deprecate config in dbconsole
  • Loading branch information
eileencodes committed Dec 16, 2019
2 parents f2b69d8 + 0983daa commit 3578f69
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions railties/CHANGELOG.md
@@ -1,3 +1,9 @@
* Deprecate `Rails::DBConsole#config`

`Rails::DBConsole#config` is deprecated without replacement. Use `Rails::DBConsole.db_config.configuration_hash` instead.

*Eileen M. Uchitelle*, *John Crepezzi*

* `Rails.application.config_for` merges shared configuration deeply.

```yaml
Expand Down
2 changes: 2 additions & 0 deletions railties/lib/rails/commands/dbconsole/dbconsole_command.rb
Expand Up @@ -16,6 +16,7 @@ def initialize(options = {})

def start
ENV["RAILS_ENV"] ||= @options[:environment] || environment
config = db_config.configuration_hash

case db_config.adapter
when /^(jdbc)?mysql/
Expand Down Expand Up @@ -92,6 +93,7 @@ def start
def config
db_config.configuration_hash
end
deprecate config: "please use db_config.configuration_hash"

def db_config
return @db_config if defined?(@db_config)
Expand Down
10 changes: 5 additions & 5 deletions railties/test/commands/dbconsole_test.rb
Expand Up @@ -30,14 +30,14 @@ def test_config_with_db_config_only
}
}
app_db_config(config_sample) do
assert_equal config_sample["test"].symbolize_keys, Rails::DBConsole.new.config
assert_equal config_sample["test"].symbolize_keys, Rails::DBConsole.new.db_config.configuration_hash
end
end

def test_config_with_no_db_config
app_db_config(nil) do
assert_raise(ActiveRecord::AdapterNotSpecified) {
Rails::DBConsole.new.config
Rails::DBConsole.new.db_config.configuration_hash
}
end
end
Expand All @@ -56,7 +56,7 @@ def test_config_with_database_url_only
}.sort

app_db_config(nil) do
assert_equal expected, Rails::DBConsole.new.config.sort
assert_equal expected, Rails::DBConsole.new.db_config.configuration_hash.sort
end
end

Expand All @@ -76,7 +76,7 @@ def test_config_choose_database_url_if_exists
}
}
app_db_config(sample_config) do
assert_equal host, Rails::DBConsole.new.config[:host]
assert_equal host, Rails::DBConsole.new.db_config.configuration_hash[:host]
end
end

Expand Down Expand Up @@ -213,7 +213,7 @@ def test_primary_is_automatically_picked_with_3_level_configuration
}

app_db_config(sample_config) do
assert_equal "postgresql", Rails::DBConsole.new.config[:adapter]
assert_equal "postgresql", Rails::DBConsole.new.db_config.configuration_hash[:adapter]
end
end

Expand Down

0 comments on commit 3578f69

Please sign in to comment.