diff options
author | José Valim <jose.valim@gmail.com> | 2010-06-24 13:23:43 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-24 13:23:43 +0200 |
commit | 6788db824ab732b13493a9d702dd8fb89fa153c8 (patch) | |
tree | ad9314fdd10b55ebb035959a71be0de921cb0d02 /railties/test | |
parent | 5441e082f9478ddb3c676c681b09786f1391483c (diff) | |
download | rails-6788db824ab732b13493a9d702dd8fb89fa153c8.tar.gz rails-6788db824ab732b13493a9d702dd8fb89fa153c8.tar.bz2 rails-6788db824ab732b13493a9d702dd8fb89fa153c8.zip |
Move Rails::LogSubscriber to ActiveSupport::LogSubscriber, allowing frameworks like ActiveRecord and ActiveResource to log outsude Rails::Application [#4816 state:resolved]
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/log_subscriber_test.rb | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/railties/test/log_subscriber_test.rb b/railties/test/log_subscriber_test.rb deleted file mode 100644 index a3a755ae62..0000000000 --- a/railties/test/log_subscriber_test.rb +++ /dev/null @@ -1,123 +0,0 @@ -require 'abstract_unit' -require 'rails/log_subscriber/test_helper' - -class MyLogSubscriber < Rails::LogSubscriber - attr_reader :event - - def some_event(event) - @event = event - info event.name - end - - def foo(event) - debug "debug" - info "info" - warn "warn" - end - - def bar(event) - info "#{color("cool", :red)}, #{color("isn't it?", :blue, true)}" - end - - def puke(event) - raise "puke" - end -end - -class SyncLogSubscriberTest < ActiveSupport::TestCase - include Rails::LogSubscriber::TestHelper - - def setup - super - @log_subscriber = MyLogSubscriber.new - end - - def teardown - super - Rails::LogSubscriber.log_subscribers.clear - end - - def instrument(*args, &block) - ActiveSupport::Notifications.instrument(*args, &block) - end - - def test_proxies_method_to_rails_logger - @log_subscriber.foo(nil) - assert_equal %w(debug), @logger.logged(:debug) - assert_equal %w(info), @logger.logged(:info) - assert_equal %w(warn), @logger.logged(:warn) - end - - def test_set_color_for_messages - Rails::LogSubscriber.colorize_logging = true - @log_subscriber.bar(nil) - assert_equal "\e[31mcool\e[0m, \e[1m\e[34misn't it?\e[0m", @logger.logged(:info).last - end - - def test_does_not_set_color_if_colorize_logging_is_set_to_false - @log_subscriber.bar(nil) - assert_equal "cool, isn't it?", @logger.logged(:info).last - end - - def test_event_is_sent_to_the_registered_class - Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber - instrument "some_event.my_log_subscriber" - wait - assert_equal %w(some_event.my_log_subscriber), @logger.logged(:info) - end - - def test_event_is_an_active_support_notifications_event - Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber - instrument "some_event.my_log_subscriber" - wait - assert_kind_of ActiveSupport::Notifications::Event, @log_subscriber.event - end - - def test_does_not_send_the_event_if_it_doesnt_match_the_class - Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber - instrument "unknown_event.my_log_subscriber" - wait - # If we get here, it means that NoMethodError was not raised. - end - - def test_does_not_send_the_event_if_logger_is_nil - Rails.logger = nil - @log_subscriber.expects(:some_event).never - Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber - instrument "some_event.my_log_subscriber" - wait - end - - def test_does_not_fail_with_non_namespaced_events - Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber - instrument "whatever" - wait - end - - def test_flushes_loggers - Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber - Rails::LogSubscriber.flush_all! - assert_equal 1, @logger.flush_count - end - - def test_flushes_the_same_logger_just_once - Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber - Rails::LogSubscriber.add :another, @log_subscriber - Rails::LogSubscriber.flush_all! - wait - assert_equal 1, @logger.flush_count - end - - def test_logging_does_not_die_on_failures - Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber - instrument "puke.my_log_subscriber" - instrument "some_event.my_log_subscriber" - wait - - assert_equal 1, @logger.logged(:info).size - assert_equal 'some_event.my_log_subscriber', @logger.logged(:info).last - - assert_equal 1, @logger.logged(:error).size - assert_equal 'Could not log "puke.my_log_subscriber" event. RuntimeError: puke', @logger.logged(:error).last - end -end
\ No newline at end of file |