aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/initializer_test.rb
blob: 1b6af718c04028c5be724dd79857bf7f62a34552 (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
require "isolation/abstract_unit"

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

    def setup
      build_app
      boot_rails
    end

    test "initializing an application initializes rails" do
      class MyApp < Rails::Application ; end

      if RUBY_VERSION < '1.9'
        $KCODE = ''
        MyApp.new
        assert_equal 'UTF8', $KCODE
      else
        Encoding.default_external = Encoding::US_ASCII
        MyApp.new
        assert_equal Encoding::UTF_8, Encoding.default_external
      end
    end

    test "initializing an application adds the application paths to the load path" do
      class MyApp < Rails::Application ; end

      MyApp.new
      assert $:.include?("#{app_path}/app/models")
    end

    test "adding an unknown framework raises an error" do
      class MyApp < Rails::Application
        config.frameworks << :action_foo
      end

      assert_raises RuntimeError do
        MyApp.new
      end
    end

    test "eager loading loads parent classes before children" do
      app_file "lib/zoo.rb", <<-ZOO
        class Zoo ; include ReptileHouse ; end
      ZOO
      app_file "lib/zoo/reptile_house.rb", <<-ZOO
        module Zoo::ReptileHouse ; end
      ZOO

      Rails::Initializer.run do |config|
        config.eager_load_paths = "#{app_path}/lib"
      end

      assert Zoo
    end
  end
end