diff options
author | Mikel Lindsaar <raasdnil@gmail.com> | 2010-01-17 12:46:51 +1100 |
---|---|---|
committer | Mikel Lindsaar <raasdnil@gmail.com> | 2010-01-17 12:46:51 +1100 |
commit | 6f663addaa7ed40f1133687d7a2be0958bf0c059 (patch) | |
tree | 7beb7f092c1979d1fd5ea6e7aaaf4f59c2f4abf4 /railties/test/application/notifications_test.rb | |
parent | 8834b2612b7ddda70ee6a685eb0063d3daa8e63d (diff) | |
parent | 3e94032227d450d479f511070c51f37f53d0ecc4 (diff) | |
download | rails-6f663addaa7ed40f1133687d7a2be0958bf0c059.tar.gz rails-6f663addaa7ed40f1133687d7a2be0958bf0c059.tar.bz2 rails-6f663addaa7ed40f1133687d7a2be0958bf0c059.zip |
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'railties/test/application/notifications_test.rb')
-rw-r--r-- | railties/test/application/notifications_test.rb | 46 |
1 files changed, 41 insertions, 5 deletions
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 |