Adding specs for log_overrider
This commit is contained in:
parent
b0a123b270
commit
fb85ffe406
2 changed files with 27 additions and 3 deletions
|
|
@ -4,7 +4,7 @@ class ActionView::LogSubscriber
|
|||
message << "template=#{from_rails_root(event.payload[:identifier])} "
|
||||
message << "layout=#{from_rails_root(event.payload[:layout])} " if event.payload[:layout]
|
||||
message << "time=#{("%.1fms" % event.duration)}"
|
||||
info(message)
|
||||
Rails.logger.info(message)
|
||||
end
|
||||
alias :render_partial :render_template
|
||||
alias :render_collection :render_template
|
||||
|
|
@ -16,7 +16,7 @@ class ActionController::LogSubscriber
|
|||
params = payload[:params].except(*INTERNAL_PARAMS)
|
||||
log_string = "event=request_routed controller=#{payload[:controller]} action=#{payload[:action]} format=#{payload[:formats].first.to_s.upcase} "
|
||||
log_string << "params='#{params.inspect}'" unless params.empty?
|
||||
info(log_string)
|
||||
Rails.logger.info(log_string)
|
||||
end
|
||||
|
||||
def process_action(event)
|
||||
|
|
@ -27,6 +27,6 @@ class ActionController::LogSubscriber
|
|||
log_string << "hstatus=#{Rack::Utils::HTTP_STATUS_CODES[payload[:status]]} time=#{"%.0fms" % event.duration} "
|
||||
log_string << " (#{additions.join(" | ")})" unless additions.blank?
|
||||
|
||||
info(log_string)
|
||||
Rails.logger.info(log_string)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,6 +24,30 @@ describe HomeController do
|
|||
get :show
|
||||
response.should redirect_to aspects_path
|
||||
end
|
||||
end
|
||||
|
||||
#This describe should apply to any controller class. HomeController is just the simplest.
|
||||
describe 'logging' do
|
||||
before do
|
||||
logger = FakeLogger.new
|
||||
Rails.stub(:logger).and_return(FakeLogger.new)
|
||||
get :show
|
||||
end
|
||||
|
||||
it 'logs the routing of a request' do
|
||||
Rails.logger.infos.first.include?('event=request_routed').should be_true
|
||||
end
|
||||
it 'logs the completion of a request' do
|
||||
Rails.logger.infos.last.include?('event=request_completed').should be_true
|
||||
end
|
||||
end
|
||||
class FakeLogger
|
||||
attr_accessor :infos
|
||||
def initialize
|
||||
self.infos = []
|
||||
end
|
||||
def info line
|
||||
self.infos << line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue