ably 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -1
  3. data/ably.gemspec +4 -3
  4. data/lib/ably/auth.rb +4 -4
  5. data/lib/ably/logger.rb +1 -1
  6. data/lib/ably/models/idiomatic_ruby_wrapper.rb +8 -8
  7. data/lib/ably/models/message.rb +6 -4
  8. data/lib/ably/models/presence_message.rb +6 -4
  9. data/lib/ably/modules/async_wrapper.rb +2 -2
  10. data/lib/ably/modules/conversions.rb +1 -1
  11. data/lib/ably/modules/encodeable.rb +1 -1
  12. data/lib/ably/modules/event_emitter.rb +2 -2
  13. data/lib/ably/modules/safe_deferrable.rb +1 -1
  14. data/lib/ably/modules/safe_yield.rb +1 -1
  15. data/lib/ably/modules/state_emitter.rb +5 -5
  16. data/lib/ably/realtime/auth.rb +1 -1
  17. data/lib/ably/realtime/channel.rb +3 -3
  18. data/lib/ably/realtime/channel/channel_manager.rb +2 -2
  19. data/lib/ably/realtime/client/incoming_message_dispatcher.rb +3 -2
  20. data/lib/ably/realtime/connection.rb +11 -6
  21. data/lib/ably/realtime/connection/websocket_transport.rb +1 -1
  22. data/lib/ably/realtime/presence.rb +3 -3
  23. data/lib/ably/realtime/presence/members_map.rb +6 -6
  24. data/lib/ably/rest/channel.rb +2 -2
  25. data/lib/ably/rest/client.rb +20 -12
  26. data/lib/ably/version.rb +1 -1
  27. data/spec/acceptance/realtime/auth_spec.rb +13 -37
  28. data/spec/acceptance/realtime/channel_history_spec.rb +7 -1
  29. data/spec/acceptance/realtime/channel_spec.rb +3 -3
  30. data/spec/acceptance/realtime/client_spec.rb +2 -2
  31. data/spec/acceptance/realtime/connection_failures_spec.rb +221 -7
  32. data/spec/acceptance/realtime/connection_spec.rb +13 -21
  33. data/spec/acceptance/realtime/message_spec.rb +2 -2
  34. data/spec/acceptance/realtime/presence_history_spec.rb +12 -3
  35. data/spec/acceptance/realtime/presence_spec.rb +10 -10
  36. data/spec/acceptance/rest/auth_spec.rb +21 -48
  37. data/spec/acceptance/rest/client_spec.rb +193 -68
  38. data/spec/shared/client_initializer_behaviour.rb +1 -9
  39. data/spec/spec_helper.rb +2 -0
  40. data/spec/support/event_emitter_helper.rb +31 -0
  41. data/spec/support/event_machine_helper.rb +1 -1
  42. data/spec/support/test_logger_helper.rb +42 -0
  43. data/spec/unit/logger_spec.rb +1 -9
  44. data/spec/unit/modules/async_wrapper_spec.rb +2 -2
  45. data/spec/unit/modules/event_emitter_spec.rb +3 -3
  46. data/spec/unit/modules/state_emitter_spec.rb +10 -10
  47. data/spec/unit/realtime/channel_spec.rb +1 -1
  48. data/spec/unit/realtime/connection_spec.rb +1 -1
  49. data/spec/unit/realtime/presence_spec.rb +1 -1
  50. data/spec/unit/rest/channel_spec.rb +22 -0
  51. data/spec/unit/util/pub_sub_spec.rb +3 -3
  52. 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 = Proc.new do
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
@@ -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) do
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
- proc do
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
- proc do
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: Proc.new { |event| String(event) } }
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) { Proc.new { |msg| obj.received_message msg } }
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) { Proc.new { |msg| obj.received_message msg } }
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
- proc do
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
- proc do
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
- proc do
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
- proc do |*args|
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 = proc { |arguments| expect(arguments).to eql(arguments) }
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
- proc { raise 'Success exception' }
257
+ lambda { raise 'Success exception' }
258
258
  end
259
259
 
260
260
  let(:failure_block) do
261
- proc { raise 'Failure exception' }
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
- proc { raise 'Success exception' }
294
+ lambda { raise 'Success exception' }
295
295
  end
296
296
 
297
297
  let(:failure_block) do
298
- proc { raise 'Failure exception' }
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
- proc do |*args|
321
+ lambda do |*args|
322
322
  block_calls << args
323
323
  end
324
324
  end
@@ -203,7 +203,7 @@ describe Ably::Realtime::Channel do
203
203
 
204
204
  context '#unsubscribe' do
205
205
  let(:callback) do
206
- Proc.new { |message| message_history[:received] += 1 }
206
+ lambda { |message| message_history[:received] += 1 }
207
207
  end
208
208
 
209
209
  before do
@@ -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 = proc { raise 'This should not be called' }
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
- Proc.new { |message| message_history[:received] += 1 }
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: Proc.new { |event| String(event) } }
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: Proc.new { raise KeyError }) }
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) { Proc.new { |msg| obj.received_message msg } }
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.5
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-04-23 00:00:00.000000000 Z
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: '1.0'
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: '1.0'
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.9'
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.9'
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.6'
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.6'
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