mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
892e38c78e
Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
58 lines
1.8 KiB
Ruby
58 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "test_helper"
|
|
require "stubs/test_server"
|
|
|
|
class BroadcastingTest < ActionCable::TestCase
|
|
test "fetching a broadcaster converts the broadcasting queue to a string" do
|
|
broadcasting = :test_queue
|
|
server = TestServer.new
|
|
broadcaster = server.broadcaster_for(broadcasting)
|
|
|
|
assert_equal "test_queue", broadcaster.broadcasting
|
|
end
|
|
|
|
test "broadcast generates notification" do
|
|
server = TestServer.new
|
|
|
|
events = []
|
|
ActiveSupport::Notifications.subscribe "broadcast.action_cable" do |*args|
|
|
events << ActiveSupport::Notifications::Event.new(*args)
|
|
end
|
|
|
|
broadcasting = "test_queue"
|
|
message = { body: "test message" }
|
|
server.broadcast(broadcasting, message)
|
|
|
|
assert_equal 1, events.length
|
|
assert_equal "broadcast.action_cable", events[0].name
|
|
assert_equal broadcasting, events[0].payload[:broadcasting]
|
|
assert_equal message, events[0].payload[:message]
|
|
assert_equal ActiveSupport::JSON, events[0].payload[:coder]
|
|
ensure
|
|
ActiveSupport::Notifications.unsubscribe "broadcast.action_cable"
|
|
end
|
|
|
|
test "broadcaster from broadcaster_for generates notification" do
|
|
server = TestServer.new
|
|
|
|
events = []
|
|
ActiveSupport::Notifications.subscribe "broadcast.action_cable" do |*args|
|
|
events << ActiveSupport::Notifications::Event.new(*args)
|
|
end
|
|
|
|
broadcasting = "test_queue"
|
|
message = { body: "test message" }
|
|
|
|
broadcaster = server.broadcaster_for(broadcasting)
|
|
broadcaster.broadcast(message)
|
|
|
|
assert_equal 1, events.length
|
|
assert_equal "broadcast.action_cable", events[0].name
|
|
assert_equal broadcasting, events[0].payload[:broadcasting]
|
|
assert_equal message, events[0].payload[:message]
|
|
assert_equal ActiveSupport::JSON, events[0].payload[:coder]
|
|
ensure
|
|
ActiveSupport::Notifications.unsubscribe "broadcast.action_cable"
|
|
end
|
|
end
|