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
Justin George 731d4392e4 Change event namespace ordering to most-significant first [#4504 state:resolved]
More work still needs to be done on some of these names
(render_template.action_view and render_template!.action_view particularly)
but this allows (for example) /^sql/ to subscribe to all
the various ORMs without further modification

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-02 22:45:54 +02:00

48 lines
1 KiB
Ruby

require "isolation/abstract_unit"
module ApplicationTests
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 "rails log_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 ActiveRecord notifications
instrument "sql.active_record", :name => "SQL", :sql => "SHOW tables"
wait
assert_equal 1, logger.logged.size
assert_match /SHOW tables/, logger.logged.last
end
end
end