class Notifications::SubscribedTest

Public Instance Methods

test_subscribed() click to toggle source
# File activesupport/test/notifications_test.rb, line 30
def test_subscribed
  name     = "foo"
  name2    = name * 2
  expected = [name, name]

  events   = []
  callback = lambda { |*_| events << _.first }
  ActiveSupport::Notifications.subscribed(callback, name) do
    ActiveSupport::Notifications.instrument(name)
    ActiveSupport::Notifications.instrument(name2)
    ActiveSupport::Notifications.instrument(name)
  end
  assert_equal expected, events

  ActiveSupport::Notifications.instrument(name)
  assert_equal expected, events
end
test_subsribing_to_instrumentation_while_inside_it() click to toggle source
# File activesupport/test/notifications_test.rb, line 48
def test_subsribing_to_instrumentation_while_inside_it
  # the repro requires that there are no evented subscribers for the "foo" event,
  # so we have to duplicate some of the setup code
  old_notifier = ActiveSupport::Notifications.notifier
  ActiveSupport::Notifications.notifier = ActiveSupport::Notifications::Fanout.new

  ActiveSupport::Notifications.subscribe("foo", TestSubscriber.new)

  ActiveSupport::Notifications.instrument("foo") do
    ActiveSupport::Notifications.subscribe("foo") {}
  end
ensure
  ActiveSupport::Notifications.notifier = old_notifier
end