From d0accc23b3d01a7d35e73c5dc901014d883ef5f7 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Tue, 21 Mar 2017 19:07:40 -0400 Subject: CLI arg "host" has precedence over ENV var "host" This is a regression from when the server command switched to its own argument parser, as opposed to Rack's. Rack's argument parser, when provided with a "host" argument, gives that value precedence over environment variables. --- railties/lib/rails/commands/server/server_command.rb | 6 ++++-- railties/test/commands/server_test.rb | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index 7e8c86fb49..278fe63c51 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -188,10 +188,12 @@ module Rails end def host - unless (default_host = options[:binding]) + if options[:binding] + options[:binding] + else default_host = environment == "development" ? "localhost" : "0.0.0.0" + ENV.fetch("HOST", default_host) end - ENV.fetch("HOST", default_host) end def environment diff --git a/railties/test/commands/server_test.rb b/railties/test/commands/server_test.rb index d21a80982b..2d1f071969 100644 --- a/railties/test/commands/server_test.rb +++ b/railties/test/commands/server_test.rb @@ -139,6 +139,14 @@ class Rails::ServerTest < ActiveSupport::TestCase end end + def test_argument_precedence_over_environment_variable + switch_env "HOST", "1.2.3.4" do + args = ["-b", "127.0.0.1"] + options = parse_arguments(args) + assert_equal "127.0.0.1", options[:Host] + end + end + def test_records_user_supplied_options server_options = parse_arguments(["-p", 3001]) assert_equal [:Port], server_options[:user_supplied_options] -- cgit v1.2.3