提交 7a3db2ea 编写于 作者: G Guillermo Iguaran 提交者: GitHub

Merge pull request #29208 from...

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
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
......
......@@ -9,6 +9,17 @@ def setup
@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)
......
......@@ -23,7 +23,7 @@ def hidden_commands # :nodoc:
end
def environment # :nodoc:
ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || "development"
end
# Receives a namespace, arguments and the behavior to invoke the command.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册