aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/load_test.rb
blob: 75dbf56a2140f37181d8b72b995883618d00f821 (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
require "isolation/abstract_unit"
require "rails"
require 'action_dispatch'

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

    def setup
      build_app
    end

    test "rails app is present" do
      assert File.exist?(app_path("config"))
    end

    test "running Rails::Application.load on the path returns a (vaguely) useful application" do
      app_file "config.ru", <<-CONFIG
        require File.dirname(__FILE__) + '/config/environment'
        use Rails::Rack::Static
        run ActionController::Dispatcher.new
      CONFIG

      @app = ActionDispatch::Utils.parse_config("#{app_path}/config.ru")
      assert_welcome get("/")
    end

    test "config.ru is used" do
      app_file "config.ru", <<-CONFIG
        class MyMiddleware
          def initialize(app)
            @app = app
          end

          def call(env)
            status, headers, body = @app.call(env)
            headers["Config-Ru-Test"] = "TESTING"
            [status, headers, body]
          end
        end

        use MyMiddleware
        run proc {|env| [200, {"Content-Type" => "text/html"}, ["VICTORY"]] }
      CONFIG

      @app = ActionDispatch::Utils.parse_config("#{app_path}/config.ru")

      assert_body    "VICTORY", get("/omg")
      assert_header  "Config-Ru-Test", "TESTING", get("/omg")
    end

    test "arbitrary.rb can be used as a config" do
      app_file "myapp.rb", <<-CONFIG
        Myapp = proc {|env| [200, {"Content-Type" => "text/html"}, ["OMG ROBOTS"]] }
      CONFIG

      @app = ActionDispatch::Utils.parse_config("#{app_path}/myapp.rb")

      assert_body "OMG ROBOTS", get("/omg")
    end
  end
end