Sha256: 7b8d38c1356029340f0dff74ac7d975fe46e6c45a14a8caf1c8c50b54cddf498

Contents?: true

Size: 870 Bytes

Versions: 2

Compression:

Stored size: 870 Bytes

Contents

require 'test_helper'

module Alondra

  class PushingTest < ActiveSupport::TestCase

    test "publish created events to the specified channel" do
      chat       = Factory.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.0.4 test/models/pushing_test.rb
alondra-0.0.3 test/models/pushing_test.rb