aboutsummaryrefslogblamecommitdiffstats
path: root/test/channel/stream_test.rb
blob: 5914b39be0203d13b1ddc949dc77177452182d13 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11

                               
                    
 
                                                              

                                                



                                           







                                    


                                                                                                       
 


                                                                                          
     

                      







                                                                                                                                                   
     
   
require 'test_helper'
require 'stubs/test_connection'
require 'stubs/room'

class ActionCable::Channel::StreamTest < ActionCable::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
    run_in_eventmachine 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
  end

  test "stream_for" do
    run_in_eventmachine do
      EM.next_tick do
        @connection.expects(:pubsub).returns mock().tap { |m| m.expects(:subscribe).with("action_cable:channel:stream_test:chat:Room#1-Campfire") }
      end

      channel = ChatChannel.new @connection, ""
      channel.stream_for Room.new(1)
    end
  end
end