2017-07-16 13:10:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:15:15 -04:00
|
|
|
require "test_helper"
|
|
|
|
require "stubs/test_connection"
|
|
|
|
require "stubs/room"
|
2015-07-21 21:03:47 -04:00
|
|
|
|
2018-06-08 16:19:39 -04:00
|
|
|
class ActionCable::Channel::BroadcastingTest < ActionCable::TestCase
|
2015-07-21 21:03:47 -04:00
|
|
|
class ChatChannel < ActionCable::Channel::Base
|
|
|
|
end
|
|
|
|
|
|
|
|
setup do
|
|
|
|
@connection = TestConnection.new
|
|
|
|
end
|
|
|
|
|
|
|
|
test "broadcasts_to" do
|
2018-05-27 14:50:04 -04:00
|
|
|
assert_called_with(
|
|
|
|
ActionCable.server,
|
|
|
|
:broadcast,
|
|
|
|
[
|
|
|
|
"action_cable:channel:broadcasting_test:chat:Room#1-Campfire",
|
|
|
|
"Hello World"
|
|
|
|
]
|
|
|
|
) do
|
|
|
|
ChatChannel.broadcast_to(Room.new(1), "Hello World")
|
|
|
|
end
|
2015-07-21 21:03:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "broadcasting_for with an object" do
|
2019-01-22 14:05:32 -05:00
|
|
|
assert_equal(
|
|
|
|
"action_cable:channel:broadcasting_test:chat:Room#1-Campfire",
|
|
|
|
ChatChannel.broadcasting_for(Room.new(1))
|
|
|
|
)
|
2015-07-21 21:03:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "broadcasting_for with an array" do
|
2019-01-22 14:05:32 -05:00
|
|
|
assert_equal(
|
|
|
|
"action_cable:channel:broadcasting_test:chat:Room#1-Campfire:Room#2-Campfire",
|
|
|
|
ChatChannel.broadcasting_for([ Room.new(1), Room.new(2) ])
|
|
|
|
)
|
2015-07-21 21:03:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "broadcasting_for with a string" do
|
2019-01-22 14:05:32 -05:00
|
|
|
assert_equal(
|
|
|
|
"action_cable:channel:broadcasting_test:chat:hello",
|
|
|
|
ChatChannel.broadcasting_for("hello")
|
|
|
|
)
|
2015-07-21 21:03:47 -04:00
|
|
|
end
|
|
|
|
end
|