2011-05-07 04:19:01 -04:00
|
|
|
require "isolation/abstract_unit"
|
|
|
|
require "active_support/log_subscriber/test_helper"
|
|
|
|
require "rack/test"
|
|
|
|
|
|
|
|
module ApplicationTests
|
|
|
|
module RackTests
|
2012-01-05 20:30:17 -05:00
|
|
|
class LoggerTest < ActiveSupport::TestCase
|
2012-06-19 22:21:00 -04:00
|
|
|
include ActiveSupport::Testing::Isolation
|
2011-05-07 04:19:01 -04:00
|
|
|
include ActiveSupport::LogSubscriber::TestHelper
|
|
|
|
include Rack::Test::Methods
|
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
super
|
2011-10-26 03:17:14 -04:00
|
|
|
@logger = MockLogger.new
|
|
|
|
Rails.stubs(:logger).returns(@logger)
|
2011-05-07 04:19:01 -04:00
|
|
|
end
|
|
|
|
|
2011-06-06 08:54:05 -04:00
|
|
|
def teardown
|
2012-06-19 22:21:00 -04:00
|
|
|
super
|
2011-06-06 08:54:05 -04:00
|
|
|
teardown_app
|
|
|
|
end
|
|
|
|
|
2011-05-07 04:19:01 -04:00
|
|
|
def logs
|
|
|
|
@logs ||= @logger.logged(:info)
|
|
|
|
end
|
|
|
|
|
2012-07-23 12:50:48 -04:00
|
|
|
test "logger logs proper HTTP GET verb and path" do
|
2011-05-07 04:19:01 -04:00
|
|
|
get "/blah"
|
|
|
|
wait
|
2011-05-23 20:45:00 -04:00
|
|
|
assert_match(/^Started GET "\/blah"/, logs[0])
|
2011-05-07 04:19:01 -04:00
|
|
|
end
|
|
|
|
|
2012-07-23 12:50:48 -04:00
|
|
|
test "logger logs proper HTTP HEAD verb and path" do
|
|
|
|
head "/blah"
|
|
|
|
wait
|
|
|
|
assert_match(/^Started HEAD "\/blah"/, logs[0])
|
|
|
|
end
|
|
|
|
|
2011-05-07 04:19:01 -04:00
|
|
|
test "logger logs HTTP verb override" do
|
|
|
|
post "/", {:_method => 'put'}
|
|
|
|
wait
|
2011-05-23 20:45:00 -04:00
|
|
|
assert_match(/^Started PUT "\/"/, logs[0])
|
2011-05-07 04:19:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "logger logs HEAD requests" do
|
|
|
|
post "/", {:_method => 'head'}
|
|
|
|
wait
|
2011-05-23 20:45:00 -04:00
|
|
|
assert_match(/^Started HEAD "\/"/, logs[0])
|
2011-05-07 04:19:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|