1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/test/application/initializers/notifications_test.rb

49 lines
1 KiB
Ruby
Raw Normal View History

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
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
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
# 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