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

CLI arg "host" has precedence over ENV var "host" #28513

Merged
merged 1 commit into from
Mar 22, 2017
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
6 changes: 4 additions & 2 deletions railties/lib/rails/commands/server/server_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ def port
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
Expand Down
8 changes: 8 additions & 0 deletions railties/test/commands/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ def test_host
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]
Expand Down