aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2010-02-15 21:44:30 +0700
committerJosé Valim <jose.valim@gmail.com>2010-02-16 22:36:15 +0100
commitf0523f72b46db14e2f50c8347a8708734c650f84 (patch)
treecf6562eb8f6c2e302a33840f36f04d838aadb569 /railties/test
parent7cff54f5d3ae2e364f0d147ceb86ea701b21389c (diff)
downloadrails-f0523f72b46db14e2f50c8347a8708734c650f84.tar.gz
rails-f0523f72b46db14e2f50c8347a8708734c650f84.tar.bz2
rails-f0523f72b46db14e2f50c8347a8708734c650f84.zip
Rename Rails::Subscriber to Rails::LogSubscriber
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/initializers/notifications_test.rb2
-rw-r--r--railties/test/log_subscriber_test.rb119
-rw-r--r--railties/test/railties/railtie_test.rb8
-rw-r--r--railties/test/subscriber_test.rb119
4 files changed, 124 insertions, 124 deletions
diff --git a/railties/test/application/initializers/notifications_test.rb b/railties/test/application/initializers/notifications_test.rb
index 061bb34c19..b99cf5bb4f 100644
--- a/railties/test/application/initializers/notifications_test.rb
+++ b/railties/test/application/initializers/notifications_test.rb
@@ -28,7 +28,7 @@ module ApplicationTests
ActiveSupport::Notifications.notifier.wait
end
- test "rails subscribers are added" do
+ test "rails log_subscribers are added" do
add_to_config <<-RUBY
config.colorize_logging = false
RUBY
diff --git a/railties/test/log_subscriber_test.rb b/railties/test/log_subscriber_test.rb
new file mode 100644
index 0000000000..be176df1bb
--- /dev/null
+++ b/railties/test/log_subscriber_test.rb
@@ -0,0 +1,119 @@
+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
+ Rails::LogSubscriber.instance_variable_set(:@log_tailer, nil)
+ end
+
+ def teardown
+ super
+ Rails::LogSubscriber.log_subscribers.clear
+ Rails::LogSubscriber.instance_variable_set(:@log_tailer, nil)
+ 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 "my_log_subscriber.some_event"
+ wait
+ assert_equal %w(my_log_subscriber.some_event), @logger.logged(:info)
+ end
+
+ def test_event_is_an_active_support_notifications_event
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.some_event"
+ 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 "my_log_subscriber.unknown_event"
+ wait
+ # If we get here, it means that NoMethodError was 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 "my_log_subscriber.some_event"
+ 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 "my_log_subscriber.puke"
+ instrument "my_log_subscriber.some_event"
+ wait
+
+ assert_equal 1, @logger.logged(:info).size
+ assert_equal 'my_log_subscriber.some_event', @logger.logged(:info).last
+
+ assert_equal 1, @logger.logged(:error).size
+ assert_equal 'Could not log "my_log_subscriber.puke" event. RuntimeError: puke', @logger.logged(:error).last
+ end
+end \ No newline at end of file
diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb
index b723e08281..9eb4e9993a 100644
--- a/railties/test/railties/railtie_test.rb
+++ b/railties/test/railties/railtie_test.rb
@@ -51,12 +51,12 @@ module RailtiesTest
assert_equal "bar", Bar.config.foo.bar
end
- test "railtie can add subscribers" do
+ test "railtie can add log subscribers" do
begin
- class Foo < Rails::Railtie ; subscriber(Rails::Subscriber.new) ; end
- assert_kind_of Rails::Subscriber, Rails::Subscriber.subscribers[:foo]
+ class Foo < Rails::Railtie ; log_subscriber(Rails::LogSubscriber.new) ; end
+ assert_kind_of Rails::LogSubscriber, Rails::LogSubscriber.log_subscribers[:foo]
ensure
- Rails::Subscriber.subscribers.clear
+ Rails::LogSubscriber.log_subscribers.clear
end
end
diff --git a/railties/test/subscriber_test.rb b/railties/test/subscriber_test.rb
deleted file mode 100644
index f6c895093f..0000000000
--- a/railties/test/subscriber_test.rb
+++ /dev/null
@@ -1,119 +0,0 @@
-require 'abstract_unit'
-require 'rails/subscriber/test_helper'
-
-class MySubscriber < Rails::Subscriber
- 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 SyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::TestHelper
-
- def setup
- super
- @subscriber = MySubscriber.new
- Rails::Subscriber.instance_variable_set(:@log_tailer, nil)
- end
-
- def teardown
- super
- Rails::Subscriber.subscribers.clear
- Rails::Subscriber.instance_variable_set(:@log_tailer, nil)
- end
-
- def instrument(*args, &block)
- ActiveSupport::Notifications.instrument(*args, &block)
- end
-
- def test_proxies_method_to_rails_logger
- @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::Subscriber.colorize_logging = true
- @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
- @subscriber.bar(nil)
- assert_equal "cool, isn't it?", @logger.logged(:info).last
- end
-
- def test_event_is_sent_to_the_registered_class
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.some_event"
- wait
- assert_equal %w(my_subscriber.some_event), @logger.logged(:info)
- end
-
- def test_event_is_an_active_support_notifications_event
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.some_event"
- wait
- assert_kind_of ActiveSupport::Notifications::Event, @subscriber.event
- end
-
- def test_does_not_send_the_event_if_it_doesnt_match_the_class
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.unknown_event"
- wait
- # If we get here, it means that NoMethodError was raised.
- end
-
- def test_does_not_send_the_event_if_logger_is_nil
- Rails.logger = nil
- @subscriber.expects(:some_event).never
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.some_event"
- wait
- end
-
- def test_flushes_loggers
- Rails::Subscriber.add :my_subscriber, @subscriber
- Rails::Subscriber.flush_all!
- assert_equal 1, @logger.flush_count
- end
-
- def test_flushes_the_same_logger_just_once
- Rails::Subscriber.add :my_subscriber, @subscriber
- Rails::Subscriber.add :another, @subscriber
- Rails::Subscriber.flush_all!
- wait
- assert_equal 1, @logger.flush_count
- end
-
- def test_logging_does_not_die_on_failures
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.puke"
- instrument "my_subscriber.some_event"
- wait
-
- assert_equal 1, @logger.logged(:info).size
- assert_equal 'my_subscriber.some_event', @logger.logged(:info).last
-
- assert_equal 1, @logger.logged(:error).size
- assert_equal 'Could not log "my_subscriber.puke" event. RuntimeError: puke', @logger.logged(:error).last
- end
-end \ No newline at end of file