2015-07-12 11:07:31 -04:00
|
|
|
require 'test_helper'
|
|
|
|
require 'stubs/test_connection'
|
2015-07-13 11:43:52 -04:00
|
|
|
require 'stubs/room'
|
2015-07-12 11:07:31 -04:00
|
|
|
|
|
|
|
class ActionCable::Channel::StreamTest < ActiveSupport::TestCase
|
|
|
|
class ChatChannel < ActionCable::Channel::Base
|
|
|
|
def subscribed
|
2015-07-21 21:03:47 -04:00
|
|
|
if params[:id]
|
|
|
|
@room = Room.new params[:id]
|
|
|
|
stream_from "test_room_#{@room.id}"
|
|
|
|
end
|
2015-07-12 11:07:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
setup do
|
|
|
|
@connection = TestConnection.new
|
|
|
|
end
|
|
|
|
|
|
|
|
test "streaming start and stop" do
|
2015-07-21 21:03:47 -04:00
|
|
|
@connection.expects(:pubsub).returns mock().tap { |m| m.expects(:subscribe).with("test_room_1") }
|
2015-07-12 11:07:31 -04:00
|
|
|
channel = ChatChannel.new @connection, "{id: 1}", { id: 1 }
|
|
|
|
|
|
|
|
@connection.expects(:pubsub).returns mock().tap { |m| m.expects(:unsubscribe_proc) }
|
|
|
|
channel.unsubscribe_from_channel
|
|
|
|
end
|
2015-07-21 21:03:47 -04:00
|
|
|
|
|
|
|
test "stream_for" do
|
|
|
|
@connection.expects(:pubsub).returns mock().tap { |m| m.expects(:subscribe).with("action_cable:channel:stream_test:chat:Room#1-Campfire") }
|
|
|
|
channel = ChatChannel.new @connection, ""
|
|
|
|
channel.stream_for Room.new(1)
|
|
|
|
end
|
2015-07-12 11:07:31 -04:00
|
|
|
end
|