aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/commands/server_test.rb
blob: 6a75207ebb7e4e85827057ccdf1d08bc48de85c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'abstract_unit'
require 'rails/commands/server'

class Rails::ServerTest < ActiveSupport::TestCase

  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
    rails = ENV['RAILS_ENV']
    ENV['RAILS_ENV'] = 'production'
    server = Rails::Server.new
    assert_equal 'production', server.options[:environment]
  ensure
    ENV['RAILS_ENV'] = rails
  end

  def test_environment_with_rack_env
    rack, rails = ENV['RACK_ENV'], ENV['RAILS_ENV']
    ENV['RAILS_ENV'] = nil
    ENV['RACK_ENV'] = 'production'
    server = Rails::Server.new
    assert_equal 'production', server.options[:environment]
  ensure
    ENV['RACK_ENV'] = rack
    ENV['RAILS_ENV'] = rails
  end
end