2012-03-20 19:28:30 -04:00
|
|
|
require 'abstract_unit'
|
2012-12-06 07:05:45 -05:00
|
|
|
require 'env_helpers'
|
2012-03-20 19:28:30 -04:00
|
|
|
require 'rails/commands/server'
|
|
|
|
|
|
|
|
class Rails::ServerTest < ActiveSupport::TestCase
|
2012-12-06 07:05:45 -05:00
|
|
|
include EnvHelpers
|
2012-03-20 19:28:30 -04:00
|
|
|
|
|
|
|
def test_environment_with_server_option
|
2012-05-15 05:37:54 -04:00
|
|
|
args = ["thin", "-e", "production"]
|
2012-03-20 19:28:30 -04:00
|
|
|
options = Rails::Server::Options.new.parse!(args)
|
|
|
|
assert_equal 'production', options[:environment]
|
|
|
|
assert_equal 'thin', options[:server]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_environment_without_server_option
|
2012-05-15 05:37:54 -04:00
|
|
|
args = ["-e", "production"]
|
2012-03-20 19:28:30 -04:00
|
|
|
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
|
2012-12-05 12:05:33 -05:00
|
|
|
|
|
|
|
def test_environment_with_rails_env
|
2015-03-20 11:14:11 -04:00
|
|
|
with_rack_env nil do
|
|
|
|
with_rails_env 'production' do
|
|
|
|
server = Rails::Server.new
|
|
|
|
assert_equal 'production', server.options[:environment]
|
|
|
|
end
|
2012-12-06 07:05:45 -05:00
|
|
|
end
|
2012-12-05 12:05:33 -05:00
|
|
|
end
|
|
|
|
|
2015-03-20 11:14:11 -04:00
|
|
|
def test_environment_with_rack_env
|
2013-10-12 14:27:13 -04:00
|
|
|
with_rails_env nil do
|
2015-03-20 11:14:11 -04:00
|
|
|
with_rack_env 'production' do
|
|
|
|
server = Rails::Server.new
|
|
|
|
assert_equal 'production', server.options[:environment]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-03-19 05:06:28 -04:00
|
|
|
|
2015-08-17 14:02:35 -04:00
|
|
|
def test_environment_with_port
|
|
|
|
switch_env "PORT", "1234" do
|
|
|
|
server = Rails::Server.new
|
|
|
|
assert_equal 1234, server.options[:Port]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-07-20 23:35:20 -04:00
|
|
|
def test_caching_without_option
|
|
|
|
args = []
|
|
|
|
options = Rails::Server::Options.new.parse!(args)
|
|
|
|
assert_equal nil, options[:caching]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_caching_with_option
|
|
|
|
args = ["--dev-caching"]
|
|
|
|
options = Rails::Server::Options.new.parse!(args)
|
|
|
|
assert_equal true, options[:caching]
|
|
|
|
|
|
|
|
args = ["--no-dev-caching"]
|
|
|
|
options = Rails::Server::Options.new.parse!(args)
|
|
|
|
assert_equal false, options[:caching]
|
|
|
|
end
|
|
|
|
|
2015-03-20 11:14:11 -04:00
|
|
|
def test_log_stdout
|
|
|
|
with_rack_env nil do
|
|
|
|
with_rails_env nil do
|
2015-03-19 05:06:28 -04:00
|
|
|
args = []
|
2013-10-12 14:27:13 -04:00
|
|
|
options = Rails::Server::Options.new.parse!(args)
|
|
|
|
assert_equal true, options[:log_stdout]
|
|
|
|
|
2015-03-20 11:14:11 -04:00
|
|
|
args = ["-e", "development"]
|
|
|
|
options = Rails::Server::Options.new.parse!(args)
|
|
|
|
assert_equal true, options[:log_stdout]
|
|
|
|
|
|
|
|
args = ["-e", "production"]
|
2013-10-12 14:27:13 -04:00
|
|
|
options = Rails::Server::Options.new.parse!(args)
|
|
|
|
assert_equal false, options[:log_stdout]
|
2015-03-20 11:14:11 -04:00
|
|
|
|
|
|
|
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
|
2013-10-12 14:27:13 -04:00
|
|
|
end
|
|
|
|
end
|
2013-06-18 16:24:00 -04:00
|
|
|
end
|
2012-03-20 19:28:30 -04:00
|
|
|
end
|