diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-10-03 23:43:12 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-10-03 23:43:12 +0000 |
commit | 748e6873c2c74eecd4985e0d2ff2bf4c3c95ea80 (patch) | |
tree | 6ec5dca529f9a8cebdb01b9db4c2100ec8c619dd /activesupport/test | |
parent | 406ea8f31db6ee8c74890e2f3f36217f07480892 (diff) | |
download | rails-748e6873c2c74eecd4985e0d2ff2bf4c3c95ea80.tar.gz rails-748e6873c2c74eecd4985e0d2ff2bf4c3c95ea80.tar.bz2 rails-748e6873c2c74eecd4985e0d2ff2bf4c3c95ea80.zip |
BufferedLogger#auto_flushing = N flushes the log every N messages. Buffers with an array instead of string.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7732 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/buffered_logger_test.rb | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb index 9a78ee3694..cabdb59045 100644 --- a/activesupport/test/buffered_logger_test.rb +++ b/activesupport/test/buffered_logger_test.rb @@ -8,7 +8,7 @@ class BufferedLoggerTest < Test::Unit::TestCase @output = StringIO.new @logger = ActiveSupport::BufferedLogger.new(@output) end - + def test_should_log_debugging_message_when_debugging @logger.level = Logger::DEBUG @logger.add(Logger::DEBUG, @message) @@ -26,35 +26,62 @@ class BufferedLoggerTest < Test::Unit::TestCase @logger.add(Logger::INFO) {@message} assert @output.string.include?(@message) end - + def test_should_add_message_passed_as_block_when_using_shortcut @logger.level = Logger::INFO @logger.info {@message} assert @output.string.include?(@message) end - + def test_should_convert_message_to_string @logger.level = Logger::INFO @logger.info @integer_message assert @output.string.include?(@integer_message.to_s) end - + def test_should_convert_message_to_string_when_passed_in_block @logger.level = Logger::INFO @logger.info {@integer_message} assert @output.string.include?(@integer_message.to_s) end - + def test_should_not_evaluate_block_if_message_wont_be_logged @logger.level = Logger::INFO evaluated = false @logger.add(Logger::DEBUG) {evaluated = true} - assert evaluated == false + assert evaluated == false end - + def test_should_not_mutate_message message_copy = @message.dup @logger.info @message assert_equal message_copy, @message end + + + [false, nil, 0].each do |disable| + define_method "test_disabling_auto_flush_with_#{disable.inspect}_should_buffer_until_explicit_flush" do + @logger.auto_flushing = disable + + 4.times do + @logger.info 'wait for it..' + assert @output.string.empty?, @output.string + end + + @logger.flush + assert !@output.string.empty?, @logger.buffer.size + end + end + + def test_should_auto_flush_every_n_messages + @logger.auto_flushing = 5 + + 4.times do + @logger.info 'wait for it..' + assert @output.string.empty?, @output.string + end + + @logger.info 'there it is.' + assert !@output.string.empty?, @output.string + end end |