class Notifications::SyncPubSubTest

Public Instance Methods

test_events_are_published_to_a_listener() click to toggle source
# File activesupport/test/notifications_test.rb, line 116
def test_events_are_published_to_a_listener
  @notifier.publish :foo
  @notifier.wait
  assert_equal [[:foo]], @events
end
test_log_subscriber_with_pattern() click to toggle source
# File activesupport/test/notifications_test.rb, line 156
def test_log_subscriber_with_pattern
  events = []
  @notifier.subscribe(/\d/) { |*args| events << args }

  @notifier.publish "1"
  @notifier.publish "a.1"
  @notifier.publish "1.a"
  @notifier.wait

  assert_equal [["1"], ["a.1"], ["1.a"]], events
end
test_log_subscriber_with_string() click to toggle source
# File activesupport/test/notifications_test.rb, line 144
def test_log_subscriber_with_string
  events = []
  @notifier.subscribe("1") { |*args| events << args }

  @notifier.publish "1"
  @notifier.publish "1.a"
  @notifier.publish "a.1"
  @notifier.wait

  assert_equal [["1"]], events
end
test_multiple_log_subscribers() click to toggle source
# File activesupport/test/notifications_test.rb, line 168
def test_multiple_log_subscribers
  @another = []
  @notifier.subscribe { |*args| @another << args }
  @notifier.publish :foo
  @notifier.wait

  assert_equal [[:foo]], @events
  assert_equal [[:foo]], @another
end
test_publish_with_subscriber() click to toggle source
# File activesupport/test/notifications_test.rb, line 178
def test_publish_with_subscriber
  subscriber = TestSubscriber.new
  @notifier.subscribe nil, subscriber
  @notifier.publish :foo

  assert_equal [[:foo]], subscriber.publishes
end
test_publishing_after_a_new_subscribe_works() click to toggle source
# File activesupport/test/notifications_test.rb, line 129
def test_publishing_after_a_new_subscribe_works
  @notifier.publish :foo
  @notifier.publish :foo

  @notifier.subscribe("not_existent") do |*args|
    @events << ActiveSupport::Notifications::Event.new(*args)
  end

  @notifier.publish :foo
  @notifier.publish :foo
  @notifier.wait

  assert_equal [[:foo]] * 4, @events
end
test_publishing_multiple_times_works() click to toggle source
# File activesupport/test/notifications_test.rb, line 122
def test_publishing_multiple_times_works
  @notifier.publish :foo
  @notifier.publish :foo
  @notifier.wait
  assert_equal [[:foo], [:foo]], @events
end

Private Instance Methods

event(*args) click to toggle source
# File activesupport/test/notifications_test.rb, line 187
def event(*args)
  args
end