2009-10-09 08:17:08 -04:00
|
|
|
require "isolation/abstract_unit"
|
|
|
|
|
|
|
|
module ApplicationTests
|
2009-12-28 20:45:17 -05:00
|
|
|
class NotificationsTest < Test::Unit::TestCase
|
|
|
|
include ActiveSupport::Testing::Isolation
|
2009-10-09 08:17:08 -04:00
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
boot_rails
|
2010-01-12 11:48:09 -05:00
|
|
|
end
|
|
|
|
|
2011-06-06 08:54:05 -04:00
|
|
|
def teardown
|
|
|
|
teardown_app
|
|
|
|
end
|
|
|
|
|
2010-01-12 11:48:09 -05:00
|
|
|
def instrument(*args, &block)
|
|
|
|
ActiveSupport::Notifications.instrument(*args, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def wait
|
|
|
|
ActiveSupport::Notifications.notifier.wait
|
|
|
|
end
|
|
|
|
|
2010-02-15 09:44:30 -05:00
|
|
|
test "rails log_subscribers are added" do
|
2010-01-12 11:48:09 -05:00
|
|
|
add_to_config <<-RUBY
|
|
|
|
config.colorize_logging = false
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
require "#{app_path}/config/environment"
|
2010-07-20 15:20:19 -04:00
|
|
|
require "active_support/log_subscriber/test_helper"
|
2010-01-12 11:48:09 -05:00
|
|
|
|
2010-07-20 15:20:19 -04:00
|
|
|
logger = ActiveSupport::LogSubscriber::TestHelper::MockLogger.new
|
|
|
|
ActiveRecord::Base.logger = logger
|
2010-01-12 11:48:09 -05:00
|
|
|
|
2010-06-14 17:21:53 -04:00
|
|
|
# Mimic Active Record notifications
|
2010-04-28 00:16:06 -04:00
|
|
|
instrument "sql.active_record", :name => "SQL", :sql => "SHOW tables"
|
2010-01-12 11:48:09 -05:00
|
|
|
wait
|
|
|
|
|
2010-07-20 15:20:19 -04:00
|
|
|
assert_equal 1, logger.logged(:debug).size
|
2011-05-23 20:45:00 -04:00
|
|
|
assert_match(/SHOW tables/, logger.logged(:debug).last)
|
2010-01-12 11:48:09 -05:00
|
|
|
end
|
2009-10-09 08:17:08 -04:00
|
|
|
end
|
|
|
|
end
|