ably 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -1
- data/ably.gemspec +4 -3
- data/lib/ably/auth.rb +4 -4
- data/lib/ably/logger.rb +1 -1
- data/lib/ably/models/idiomatic_ruby_wrapper.rb +8 -8
- data/lib/ably/models/message.rb +6 -4
- data/lib/ably/models/presence_message.rb +6 -4
- data/lib/ably/modules/async_wrapper.rb +2 -2
- data/lib/ably/modules/conversions.rb +1 -1
- data/lib/ably/modules/encodeable.rb +1 -1
- data/lib/ably/modules/event_emitter.rb +2 -2
- data/lib/ably/modules/safe_deferrable.rb +1 -1
- data/lib/ably/modules/safe_yield.rb +1 -1
- data/lib/ably/modules/state_emitter.rb +5 -5
- data/lib/ably/realtime/auth.rb +1 -1
- data/lib/ably/realtime/channel.rb +3 -3
- data/lib/ably/realtime/channel/channel_manager.rb +2 -2
- data/lib/ably/realtime/client/incoming_message_dispatcher.rb +3 -2
- data/lib/ably/realtime/connection.rb +11 -6
- data/lib/ably/realtime/connection/websocket_transport.rb +1 -1
- data/lib/ably/realtime/presence.rb +3 -3
- data/lib/ably/realtime/presence/members_map.rb +6 -6
- data/lib/ably/rest/channel.rb +2 -2
- data/lib/ably/rest/client.rb +20 -12
- data/lib/ably/version.rb +1 -1
- data/spec/acceptance/realtime/auth_spec.rb +13 -37
- data/spec/acceptance/realtime/channel_history_spec.rb +7 -1
- data/spec/acceptance/realtime/channel_spec.rb +3 -3
- data/spec/acceptance/realtime/client_spec.rb +2 -2
- data/spec/acceptance/realtime/connection_failures_spec.rb +221 -7
- data/spec/acceptance/realtime/connection_spec.rb +13 -21
- data/spec/acceptance/realtime/message_spec.rb +2 -2
- data/spec/acceptance/realtime/presence_history_spec.rb +12 -3
- data/spec/acceptance/realtime/presence_spec.rb +10 -10
- data/spec/acceptance/rest/auth_spec.rb +21 -48
- data/spec/acceptance/rest/client_spec.rb +193 -68
- data/spec/shared/client_initializer_behaviour.rb +1 -9
- data/spec/spec_helper.rb +2 -0
- data/spec/support/event_emitter_helper.rb +31 -0
- data/spec/support/event_machine_helper.rb +1 -1
- data/spec/support/test_logger_helper.rb +42 -0
- data/spec/unit/logger_spec.rb +1 -9
- data/spec/unit/modules/async_wrapper_spec.rb +2 -2
- data/spec/unit/modules/event_emitter_spec.rb +3 -3
- data/spec/unit/modules/state_emitter_spec.rb +10 -10
- data/spec/unit/realtime/channel_spec.rb +1 -1
- data/spec/unit/realtime/connection_spec.rb +1 -1
- data/spec/unit/realtime/presence_spec.rb +1 -1
- data/spec/unit/rest/channel_spec.rb +22 -0
- data/spec/unit/util/pub_sub_spec.rb +3 -3
- metadata +26 -8
@@ -0,0 +1,31 @@
|
|
1
|
+
module Ably
|
2
|
+
module Modules
|
3
|
+
module EventEmitter
|
4
|
+
# Unplugs currently registered listener callbacks
|
5
|
+
# Ensures multiple calls to unplug is not destructive
|
6
|
+
def unplug_listeners
|
7
|
+
unplugged_callbacks[:callbacks] = unplugged_callbacks.fetch(:callbacks).merge(callbacks)
|
8
|
+
unplugged_callbacks[:callbacks_any] = unplugged_callbacks.fetch(:callbacks_any) + callbacks_any
|
9
|
+
callbacks.clear
|
10
|
+
callbacks_any.clear
|
11
|
+
end
|
12
|
+
|
13
|
+
# Plug in previously unplugged listener callbacks
|
14
|
+
# But merge them together in case other listners have been added in the mean time
|
15
|
+
def plugin_listeners
|
16
|
+
@callbacks = callbacks.merge(unplugged_callbacks.fetch(:callbacks))
|
17
|
+
@callbacks_any = callbacks_any + unplugged_callbacks.fetch(:callbacks_any)
|
18
|
+
unplugged_callbacks.fetch(:callbacks).clear
|
19
|
+
unplugged_callbacks.fetch(:callbacks_any).clear
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def unplugged_callbacks
|
24
|
+
@unplugged_callbacks ||= {
|
25
|
+
callbacks: Hash.new { |hash, key| hash[key] = [] },
|
26
|
+
callbacks_any: []
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -124,7 +124,7 @@ RSpec.configure do |config|
|
|
124
124
|
example_block = example.example.instance_variable_get('@example_block')
|
125
125
|
example_group_instance = example.example.instance_variable_get('@example_group_instance')
|
126
126
|
|
127
|
-
event_machine_block =
|
127
|
+
event_machine_block = lambda do |*args|
|
128
128
|
RSpec::EventMachine.run_reactor(timeout) do
|
129
129
|
example_group_instance.instance_exec(example, &example_block)
|
130
130
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Class with standard Ruby Logger interface
|
2
|
+
# but it keeps a record of the lof entries for later inspection
|
3
|
+
#
|
4
|
+
# Recommendation: Use :prevent_log_stubbing attibute on tests that use this logger
|
5
|
+
#
|
6
|
+
class TestLogger
|
7
|
+
def initialize
|
8
|
+
@messages = []
|
9
|
+
end
|
10
|
+
|
11
|
+
SEVERITIES = [:fatal, :error, :warn, :info, :debug]
|
12
|
+
SEVERITIES.each do |severity_sym|
|
13
|
+
define_method(severity_sym) do |*args, &block|
|
14
|
+
if block
|
15
|
+
@messages << [severity_sym, block.call]
|
16
|
+
else
|
17
|
+
@messages << [severity_sym, args.join(', ')]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def logs(options = {})
|
23
|
+
min_severity = options[:min_severity]
|
24
|
+
if min_severity
|
25
|
+
severity_level = SEVERITIES.index(min_severity)
|
26
|
+
raise "Unknown severity: #{min_severity}" if severity_level.nil?
|
27
|
+
|
28
|
+
@messages.select do |severity, message|
|
29
|
+
SEVERITIES.index(severity) <= severity_level
|
30
|
+
end
|
31
|
+
else
|
32
|
+
@messages
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def level
|
37
|
+
1
|
38
|
+
end
|
39
|
+
|
40
|
+
def level=(new_level)
|
41
|
+
end
|
42
|
+
end
|
data/spec/unit/logger_spec.rb
CHANGED
@@ -121,15 +121,7 @@ describe Ably::Logger do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
context 'with a valid interface' do
|
124
|
-
let(:custom_logger)
|
125
|
-
Class.new do
|
126
|
-
extend Forwardable
|
127
|
-
def initialize
|
128
|
-
@logger = Logger.new(STDOUT)
|
129
|
-
end
|
130
|
-
def_delegators :@logger, :fatal, :error, :warn, :info, :debug, :level, :level=
|
131
|
-
end
|
132
|
-
end
|
124
|
+
let(:custom_logger) { TestLogger }
|
133
125
|
let(:custom_logger_object) { custom_logger.new }
|
134
126
|
|
135
127
|
subject { Ably::Logger.new(rest_client, Logger::INFO, custom_logger_object) }
|
@@ -31,7 +31,7 @@ describe Ably::Modules::AsyncWrapper, :api_private do
|
|
31
31
|
context '#async_wrap blocking block' do
|
32
32
|
context 'returns result' do
|
33
33
|
let(:block) do
|
34
|
-
|
34
|
+
lambda do
|
35
35
|
sleep sleep_time
|
36
36
|
result
|
37
37
|
end
|
@@ -104,7 +104,7 @@ describe Ably::Modules::AsyncWrapper, :api_private do
|
|
104
104
|
|
105
105
|
context 'raises an Exception' do
|
106
106
|
let(:block) do
|
107
|
-
|
107
|
+
lambda do
|
108
108
|
sleep sleep_time
|
109
109
|
raise RuntimeError, 'Intentional'
|
110
110
|
end
|
@@ -38,7 +38,7 @@ describe Ably::Modules::EventEmitter do
|
|
38
38
|
|
39
39
|
context 'with coercion', :api_private do
|
40
40
|
let(:options) do
|
41
|
-
{ coerce_into:
|
41
|
+
{ coerce_into: lambda { |event| String(event) } }
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'calls the provided proc to coerce the event name' do
|
@@ -244,7 +244,7 @@ describe Ably::Modules::EventEmitter do
|
|
244
244
|
end
|
245
245
|
|
246
246
|
context '#off' do
|
247
|
-
let(:callback) {
|
247
|
+
let(:callback) { lambda { |msg| obj.received_message msg } }
|
248
248
|
|
249
249
|
context 'with event specified in on handler' do
|
250
250
|
before do
|
@@ -356,7 +356,7 @@ describe Ably::Modules::EventEmitter do
|
|
356
356
|
end
|
357
357
|
|
358
358
|
context '#unsafe_off' do
|
359
|
-
let(:callback) {
|
359
|
+
let(:callback) { lambda { |msg| obj.received_message msg } }
|
360
360
|
|
361
361
|
context 'with unsafe_on subscribers' do
|
362
362
|
before do
|
@@ -85,7 +85,7 @@ describe Ably::Modules::StateEmitter do
|
|
85
85
|
context 'without :else option block' do
|
86
86
|
let(:block_calls) { [] }
|
87
87
|
let(:block) do
|
88
|
-
|
88
|
+
lambda do
|
89
89
|
block_calls << Time.now
|
90
90
|
end
|
91
91
|
end
|
@@ -116,7 +116,7 @@ describe Ably::Modules::StateEmitter do
|
|
116
116
|
context 'with an array of targets' do
|
117
117
|
let(:block_calls) { [] }
|
118
118
|
let(:block) do
|
119
|
-
|
119
|
+
lambda do
|
120
120
|
block_calls << Time.now
|
121
121
|
end
|
122
122
|
end
|
@@ -158,14 +158,14 @@ describe Ably::Modules::StateEmitter do
|
|
158
158
|
context 'with :else option block', :api_private do
|
159
159
|
let(:success_calls) { [] }
|
160
160
|
let(:success_block) do
|
161
|
-
|
161
|
+
lambda do
|
162
162
|
success_calls << Time.now
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
166
|
let(:failure_calls) { [] }
|
167
167
|
let(:failure_block) do
|
168
|
-
|
168
|
+
lambda do |*args|
|
169
169
|
failure_calls << args
|
170
170
|
end
|
171
171
|
end
|
@@ -244,7 +244,7 @@ describe Ably::Modules::StateEmitter do
|
|
244
244
|
end
|
245
245
|
|
246
246
|
specify 'are passed to else blocks' do
|
247
|
-
else_block =
|
247
|
+
else_block = lambda { |arguments| expect(arguments).to eql(arguments) }
|
248
248
|
subject.once_or_if(:connected, else: else_block) do
|
249
249
|
raise 'Success should not be called'
|
250
250
|
end
|
@@ -254,11 +254,11 @@ describe Ably::Modules::StateEmitter do
|
|
254
254
|
|
255
255
|
context 'with blocks that raise exceptions' do
|
256
256
|
let(:success_block) do
|
257
|
-
|
257
|
+
lambda { raise 'Success exception' }
|
258
258
|
end
|
259
259
|
|
260
260
|
let(:failure_block) do
|
261
|
-
|
261
|
+
lambda { raise 'Failure exception' }
|
262
262
|
end
|
263
263
|
|
264
264
|
let(:target_state) { :connected }
|
@@ -291,11 +291,11 @@ describe Ably::Modules::StateEmitter do
|
|
291
291
|
let(:target_state) { :connected }
|
292
292
|
|
293
293
|
let(:success_block) do
|
294
|
-
|
294
|
+
lambda { raise 'Success exception' }
|
295
295
|
end
|
296
296
|
|
297
297
|
let(:failure_block) do
|
298
|
-
|
298
|
+
lambda { raise 'Failure exception' }
|
299
299
|
end
|
300
300
|
|
301
301
|
before do
|
@@ -318,7 +318,7 @@ describe Ably::Modules::StateEmitter do
|
|
318
318
|
context '#once_state_changed', :api_private do
|
319
319
|
let(:block_calls) { [] }
|
320
320
|
let(:block) do
|
321
|
-
|
321
|
+
lambda do |*args|
|
322
322
|
block_calls << args
|
323
323
|
end
|
324
324
|
end
|
@@ -56,7 +56,7 @@ describe Ably::Realtime::Connection do
|
|
56
56
|
describe '#off_resume' do
|
57
57
|
it 'registers a callback' do
|
58
58
|
subject.on_resume { callbacks << true }
|
59
|
-
additional_proc =
|
59
|
+
additional_proc = lambda { raise 'This should not be called' }
|
60
60
|
subject.off_resume(&additional_proc)
|
61
61
|
subject.trigger_resumed
|
62
62
|
expect(callbacks.count).to eql(1)
|
@@ -98,7 +98,7 @@ describe Ably::Realtime::Presence do
|
|
98
98
|
|
99
99
|
context '#unsubscribe' do
|
100
100
|
let(:callback) do
|
101
|
-
|
101
|
+
lambda { |message| message_history[:received] += 1 }
|
102
102
|
end
|
103
103
|
before do
|
104
104
|
subject.subscribe(enter_action, &callback)
|
@@ -22,6 +22,19 @@ describe Ably::Rest::Channel do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
context 'as frozen UTF_8 string' do
|
26
|
+
let(:channel_name) { 'unique'.freeze }
|
27
|
+
let(:encoding) { Encoding::UTF_8 }
|
28
|
+
|
29
|
+
it 'is permitted' do
|
30
|
+
expect(subject.name).to eql(channel_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'remains as UTF-8' do
|
34
|
+
expect(subject.name.encoding).to eql(encoding)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
25
38
|
context 'as SHIFT_JIS string' do
|
26
39
|
let(:encoding) { Encoding::SHIFT_JIS }
|
27
40
|
|
@@ -74,6 +87,15 @@ describe Ably::Rest::Channel do
|
|
74
87
|
end
|
75
88
|
end
|
76
89
|
|
90
|
+
context 'as frozen UTF_8 string' do
|
91
|
+
let(:encoded_value) { 'unique'.freeze }
|
92
|
+
let(:encoding) { Encoding::UTF_8 }
|
93
|
+
|
94
|
+
it 'is permitted' do
|
95
|
+
expect(subject.publish(encoded_value, 'data')).to eql(true)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
77
99
|
context 'as SHIFT_JIS string' do
|
78
100
|
let(:encoding) { Encoding::SHIFT_JIS }
|
79
101
|
|
@@ -26,7 +26,7 @@ describe Ably::Util::PubSub do
|
|
26
26
|
|
27
27
|
context 'with coercion', api_private: true do
|
28
28
|
let(:options) do
|
29
|
-
{ coerce_into:
|
29
|
+
{ coerce_into: lambda { |event| String(event) } }
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'calls the provided proc to coerce the event name' do
|
@@ -36,7 +36,7 @@ describe Ably::Util::PubSub do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
context 'and two different configurations but sharing the same class' do
|
39
|
-
let!(:exception_pubsub) { Ably::Util::PubSub.new(coerce_into:
|
39
|
+
let!(:exception_pubsub) { Ably::Util::PubSub.new(coerce_into: lambda { |event| raise KeyError }) }
|
40
40
|
|
41
41
|
it 'does not share state' do
|
42
42
|
expect(obj).to receive(:received_message).with(msg).once
|
@@ -58,7 +58,7 @@ describe Ably::Util::PubSub do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
context '#unsubscribe' do
|
61
|
-
let(:callback) {
|
61
|
+
let(:callback) { lambda { |msg| obj.received_message msg } }
|
62
62
|
|
63
63
|
before do
|
64
64
|
subject.subscribe(:message, &callback)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ably
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lewis Marshall
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-05-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 1.2.6
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 1.2.6
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: em-http-request
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,14 +59,28 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '0.
|
62
|
+
version: '0.12'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '0.
|
69
|
+
version: '0.12'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: excon
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0.55'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0.55'
|
70
84
|
- !ruby/object:Gem::Dependency
|
71
85
|
name: json
|
72
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,14 +101,14 @@ dependencies:
|
|
87
101
|
requirements:
|
88
102
|
- - "~>"
|
89
103
|
- !ruby/object:Gem::Version
|
90
|
-
version: '0.
|
104
|
+
version: '0.7'
|
91
105
|
type: :runtime
|
92
106
|
prerelease: false
|
93
107
|
version_requirements: !ruby/object:Gem::Requirement
|
94
108
|
requirements:
|
95
109
|
- - "~>"
|
96
110
|
- !ruby/object:Gem::Version
|
97
|
-
version: '0.
|
111
|
+
version: '0.7'
|
98
112
|
- !ruby/object:Gem::Dependency
|
99
113
|
name: msgpack
|
100
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -390,6 +404,7 @@ files:
|
|
390
404
|
- spec/spec_helper.rb
|
391
405
|
- spec/support/api_helper.rb
|
392
406
|
- spec/support/debug_failure_helper.rb
|
407
|
+
- spec/support/event_emitter_helper.rb
|
393
408
|
- spec/support/event_machine_helper.rb
|
394
409
|
- spec/support/markdown_spec_formatter.rb
|
395
410
|
- spec/support/private_api_formatter.rb
|
@@ -397,6 +412,7 @@ files:
|
|
397
412
|
- spec/support/random_helper.rb
|
398
413
|
- spec/support/rest_testapp_before_retry.rb
|
399
414
|
- spec/support/test_app.rb
|
415
|
+
- spec/support/test_logger_helper.rb
|
400
416
|
- spec/unit/auth_spec.rb
|
401
417
|
- spec/unit/logger_spec.rb
|
402
418
|
- spec/unit/models/auth_details_spec.rb
|
@@ -493,6 +509,7 @@ test_files:
|
|
493
509
|
- spec/spec_helper.rb
|
494
510
|
- spec/support/api_helper.rb
|
495
511
|
- spec/support/debug_failure_helper.rb
|
512
|
+
- spec/support/event_emitter_helper.rb
|
496
513
|
- spec/support/event_machine_helper.rb
|
497
514
|
- spec/support/markdown_spec_formatter.rb
|
498
515
|
- spec/support/private_api_formatter.rb
|
@@ -500,6 +517,7 @@ test_files:
|
|
500
517
|
- spec/support/random_helper.rb
|
501
518
|
- spec/support/rest_testapp_before_retry.rb
|
502
519
|
- spec/support/test_app.rb
|
520
|
+
- spec/support/test_logger_helper.rb
|
503
521
|
- spec/unit/auth_spec.rb
|
504
522
|
- spec/unit/logger_spec.rb
|
505
523
|
- spec/unit/models/auth_details_spec.rb
|