Merge pull request #21267 from davidcornu/rails-server-port-env-var

Use the PORT environment variable for rails server
This commit is contained in:
Rafael Mendonça França 2015-08-24 12:11:36 -03:00
commit 1c1ad2b746
3 changed files with 12 additions and 1 deletions

View File

@ -1,3 +1,7 @@
* `rails server` will now honour the `PORT` environment variable
*David Cornu*
* Plugins generated using `rails plugin new` are now generated with the
version number set to 0.1.0.

View File

@ -86,7 +86,7 @@ module Rails
def default_options
super.merge({
Port: 3000,
Port: ENV.fetch('PORT', 3000).to_i,
DoNotReverseLookup: true,
environment: (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup,
daemonize: false,

View File

@ -44,6 +44,13 @@ class Rails::ServerTest < ActiveSupport::TestCase
end
end
def test_environment_with_port
switch_env "PORT", "1234" do
server = Rails::Server.new
assert_equal 1234, server.options[:Port]
end
end
def test_caching_without_option
args = []
options = Rails::Server::Options.new.parse!(args)