Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

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  
    1212  end 
    1313end 
    1414 
    15 class BenchmarkTest < Test::Unit::TestCase 
    16   class MockLogger 
    17     def method_missing(*args) 
     15uses_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" 
    1823    end 
    19   end 
    2024 
    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 
    2829 
    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 
    3237  end 
    3338end 
  • actionpack/lib/action_controller/benchmarking.rb

    old new  
    3131        end 
    3232      end 
    3333 
    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
    3535      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 } 
    4037      end 
    4138    end 
    4239