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

57 lines
1.5 KiB
Ruby
Raw Normal View History

2009-10-09 08:17:08 -04:00
require "isolation/abstract_unit"
module ApplicationTests
2012-01-05 20:30:17 -05:00
class NotificationsTest < ActiveSupport::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 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
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"
require "active_support/log_subscriber/test_helper"
2010-01-12 11:48:09 -05:00
logger = ActiveSupport::LogSubscriber::TestHelper::MockLogger.new
ActiveRecord::Base.logger = logger
2010-01-12 11:48:09 -05:00
# Mimic Active Record notifications
2012-10-14 06:03:39 -04:00
instrument "sql.active_record", name: "SQL", sql: "SHOW tables"
2010-01-12 11:48:09 -05:00
wait
assert_equal 1, logger.logged(:debug).size
assert_match(/SHOW tables/, logger.logged(:debug).last)
2010-01-12 11:48:09 -05:00
end
test 'rails load_config_initializer event is instrumented' do
app_file 'config/initializers/foo.rb', ''
events = []
callback = -> (*_) { events << _ }
ActiveSupport::Notifications.subscribed(callback, 'load_config_initializer.railties') do
app
end
assert_equal %w[load_config_initializer.railties], events.map(&:first)
assert_includes events.first.last[:initializer], 'config/initializers/foo.rb'
end
2009-10-09 08:17:08 -04:00
end
end