spec/unit/realtime/presence_spec.rb in ably-0.6.2 vs spec/unit/realtime/presence_spec.rb in ably-0.7.0

- old
+ new

@@ -1,7 +1,8 @@ +# encoding: utf-8 require 'spec_helper' -require 'support/protocol_msgbus_helper' +require 'shared/protocol_msgbus_behaviour' describe Ably::Realtime::Presence do let(:channel) { double('Ably::Realtime::Channel').as_null_object } subject do @@ -20,15 +21,15 @@ expect { subject.trigger(:invalid) }.to raise_error KeyError expect { subject.off(:invalid) }.to raise_error KeyError end end - context 'msgbus' do + context 'msgbus', :api_private do let(:message) do Ably::Models::PresenceMessage.new({ 'action' => 0, - 'member_id' => SecureRandom.hex, + 'connection_id' => random_str, }, instance_double('Ably::Models::ProtocolMessage')) end let(:msgbus) { subject.__incoming_msgbus__ } specify 'supports messages' do @@ -46,14 +47,18 @@ context 'subscriptions' do let(:message_history) { Hash.new { |hash, key| hash[key] = 0 } } let(:presence_action) { Ably::Models::PresenceMessage::ACTION.Enter } let(:message) do - instance_double('Ably::Models::PresenceMessage', action: presence_action, member_id: SecureRandom.hex, decode: true) + instance_double('Ably::Models::PresenceMessage', action: presence_action, connection_id: random_str, decode: true, member_key: random_str) end context '#subscribe' do + before do + subject.sync_completed + end + specify 'to all presence state actions' do subject.subscribe { |message| message_history[:received] += 1} subject.__incoming_msgbus__.publish(:presence, message) expect(message_history[:received]).to eql(1) end @@ -65,9 +70,13 @@ expect(message_history[:received]).to eql(1) end end context '#unsubscribe' do + before do + subject.sync_completed + end + let(:callback) do Proc.new { |message| message_history[:received] += 1 } end before do subject.subscribe(presence_action, &callback)