aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/configuration_test.rb
blob: 83e14019932b18e94e6c58e45e5dd5b614af4593 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require "isolation/abstract_unit"

module ApplicationTests
  class InitializerTest < Test::Unit::TestCase
    include ActiveSupport::Testing::Isolation

    def setup
      build_app
      boot_rails
    end

    test "the application root is set correctly" do
      require "#{app_path}/config/environment"
      assert_equal Pathname.new(app_path), Rails.application.root
    end

    test "the application root can be set" do
      FileUtils.mkdir_p("#{app_path}/hello")
      add_to_config <<-RUBY
        config.frameworks = []
        config.root = '#{app_path}/hello'
      RUBY
      require "#{app_path}/config/environment"
      assert_equal Pathname.new("#{app_path}/hello"), Rails.application.root
    end

    test "the application root is detected as where config.ru is located" do
      add_to_config <<-RUBY
        config.frameworks = []
      RUBY
      FileUtils.mv "#{app_path}/config.ru", "#{app_path}/config/config.ru"
      require "#{app_path}/config/environment"
      assert_equal Pathname.new("#{app_path}/config"), Rails.application.root
    end

    test "the application root is Dir.pwd if there is no config.ru" do
      File.delete("#{app_path}/config.ru")
      add_to_config <<-RUBY
        config.frameworks = []
      RUBY

      Dir.chdir("#{app_path}/app") do
        require "#{app_path}/config/environment"
        assert_equal Pathname.new("#{app_path}/app"), Rails.application.root
      end
    end

    test "config.active_support.bare does not require all of ActiveSupport" do
      add_to_config "config.frameworks = []; config.active_support.bare = true"

      Dir.chdir("#{app_path}/app") do
        require "#{app_path}/config/environment"
        assert_raises(NoMethodError) { 1.day }
      end
    end

    test "marking the application as threadsafe sets the correct config variables" do
      add_to_config <<-RUBY
        config.threadsafe!
      RUBY

      require "#{app_path}/config/application"
      assert AppTemplate::Application.configuration.action_controller.allow_concurrency
    end

    test "the application can be marked as threadsafe when there are no frameworks" do
      FileUtils.rm_rf("#{app_path}/config/environments")
      add_to_config <<-RUBY
        config.frameworks = []
        config.threadsafe!
      RUBY

      assert_nothing_raised do
        require "#{app_path}/config/application"
      end
    end
  end
end