Skip to content

Commit

Permalink
Make logging to stdout work again with implicit development env
Browse files Browse the repository at this point in the history
  • Loading branch information
schuetzm committed Oct 13, 2013
1 parent 3651101 commit 16c0023
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
3 changes: 2 additions & 1 deletion railties/lib/rails/commands/server.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'fileutils'
require 'optparse'
require 'action_dispatch'
require 'rails'

module Rails
class Server < ::Rack::Server
Expand Down Expand Up @@ -32,7 +33,7 @@ def parse!(args)

opt_parser.parse! args

options[:log_stdout] = options[:daemonize].blank? && options[:environment] == "development"
options[:log_stdout] = options[:daemonize].blank? && (options[:environment] || Rails.env) == "development"
options[:server] = args.shift
options
end
Expand Down
60 changes: 48 additions & 12 deletions railties/test/commands/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,62 @@ def test_server_option_without_environment
end

def test_environment_with_rails_env
with_rails_env 'production' do
server = Rails::Server.new
assert_equal 'production', server.options[:environment]
with_rack_env nil do
with_rails_env 'production' do
server = Rails::Server.new
assert_equal 'production', server.options[:environment]
end
end
end

def test_environment_with_rack_env
with_rack_env 'production' do
server = Rails::Server.new
assert_equal 'production', server.options[:environment]
with_rails_env nil do
with_rack_env 'production' do
server = Rails::Server.new
assert_equal 'production', server.options[:environment]
end
end
end

def test_log_stdout
args = ["-e", "development"]
options = Rails::Server::Options.new.parse!(args)
assert_equal true, options[:log_stdout]
with_rack_env nil do
with_rails_env nil do
args = []
options = Rails::Server::Options.new.parse!(args)
assert_equal true, options[:log_stdout]

args = ["-e", "production"]
options = Rails::Server::Options.new.parse!(args)
assert_equal false, options[:log_stdout]
args = ["-e", "development"]
options = Rails::Server::Options.new.parse!(args)
assert_equal true, options[:log_stdout]

args = ["-e", "production"]
options = Rails::Server::Options.new.parse!(args)
assert_equal false, options[:log_stdout]

with_rack_env 'development' do
args = []
options = Rails::Server::Options.new.parse!(args)
assert_equal true, options[:log_stdout]
end

with_rack_env 'production' do
args = []
options = Rails::Server::Options.new.parse!(args)
assert_equal false, options[:log_stdout]
end

with_rails_env 'development' do
args = []
options = Rails::Server::Options.new.parse!(args)
assert_equal true, options[:log_stdout]
end

with_rails_env 'production' do
args = []
options = Rails::Server::Options.new.parse!(args)
assert_equal false, options[:log_stdout]
end
end
end
end
end
4 changes: 4 additions & 0 deletions railties/test/env_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require 'rails'

module EnvHelpers
private

def with_rails_env(env)
Rails.instance_variable_set :@_env, nil
switch_env 'RAILS_ENV', env do
switch_env 'RACK_ENV', nil do
yield
Expand All @@ -10,6 +13,7 @@ def with_rails_env(env)
end

def with_rack_env(env)
Rails.instance_variable_set :@_env, nil
switch_env 'RACK_ENV', env do
switch_env 'RAILS_ENV', nil do
yield
Expand Down

0 comments on commit 16c0023

Please sign in to comment.