aboutsummaryrefslogblamecommitdiffstats
path: root/railties/test/application/rack/logger_test.rb
blob: a77c6f472c1d6e48fa285c84e3d2af9200b153e3 (plain) (tree)
1
2
3
4
5
6
7





                                                   
                                              






                                                      

                                             

         



                    






                                                     
                                                      




                                              
                                                  




                                         
                                                   



         
require "isolation/abstract_unit"
require "active_support/log_subscriber/test_helper"
require "rack/test"

module ApplicationTests
  module RackTests
    class LoggerTest < ActiveSupport::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)
      end

      test "logger logs proper HTTP verb and path" do
        get "/blah"
        wait
        assert_match(/^Started GET "\/blah"/, logs[0])
      end

      test "logger logs HTTP verb override" do
        post "/", {:_method => 'put'}
        wait
        assert_match(/^Started PUT "\/"/, logs[0])
      end

      test "logger logs HEAD requests" do
        post "/", {:_method => 'head'}
        wait
        assert_match(/^Started HEAD "\/"/, logs[0])
      end
    end
  end
end