Skip to content

Commit

Permalink
Allow forcing use of DATABASE_URL in test env
Browse files Browse the repository at this point in the history
This is a gross but backwards compatible way to enable Heroku CI.
  • Loading branch information
tpope committed Apr 28, 2017
1 parent a051a38 commit 72d0488
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/rails-default-database.rb
Expand Up @@ -17,7 +17,7 @@ def database_configuration_with_default
if url = ENV['DATABASE_URL'].presence
(environments_for_database_configuration | config.keys).each do |k|
config[k] = {'url' => url.gsub('%s', k)}
if k == 'test'
if k == 'test' && ENV['TEST_DATABASE_URL'] != 'default'
config[k]['url'] =
config[k]['url'].sub(/(?:_(?:#{environments_for_database_configuration.join('|')})(?:\d*|%i))?(?=\?|$)/, "_test")
end
Expand All @@ -26,8 +26,9 @@ def database_configuration_with_default
else
default_database_configuration.merge(config)
end.tap do |c|
if ENV['TEST_DATABASE_URL'].present?
c['test'] = {'url' => ENV['TEST_DATABASE_URL']}
url = ENV['TEST_DATABASE_URL'].presence
if url && url != 'default'
c['test'] = {'url' => url}
end
%w(url database).each do |key|
if value = c['test'] && c['test'][key]
Expand Down

0 comments on commit 72d0488

Please sign in to comment.