Sha256: 69b59ba1284680154f682601e39ba25b471aaa8db1a9238bcee3993258d3c002

Contents?: true

Size: 1.99 KB

Versions: 7

Compression:

Stored size: 1.99 KB

Contents

# encoding: utf-8
require 'spec_helper'

describe Ably::Realtime::Presence, 'history', :event_machine do
  vary_by_protocol do
    let(:default_options)     { { api_key: api_key, environment: environment, protocol: protocol } }

    let(:channel_name)        { "persisted:#{random_str(2)}" }

    let(:client_one)          { Ably::Realtime::Client.new(default_options.merge(client_id: random_str)) }
    let(:channel_client_one)  { client_one.channel(channel_name) }
    let(:presence_client_one) { channel_client_one.presence }

    let(:client_two)          { Ably::Realtime::Client.new(default_options.merge(client_id: random_str)) }
    let(:channel_client_two)  { client_two.channel(channel_name) }
    let(:presence_client_two) { channel_client_two.presence }

    let(:data)                { random_str }
    let(:leave_data)          { random_str }

    it 'provides up to the moment presence history' do
      presence_client_one.enter(data: data) do
        presence_client_one.leave(data: leave_data) do
          presence_client_one.history do |history|
            expect(history.count).to eql(2)

            expect(history[1].action).to eq(:enter)
            expect(history[1].client_id).to eq(client_one.client_id)
            expect(history[1].data).to eql(data)

            expect(history[0].action).to eq(:leave)
            expect(history[0].client_id).to eq(client_one.client_id)
            expect(history[0].data).to eql(leave_data)

            stop_reactor
          end
        end
      end
    end

    it 'ensures REST presence history message IDs match ProtocolMessage wrapped message and connection IDs via Realtime' do
      presence_client_one.subscribe(:enter) do |message|
        presence_client_one.history do |history|
          expect(history.count).to eql(1)

          expect(history[0].id).to eql(message.id)
          expect(history[0].connection_id).to eql(message.connection_id)
          stop_reactor
        end
      end

      presence_client_one.enter(data: data)
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ably-rest-0.7.5 lib/submodules/ably-ruby/spec/acceptance/realtime/presence_history_spec.rb
ably-0.7.5 spec/acceptance/realtime/presence_history_spec.rb
ably-0.7.4 spec/acceptance/realtime/presence_history_spec.rb
ably-rest-0.7.3 lib/submodules/ably-ruby/spec/acceptance/realtime/presence_history_spec.rb
ably-0.7.2 spec/acceptance/realtime/presence_history_spec.rb
ably-0.7.1 spec/acceptance/realtime/presence_history_spec.rb
ably-0.7.0 spec/acceptance/realtime/presence_history_spec.rb