diff options
author | Guillermo Iguaran <guilleiguaran@gmail.com> | 2017-05-28 23:59:59 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-28 23:59:59 -0500 |
commit | 7a3db2ea15970e4c9c31a2b23303928aeadb391d (patch) | |
tree | db6c621d4be92b0c677035e4c09f5d7613ef5c13 /activerecord | |
parent | 109bca95022d9471c0aafb9efeb4ba8eb6d99832 (diff) | |
parent | 8ace8c76a4d90cca29ede40dbc7f81351eb2e137 (diff) | |
download | rails-7a3db2ea15970e4c9c31a2b23303928aeadb391d.tar.gz rails-7a3db2ea15970e4c9c31a2b23303928aeadb391d.tar.bz2 rails-7a3db2ea15970e4c9c31a2b23303928aeadb391d.zip |
Merge pull request #29208 from kamipo/default_env_fall_back_to_default_env_when_rails_env_or_rack_env_is_empty_string
`DEFAULT_ENV` falls back to `default_env` when `RAILS_ENV` or `RACK_ENV` is an empty string
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_handling.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/connection_adapters/connection_handler_test.rb | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb index 2ede92feff..b8fbb489b6 100644 --- a/activerecord/lib/active_record/connection_handling.rb +++ b/activerecord/lib/active_record/connection_handling.rb @@ -1,6 +1,6 @@ module ActiveRecord module ConnectionHandling - RAILS_ENV = -> { (Rails.env if defined?(Rails.env)) || ENV["RAILS_ENV"] || ENV["RACK_ENV"] } + RAILS_ENV = -> { (Rails.env if defined?(Rails.env)) || ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence } DEFAULT_ENV = -> { RAILS_ENV.call || "default_env" } # Establishes the connection to the database. Accepts a hash as input where diff --git a/activerecord/test/cases/connection_adapters/connection_handler_test.rb b/activerecord/test/cases/connection_adapters/connection_handler_test.rb index 681399c8bb..2a71f08d90 100644 --- a/activerecord/test/cases/connection_adapters/connection_handler_test.rb +++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb @@ -9,6 +9,17 @@ module ActiveRecord @pool = @handler.establish_connection(ActiveRecord::Base.configurations["arunit"]) end + def test_default_env_fall_back_to_default_env_when_rails_env_or_rack_env_is_empty_string + original_rails_env = ENV["RAILS_ENV"] + original_rack_env = ENV["RACK_ENV"] + ENV["RAILS_ENV"] = ENV["RACK_ENV"] = "" + + assert_equal "default_env", ActiveRecord::ConnectionHandling::DEFAULT_ENV.call + ensure + ENV["RAILS_ENV"] = original_rails_env + ENV["RACK_ENV"] = original_rack_env + end + def test_establish_connection_uses_spec_name config = { "readonly" => { "adapter" => "sqlite3" } } resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new(config) |