1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/test/commands/server_test.rb

89 lines
2.5 KiB
Ruby
Raw Normal View History

require 'abstract_unit'
require 'env_helpers'
require 'rails/commands/server'
class Rails::ServerTest < ActiveSupport::TestCase
include EnvHelpers
def test_environment_with_server_option
args = ["thin", "-e", "production"]
options = Rails::Server::Options.new.parse!(args)
assert_equal 'production', options[:environment]
assert_equal 'thin', options[:server]
end
def test_environment_without_server_option
args = ["-e", "production"]
options = Rails::Server::Options.new.parse!(args)
assert_equal 'production', options[:environment]
assert_nil options[:server]
end
def test_server_option_without_environment
args = ["thin"]
options = Rails::Server::Options.new.parse!(args)
assert_nil options[:environment]
assert_equal 'thin', options[:server]
end
def test_environment_with_rails_env
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_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
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", "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
Only output Server logs in Development Right now when you start a server via `rails s`, the logger gets extended so that it logs to the file system and also to stdout. This extension behavior is not "intelligent" and if the default logger is already set to output to stdout, then the contents will be received twice. To capture logs in accordance with http://www.12factor.net/logs some platforms require the logs to be sent to standard out. If a logger is set to stdout, and the server is started using `rails server` instead of another method (i.e. `thin start` etc.) then the app will produce double logs. This PR fixes the issue by only extending the logger to standard out in the development environment. So that in production you don't get double logs like this: ``` ActionView::Template::Error (wrong number of arguments (5 for 4)): 1: <% lang_index = 0 %> 2: <div class="row"> 3: <ul class="nav nav-tabs nav-stacked span2" data-tabs="tabs" id="repo-tabs"> 4: <% repos.group_by(&:language).each do |lang, repos| %> 5: <% unless lang == nil %> 6: <li><a href="#<%= "#{lang.parameterize}#{lang.hash}" %>" data-toggle="tab"><%= lang %></a></li> 7: <% end -%> app/views/shared/_repos.html.erb:4:in `_app_views_shared__repos_html_erb___1685450633638247395_70300668607000' app/views/pages/index.html.erb:13:in `_app_views_pages_index_html_erb__2084723628308867770_70300687584880' ActionView::Template::Error (wrong number of arguments (5 for 4)): 1: <% lang_index = 0 %> 2: <div class="row"> 3: <ul class="nav nav-tabs nav-stacked span2" data-tabs="tabs" id="repo-tabs"> 4: <% repos.group_by(&:language).each do |lang, repos| %> 5: <% unless lang == nil %> 6: <li><a href="#<%= "#{lang.parameterize}#{lang.hash}" %>" data-toggle="tab"><%= lang %></a></li> 7: <% end -%> app/views/shared/_repos.html.erb:4:in `_app_views_shared__repos_html_erb___1685450633638247395_70300668607000' app/views/pages/index.html.erb:13:in `_app_views_pages_index_html_erb__2084723628308867770_70300687584880' ``` ATP Railties. Opened against master in favor of #10999
2013-06-18 16:24:00 -04:00
end
end