Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEFAULT_ENV falls back to default_env when RAILS_ENV or RACK_ENV is an empty string #29208

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/connection_handling.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down