diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-12 17:48:09 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-13 01:19:23 +0100 |
commit | fe3ceabeed6bde67eb9c0e64b27e133a66e13d83 (patch) | |
tree | 523dcb635d1d8934e035e54c8ece3b49413688ed /railties/test/application | |
parent | 7f25ccf38d6cab2b96494ed1a6b7cdffeef8eae7 (diff) | |
download | rails-fe3ceabeed6bde67eb9c0e64b27e133a66e13d83.tar.gz rails-fe3ceabeed6bde67eb9c0e64b27e133a66e13d83.tar.bz2 rails-fe3ceabeed6bde67eb9c0e64b27e133a66e13d83.zip |
Set up subscriber on initialization.
Diffstat (limited to 'railties/test/application')
-rw-r--r-- | railties/test/application/generators_test.rb | 2 | ||||
-rw-r--r-- | railties/test/application/notifications_test.rb | 46 |
2 files changed, 42 insertions, 6 deletions
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 0c858d6394..e1e51c318c 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -52,8 +52,8 @@ module ApplicationTests config.generators.test_framework :rspec RUBY - require "#{app_path}/config/environment" # Initialize the application + require "#{app_path}/config/environment" require "rails/generators" Rails::Generators.configure! diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb index b57e829cca..1eb0777db8 100644 --- a/railties/test/application/notifications_test.rb +++ b/railties/test/application/notifications_test.rb @@ -12,28 +12,64 @@ module ApplicationTests end end + class MockLogger + def method_missing(*args) + @logged ||= [] + @logged << args.last + end + + def logged + @logged.compact.map { |l| l.to_s.strip } + end + end + class NotificationsTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation def setup build_app boot_rails + end + + def instrument(*args, &block) + ActiveSupport::Notifications.instrument(*args, &block) + end + + def wait + ActiveSupport::Notifications.notifier.wait + end + + test "new queue is set" do + # We don't want to load all frameworks, so remove them and clean up environments. + use_frameworks [] FileUtils.rm_rf("#{app_path}/config/environments") - require "active_support/notifications" - @events = [] add_to_config <<-RUBY config.notifications.notifier = ActiveSupport::Notifications::Notifier.new(ApplicationTests::MyQueue.new) RUBY - end - test "new queue is set" do - use_frameworks [] require "#{app_path}/config/environment" assert_raise RuntimeError do ActiveSupport::Notifications.publish('foo') end end + + test "rails subscribers are added" do + add_to_config <<-RUBY + config.colorize_logging = false + RUBY + + require "#{app_path}/config/environment" + + ActiveRecord::Base.logger = logger = MockLogger.new + + # Mimic an ActiveRecord notifications + instrument "active_record.sql", :name => "SQL", :sql => "SHOW tables" + wait + + assert_equal 1, logger.logged.size + assert_match /SHOW tables/, logger.logged.last + end end end |