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
|
2014-07-07 21:57:55 -04:00
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.logger = ActiveSupport::LogSubscriber::TestHelper::MockLogger.new
|
|
|
|
RUBY
|
|
|
|
|
2011-05-07 04:19:01 -04:00
|
|
|
require "#{app_path}/config/environment"
|
|
|
|
super
|
|
|
|
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
|
2014-07-07 21:57:55 -04:00
|
|
|
@logs ||= Rails.logger.logged(:info).join("\n")
|
2011-05-07 04:19:01 -04:00
|
|
|
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
|
2012-09-26 18:08:25 -04:00
|
|
|
assert_match 'Started GET "/blah"', logs
|
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
|
2012-09-26 18:08:25 -04:00
|
|
|
assert_match 'Started HEAD "/blah"', logs
|
2012-07-23 12:50:48 -04:00
|
|
|
end
|
|
|
|
|
2011-05-07 04:19:01 -04:00
|
|
|
test "logger logs HTTP verb override" do
|
2012-09-26 18:08:25 -04:00
|
|
|
post "/", _method: 'put'
|
2011-05-07 04:19:01 -04:00
|
|
|
wait
|
2012-09-26 18:08:25 -04:00
|
|
|
assert_match 'Started PUT "/"', logs
|
2011-05-07 04:19:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "logger logs HEAD requests" do
|
2012-09-26 18:08:25 -04:00
|
|
|
post "/", _method: 'head'
|
2011-05-07 04:19:01 -04:00
|
|
|
wait
|
2012-09-26 18:08:25 -04:00
|
|
|
assert_match 'Started HEAD "/"', logs
|
2011-05-07 04:19:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|