rails/test/channel/stream_test.rb

33 lines
986 B
Ruby
Raw Normal View History

2015-07-12 15:07:31 +00:00
require 'test_helper'
require 'stubs/test_connection'
2015-07-13 15:43:52 +00:00
require 'stubs/room'
2015-07-12 15:07:31 +00:00
class ActionCable::Channel::StreamTest < ActiveSupport::TestCase
class ChatChannel < ActionCable::Channel::Base
def subscribed
if params[:id]
@room = Room.new params[:id]
stream_from "test_room_#{@room.id}"
end
2015-07-12 15:07:31 +00:00
end
end
setup do
@connection = TestConnection.new
end
test "streaming start and stop" do
@connection.expects(:pubsub).returns mock().tap { |m| m.expects(:subscribe).with("test_room_1") }
2015-07-12 15:07:31 +00: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
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 15:07:31 +00:00
end