aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/rack/logger_test.rb
blob: 984d8374fbc429ea00cba19609b223ba971799b9 (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
require "isolation/abstract_unit"
require "active_support/log_subscriber/test_helper"
require "rack/test"
require "mocha/setup"

module ApplicationTests
  module RackTests
    class LoggerTest < Test::Unit::TestCase
      include ActiveSupport::LogSubscriber::TestHelper
      include Rack::Test::Methods

      def setup
        build_app
        require "#{app_path}/config/environment"
        super
        @logger = MockLogger.new
        Rails.stubs(:logger).returns(@logger)
      end

      def teardown
        teardown_app
      end

      def logs
        @logs ||= @logger.logged(:info).join("\n")
      end

      test "logger logs proper HTTP verb and path" do
        get "/blah"
        wait
        assert_match 'Started GET "/blah"', logs
      end

      test "logger logs HTTP verb override" do
        post "/", :_method => 'put'
        wait
        assert_match 'Started PUT "/"', logs
      end

      test "logger logs HEAD requests" do
        post "/", :_method => 'head'
        wait
        assert_match 'Started HEAD "/"', logs
      end
    end
  end
end