Skip to content

Commit

Permalink
Update pumactl to remove development as default environment
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSpeed committed Oct 15, 2019
1 parent 860c175 commit e021a7f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/puma/control_cli.rb
Expand Up @@ -22,7 +22,7 @@ def initialize(argv, stdout=STDOUT, stderr=STDERR)
@control_auth_token = nil
@config_file = nil
@command = nil
@environment = ENV['RACK_ENV'] || "development"
@environment = ENV['RACK_ENV']

@argv = argv.dup
@stdout = stdout
Expand Down Expand Up @@ -82,8 +82,10 @@ def initialize(argv, stdout=STDOUT, stderr=STDERR)
@command = argv.shift

unless @config_file == '-'
environment = @environment || 'development'

if @config_file.nil?
@config_file = %W(config/puma/#{@environment}.rb config/puma.rb).find do |f|
@config_file = %W(config/puma/#{environment}.rb config/puma.rb).find do |f|
File.exist?(f)
end
end
Expand Down
49 changes: 44 additions & 5 deletions test/test_pumactl.rb
Expand Up @@ -29,16 +29,54 @@ def test_config_file
assert_equal "t3-pid", control_cli.instance_variable_get("@pidfile")
end

def test_environment
ENV.delete 'RACK_ENV' # remove from travis
def test_rack_env_without_environment
ENV.update("RACK_ENV" => "test")
control_cli = Puma::ControlCLI.new ["halt"]
assert_equal "development", control_cli.instance_variable_get("@environment")
assert_equal "test", control_cli.instance_variable_get("@environment")
end

def test_environment_without_rack_env
ENV.delete "RACK_ENV" # remove from travis
control_cli = Puma::ControlCLI.new ["halt"]
assert_nil control_cli.instance_variable_get("@environment")
control_cli = Puma::ControlCLI.new ["-e", "test", "halt"]
assert_equal "test", control_cli.instance_variable_get("@environment")
end

def test_environment_with_rack_env
ENV.update("RACK_ENV" => "production")
control_cli = Puma::ControlCLI.new ["halt"]
assert_equal "production", control_cli.instance_variable_get("@environment")
control_cli = Puma::ControlCLI.new ["-e", "test", "halt"]
assert_equal "test", control_cli.instance_variable_get("@environment")
end

def test_config_file_exist
ENV.delete 'RACK_ENV' # remove from travis
def test_environment_specific_config_file_exist
ENV.delete "RACK_ENV"
port = 6002
Dir.mktmpdir do |tmp_dir|
Dir.chdir(tmp_dir) do
FileUtils.mkdir("config")
File.open("config/puma.rb", "w") { |f| f << "port #{port}" }
control_cli = Puma::ControlCLI.new ["-e", "production", "halt"]
assert_equal "config/puma.rb",
control_cli.instance_variable_get("@config_file")
end
end

Dir.mktmpdir do |tmp_dir|
Dir.chdir(tmp_dir) do
FileUtils.mkdir_p("config/puma")
File.open("config/puma/production.rb", "w") { |f| f << "port #{port}" }
control_cli = Puma::ControlCLI.new ["-e", "production", "halt"]
assert_equal "config/puma/production.rb",
control_cli.instance_variable_get("@config_file")
end
end
end

def test_default_config_file_exist
ENV.delete "RACK_ENV" # remove from travis
port = 6001
Dir.mktmpdir do |d|
Dir.chdir(d) do
Expand All @@ -49,6 +87,7 @@ def test_config_file_exist
control_cli.instance_variable_get("@config_file")
end
end

Dir.mktmpdir do |d|
Dir.chdir(d) do
FileUtils.mkdir_p("config/puma")
Expand Down

0 comments on commit e021a7f

Please sign in to comment.