Sha256: 75064f4344f13b85efac4da9196d80a11c7f2a5a0e7d345cccee76dc990f6cd7

Contents?: true

Size: 874 Bytes

Versions: 2

Compression:

Stored size: 874 Bytes

Contents

require 'test_helper'

module Alondra

  class PushingTest < ActiveSupport::TestCase

    test "publish created events to the specified channel" do
      chat       = FactoryGirl.create :chat
      connection = MockConnection.new
      message = chat.messages.build(:text => 'test message')

      channel_name = Channel.default_name_for(chat)
      assert channel_name =~ /chats\/\d+/

      channel    = Channel[channel_name]
      channel.subscribe connection

      sleep(0.1)

      message.save!

      sleep(0.1)

      assert connection.messages.last, "should publish a message"

      last_event = ActiveSupport::JSON.decode(connection.messages.last)
      resource   = last_event['resource']

      assert_equal 'created', last_event['event']
      assert_equal 'Message', last_event['resource_type']
      assert_equal message.id, resource['id']
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alondra-0.1.1 test/models/pushing_test.rb
alondra-0.1.0 test/models/pushing_test.rb