Sha256: 461884881a841f9d7ef8af3e9d0eda34f0845a48c266b78d6f3e44537a55c606

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'test_helper'

module Alondra

  class ChannelTest < ActiveSupport::TestCase

    def setup
      @connection = MockConnection.new
    end

    test "it has a name" do
      channel   = Channel.new('test name channel')
      assert_equal 'test name channel', channel.name
    end

    test "can fetch channel by name" do
      channel = Channel['dummy channel']
      assert_equal 'dummy channel', channel.name
    end

    test "allow clients to subscribe" do
      channel   = Channel.new('test subscriptions channel')
      assert_equal 0, channel.connections.size

      channel.subscribe @connection

      assert_equal 1, channel.connections.size
      assert channel.connections.keys.include? @connection
    end

    test "deliver events to all subscribed connections" do
      channel   = Channel.new('test deliver events channel')
      channel.subscribe @connection

      assert @connection.channels.include?(channel)

      event = Event.new :event => :created, :resource => Chat.new, :channel => 'test deliver events channel'

      channel.receive event

      assert EM.reactor_running?

      sleep(0.5) # Leave event machine to catch up

      last_message = @connection.messages.last
      assert_equal event.to_json, last_message
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alondra-0.0.3 test/models/channel_test.rb