Ticket #10613: action_controller_logger_silence_patch.diff
| File action_controller_logger_silence_patch.diff, 2.3 kB (added by dubek, 10 months ago) |
|---|
-
actionpack/test/controller/benchmark_test.rb
old new 12 12 end 13 13 end 14 14 15 class BenchmarkTest < Test::Unit::TestCase 16 class MockLogger 17 def method_missing(*args) 15 uses_mocha "Benchmark test" do 16 class BenchmarkTest < Test::Unit::TestCase 17 def setup 18 @controller = BenchmarkedController.new 19 # benchmark doesn't do anything unless a logger is set 20 @controller.logger = stub_everything('benchmark_controller', :level => Logger::DEBUG) 21 @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new 22 @request.host = "test.actioncontroller.i" 18 23 end 19 end20 24 21 def setup 22 @controller = BenchmarkedController.new 23 # benchmark doesn't do anything unless a logger is set 24 @controller.logger = MockLogger.new 25 @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new 26 @request.host = "test.actioncontroller.i" 27 end 25 def test_with_http_1_0_request 26 @request.host = nil 27 assert_nothing_raised { get :public_action } 28 end 28 29 29 def test_with_http_1_0_request 30 @request.host = nil 31 assert_nothing_raised { get :public_action } 30 def test_benchmark_should_silence_the_logger 31 @controller.logger.expects(:silence) 32 @controller.logger.expects(:add) 33 @controller.class.benchmark "Benchmark test" do 34 # dummy block, not really executed 35 end 36 end 32 37 end 33 38 end -
actionpack/lib/action_controller/benchmarking.rb
old new 31 31 end 32 32 end 33 33 34 # Silences the logger for the duration of the block.34 # Silences the logger for the duration of a block. Uses the logger's own silence method. 35 35 def silence 36 old_logger_level, logger.level = logger.level, Logger::ERROR if logger 37 yield 38 ensure 39 logger.level = old_logger_level if logger 36 logger.silence { yield } 40 37 end 41 38 end 42 39