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
|
2009-12-28 20:45:17 -05:00
|
|
|
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
|
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
|
|
|
|
|
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
|
2013-11-11 12:56:02 -05:00
|
|
|
|
|
|
|
test 'rails load_config_initializer event is instrumented' do
|
|
|
|
app_file 'config/initializers/foo.rb', ''
|
|
|
|
|
|
|
|
events = []
|
2013-11-16 16:50:52 -05:00
|
|
|
callback = ->(*_) { events << _ }
|
2013-11-11 12:56:02 -05:00
|
|
|
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
|