aboutsummaryrefslogtreecommitdiffstats
path: root/test/channel/stream_test.rb
blob: b0a6f49072867202715139521085a120b5d98a15 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'test_helper'
require 'stubs/test_connection'
require 'stubs/room'

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
    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") }
    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
end