2009-10-09 08:17:08 -04:00
|
|
|
require "isolation/abstract_unit"
|
|
|
|
|
|
|
|
module ApplicationTests
|
2010-01-12 11:48:09 -05:00
|
|
|
class MockLogger
|
|
|
|
def method_missing(*args)
|
|
|
|
@logged ||= []
|
|
|
|
@logged << args.last
|
|
|
|
end
|
|
|
|
|
|
|
|
def logged
|
|
|
|
@logged.compact.map { |l| l.to_s.strip }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
ActiveRecord::Base.logger = logger = MockLogger.new
|
|
|
|
|
2010-01-17 05:29:41 -05:00
|
|
|
# Mimic ActiveRecord notifications
|
2010-01-12 11:48:09 -05:00
|
|
|
instrument "active_record.sql", :name => "SQL", :sql => "SHOW tables"
|
|
|
|
wait
|
|
|
|
|
|
|
|
assert_equal 1, logger.logged.size
|
|
|
|
assert_match /SHOW tables/, logger.logged.last
|
|
|
|
end
|
2009-10-09 08:17:08 -04:00
|
|
|
end
|
|
|
|
end
|