lib/submodules/ably-ruby/spec/acceptance/realtime/channel_spec.rb in ably-rest-0.7.3 vs lib/submodules/ably-ruby/spec/acceptance/realtime/channel_spec.rb in ably-rest-0.7.5
- old
+ new
@@ -82,16 +82,16 @@
expect(channel.state).to eq(:attached)
stop_reactor
end
end
- it 'returns a Deferrable' do
- expect(channel.attach).to be_a(EventMachine::Deferrable)
+ it 'returns a SafeDeferrable that catches exceptions in callbacks and logs them' do
+ expect(channel.attach).to be_a(Ably::Util::SafeDeferrable)
stop_reactor
end
- it 'calls the Deferrable callback on success' do
+ it 'calls the SafeDeferrable callback on success' do
channel.attach.callback do |channel|
expect(channel).to be_a(Ably::Realtime::Channel)
expect(channel.state).to eq(:attached)
stop_reactor
end
@@ -193,10 +193,30 @@
restricted_channel.on(:failed) do
expect(restricted_channel.error_reason.status).to eq(401)
stop_reactor
end
end
+
+ context 'and subsequent authorisation with suitable permissions' do
+ it 'attaches to the channel successfully and resets the channel error_reason' do
+ restricted_channel.attach
+ restricted_channel.once(:failed) do
+ restricted_client.close do
+ # A direct call to #authorise is synchronous
+ restricted_client.auth.authorise(api_key: api_key)
+
+ restricted_client.connect do
+ restricted_channel.once(:attached) do
+ expect(restricted_channel.error_reason).to be_nil
+ stop_reactor
+ end
+ restricted_channel.attach
+ end
+ end
+ end
+ end
+ end
end
end
describe '#detach' do
it 'detaches from a channel' do
@@ -228,12 +248,14 @@
channel.attach do
channel.detach
end
end
- it 'returns a Deferrable' do
- expect(channel.attach).to be_a(EventMachine::Deferrable)
- stop_reactor
+ it 'returns a SafeDeferrable that catches exceptions in callbacks and logs them' do
+ channel.attach do
+ expect(channel.detach).to be_a(Ably::Util::SafeDeferrable)
+ stop_reactor
+ end
end
it 'calls the Deferrable callback on success' do
channel.attach do
channel.detach.callback do |channel|