diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/log_subscriber.rb | 3 | ||||
-rw-r--r-- | railties/test/log_subscriber_test.rb | 8 |
2 files changed, 9 insertions, 2 deletions
diff --git a/railties/lib/rails/log_subscriber.rb b/railties/lib/rails/log_subscriber.rb index c867b92b6b..05cb70690a 100644 --- a/railties/lib/rails/log_subscriber.rb +++ b/railties/lib/rails/log_subscriber.rb @@ -60,8 +60,9 @@ module Rails def self.dispatch(args) namespace, name = args[0].split(".") - log_subscriber = log_subscribers[namespace.to_sym] + return unless namespace && name + log_subscriber = log_subscribers[namespace.to_sym] if log_subscriber.respond_to?(name) && log_subscriber.logger begin log_subscriber.send(name, ActiveSupport::Notifications::Event.new(*args)) diff --git a/railties/test/log_subscriber_test.rb b/railties/test/log_subscriber_test.rb index be176df1bb..a4de023e65 100644 --- a/railties/test/log_subscriber_test.rb +++ b/railties/test/log_subscriber_test.rb @@ -79,7 +79,7 @@ class SyncLogSubscriberTest < ActiveSupport::TestCase Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber instrument "my_log_subscriber.unknown_event" wait - # If we get here, it means that NoMethodError was raised. + # If we get here, it means that NoMethodError was not raised. end def test_does_not_send_the_event_if_logger_is_nil @@ -90,6 +90,12 @@ class SyncLogSubscriberTest < ActiveSupport::TestCase 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! |