ably-rest 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -0
  3. data/README.md +3 -1
  4. data/ably-rest.gemspec +4 -0
  5. data/lib/ably-rest.rb +2 -0
  6. data/lib/submodules/ably-ruby/.github/workflows/check.yml +15 -1
  7. data/lib/submodules/ably-ruby/CHANGELOG.md +26 -0
  8. data/lib/submodules/ably-ruby/README.md +14 -2
  9. data/lib/submodules/ably-ruby/ably.gemspec +11 -6
  10. data/lib/submodules/ably-ruby/lib/ably.rb +1 -0
  11. data/lib/submodules/ably-ruby/lib/ably/agent.rb +3 -0
  12. data/lib/submodules/ably-ruby/lib/ably/exceptions.rb +6 -0
  13. data/lib/submodules/ably-ruby/lib/ably/models/connection_details.rb +2 -0
  14. data/lib/submodules/ably-ruby/lib/ably/models/message.rb +14 -0
  15. data/lib/submodules/ably-ruby/lib/ably/models/presence_message.rb +14 -0
  16. data/lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb +8 -0
  17. data/lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb +2 -2
  18. data/lib/submodules/ably-ruby/lib/ably/realtime/channel/publisher.rb +5 -0
  19. data/lib/submodules/ably-ruby/lib/ably/realtime/client/incoming_message_dispatcher.rb +14 -6
  20. data/lib/submodules/ably-ruby/lib/ably/realtime/connection.rb +5 -2
  21. data/lib/submodules/ably-ruby/lib/ably/rest/channel.rb +8 -1
  22. data/lib/submodules/ably-ruby/lib/ably/rest/client.rb +11 -11
  23. data/lib/submodules/ably-ruby/lib/ably/version.rb +1 -13
  24. data/lib/submodules/ably-ruby/spec/acceptance/realtime/auth_spec.rb +1 -1
  25. data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_history_spec.rb +25 -0
  26. data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_spec.rb +14 -0
  27. data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_failures_spec.rb +3 -1
  28. data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_spec.rb +6 -27
  29. data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_history_spec.rb +3 -1
  30. data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_spec.rb +13 -158
  31. data/lib/submodules/ably-ruby/spec/acceptance/rest/channel_spec.rb +13 -0
  32. data/lib/submodules/ably-ruby/spec/acceptance/rest/client_spec.rb +23 -19
  33. data/lib/submodules/ably-ruby/spec/shared/model_behaviour.rb +1 -1
  34. data/lib/submodules/ably-ruby/spec/spec_helper.rb +11 -2
  35. data/lib/submodules/ably-ruby/spec/unit/models/message_spec.rb +59 -0
  36. data/lib/submodules/ably-ruby/spec/unit/models/presence_message_spec.rb +49 -0
  37. data/lib/submodules/ably-ruby/spec/unit/models/protocol_message_spec.rb +48 -0
  38. data/lib/submodules/ably-ruby/spec/unit/realtime/channel_spec.rb +1 -1
  39. data/lib/submodules/ably-ruby/spec/unit/realtime/incoming_message_dispatcher_spec.rb +38 -0
  40. data/lib/submodules/ably-ruby/spec/unit/rest/channel_spec.rb +10 -0
  41. data/lib/submodules/ably-ruby/spec/unit/rest/client_spec.rb +20 -0
  42. data/spec/unit/client_spec.rb +30 -0
  43. metadata +5 -2
@@ -19,7 +19,7 @@ shared_examples 'a model' do |shared_options = {}|
19
19
  end
20
20
 
21
21
  context '#attributes', :api_private do
22
- let(:model_options) { { action: 5 } }
22
+ let(:model_options) { { action: 5, max_message_size: 65536, max_frame_size: 524288 } }
23
23
 
24
24
  it 'provides access to #attributes' do
25
25
  expect(model.attributes).to eq(model_options)
@@ -5,8 +5,17 @@ def console(message)
5
5
  end
6
6
 
7
7
  unless RUBY_VERSION.match(/^1\./)
8
- require 'coveralls'
9
- Coveralls.wear!
8
+ require 'simplecov'
9
+
10
+ SimpleCov.start do
11
+ require 'simplecov-lcov'
12
+ SimpleCov::Formatter::LcovFormatter.config do |c|
13
+ c.report_with_single_file = true
14
+ c.single_report_path = 'coverage/lcov.info'
15
+ end
16
+ formatter SimpleCov::Formatter::LcovFormatter
17
+ add_filter %w[vendor spec]
18
+ end
10
19
  end
11
20
 
12
21
  require 'webmock/rspec'
@@ -211,6 +211,65 @@ describe Ably::Models::Message do
211
211
  end
212
212
  end
213
213
 
214
+ describe '#size' do
215
+ let(:model) { subject.new({ name: name, data: data, client_id: client_id, extras: extras }, protocol_message: protocol_message) }
216
+
217
+ context 'String (#TO3l8a)' do
218
+ let(:data) { 'example string data' }
219
+ let(:client_id) { '1' }
220
+ let(:name) { 'My Name' }
221
+ let(:extras) { 'extras' }
222
+
223
+ it 'should return 33 bytes' do
224
+ expect(model.size).to eq(33)
225
+ end
226
+ end
227
+
228
+ context 'Object (#TO3l8b)' do
229
+ let(:data) { Object.new }
230
+ let(:client_id) { String('10') }
231
+ let(:name) { 'John' }
232
+ let(:extras) { Hash.new }
233
+
234
+ it 'should return 38 bytes' do
235
+ expect(model.size).to eq(38)
236
+ end
237
+ end
238
+
239
+ context 'Array (#TO3l8b)' do
240
+ let(:data) { [1, 'two', :three] }
241
+ let(:client_id) { '2' }
242
+ let(:name) { 'Kate' }
243
+ let(:extras) { [] }
244
+
245
+ it 'should return 24 bytes' do
246
+ expect(model.size).to eq(24)
247
+ end
248
+ end
249
+
250
+ context 'extras (#TO3l8d)' do
251
+ let(:data) { { example: 'value', score: 1, hash: { test: true } } }
252
+ let(:client_id) { '3' }
253
+ let(:name) { 'John' }
254
+ let(:extras) { {} }
255
+
256
+ it 'should return 57 bytes' do
257
+ expect(model.size).to eq(57)
258
+ end
259
+ end
260
+
261
+ context 'nil (#TO3l8e)' do
262
+ let(:data) { nil }
263
+ let(:client_id) { '' }
264
+ let(:name) { '' }
265
+ let(:extras) { nil}
266
+
267
+ it 'should return 19 bytes' do
268
+ expect(model.size).to eq(0)
269
+ end
270
+ end
271
+ end
272
+
214
273
  context 'from REST request with embedded fields', :api_private do
215
274
  let(:id) { random_str }
216
275
  let(:protocol_message_id) { random_str }
@@ -220,6 +220,55 @@ describe Ably::Models::PresenceMessage do
220
220
  end
221
221
  end
222
222
 
223
+ describe '#size' do
224
+ let(:model) { subject.new({ action: 'enter', data: data, client_id: client_id }, protocol_message: protocol_message) }
225
+
226
+ context 'String (#TO3l8a)' do
227
+ let(:data) { 'example string data' }
228
+ let(:client_id) { '1' }
229
+
230
+ it 'should return 20 bytes' do
231
+ expect(model.size).to eq(20)
232
+ end
233
+ end
234
+
235
+ context 'Object (#TO3l8b)' do
236
+ let(:data) { Object.new }
237
+ let(:client_id) { '10' }
238
+
239
+ it 'should return 32 bytes' do
240
+ expect(model.size).to eq(32)
241
+ end
242
+ end
243
+
244
+ context 'Array (#TO3l8b)' do
245
+ let(:data) { [1, 'two', :three] }
246
+ let(:client_id) { '2' }
247
+
248
+ it 'should return 18 bytes' do
249
+ expect(model.size).to eq(18)
250
+ end
251
+ end
252
+
253
+ context 'extras (#TO3l8d)' do
254
+ let(:data) { { example: 'value', score: 1, hash: { test: true } } }
255
+ let(:client_id) { '3' }
256
+
257
+ it 'should return 51 bytes' do
258
+ expect(model.size).to eq(51)
259
+ end
260
+ end
261
+
262
+ context 'nil (#TO3l8e)' do
263
+ let(:data) { nil }
264
+ let(:client_id) { '4' }
265
+
266
+ it 'should return 1 bytes' do
267
+ expect(model.size).to eq(1)
268
+ end
269
+ end
270
+ end
271
+
223
272
  context 'from REST request with embedded fields', :api_private do
224
273
  let(:id) { random_str }
225
274
  let(:message_time) { Time.now + 60 }
@@ -318,6 +318,54 @@ describe Ably::Models::ProtocolMessage do
318
318
  end
319
319
  end
320
320
 
321
+ context '#message_size (#TO3l8)' do
322
+ context 'on presence' do
323
+ let(:protocol_message) do
324
+ new_protocol_message(presence: [{ action: 1, data: 'test342343', client_id: 'sdf' }])
325
+ end
326
+
327
+ it 'should return 13 bytes (sum in bytes: data and client_id)' do
328
+ expect(protocol_message.message_size).to eq(13)
329
+ end
330
+ end
331
+
332
+ context 'on message' do
333
+ let(:protocol_message) do
334
+ new_protocol_message(messages: [{ action: 1, unknown: 'test', data: 'test342343', client_id: 'sdf', name: 'sf23ewrew', extras: { time: Time.now, time_zone: 'UTC' } }])
335
+ end
336
+
337
+ it 'should return 76 bytes (sum in bytes: data, client_id, name, extras)' do
338
+ expect(protocol_message.message_size).to eq(76)
339
+ end
340
+ end
341
+ end
342
+
343
+ context '#has_correct_message_size? (#TO3l8)' do
344
+ context 'on presence' do
345
+ it 'should return true when a message has correct size' do
346
+ protocol_message = new_protocol_message(presence: [{ action: 1, data: 'x' * 100 }])
347
+ expect(protocol_message.has_correct_message_size?).to eq(true)
348
+ end
349
+
350
+ it 'should return false when a message has not correct size' do
351
+ protocol_message = new_protocol_message(presence: [{ action: 1, data: 'x' * 65537 }])
352
+ expect(protocol_message.has_correct_message_size?).to eq(false)
353
+ end
354
+ end
355
+
356
+ context 'on message' do
357
+ it 'should return true when a message has correct size' do
358
+ protocol_message = new_protocol_message(messages: [{ name: 'x' * 100 }])
359
+ expect(protocol_message.has_correct_message_size?).to eq(true)
360
+ end
361
+
362
+ it 'should return false when a message has not correct size' do
363
+ protocol_message = new_protocol_message(messages: [{ name: 'x' * 65537 }])
364
+ expect(protocol_message.has_correct_message_size?).to eq(false)
365
+ end
366
+ end
367
+ end
368
+
321
369
  context '#connection_details (#TR4o)' do
322
370
  let(:connection_details) { protocol_message.connection_details }
323
371
 
@@ -68,7 +68,7 @@ describe Ably::Realtime::Channel do
68
68
 
69
69
  describe '#publish name argument' do
70
70
  let(:encoded_value) { random_str.encode(encoding) }
71
- let(:message) { instance_double('Ably::Models::Message', client_id: nil) }
71
+ let(:message) { instance_double('Ably::Models::Message', client_id: nil, size: 0) }
72
72
 
73
73
  before do
74
74
  allow(subject).to receive(:create_message).and_return(message)
@@ -32,5 +32,43 @@ describe Ably::Realtime::Client::IncomingMessageDispatcher, :api_private do
32
32
  expect(subject).to receive_message_chain(:logger, :warn)
33
33
  msgbus.publish :protocol_message, Ably::Models::ProtocolMessage.new(:action => :attached, channel: 'unknown')
34
34
  end
35
+
36
+ context 'TO3l8' do
37
+ context 'on action presence' do
38
+ let(:presence) { 101.times.map { { data: 'x' * 655 } } }
39
+
40
+ let(:protocol_message) do
41
+ Ably::Models::ProtocolMessage.new(action: :presence, channel: 'default', presence: presence, connection_serial: 123123123)
42
+ end
43
+
44
+ it 'should raise a protocol error when message size exceeded 65536 bytes' do
45
+ allow(connection).to receive(:serial).and_return(12312312)
46
+ allow(subject).to receive(:update_connection_recovery_info)
47
+ allow(subject).to receive_message_chain(:logger, :debug)
48
+ allow(subject).to receive_message_chain(:logger, :warn)
49
+ expect(subject).to receive_message_chain(:logger, :fatal)
50
+
51
+ msgbus.publish :protocol_message, protocol_message
52
+ end
53
+ end
54
+
55
+ context 'on action message' do
56
+ let(:messages) { 101.times.map { { data: 'x' * 655 } } }
57
+
58
+ let(:protocol_message) do
59
+ Ably::Models::ProtocolMessage.new(action: :message, channel: 'default', messages: messages, connection_serial: 123123123)
60
+ end
61
+
62
+ it 'should raise a protocol error when message size exceeded 65536 bytes' do
63
+ allow(connection).to receive(:serial).and_return(12312312)
64
+ allow(subject).to receive(:update_connection_recovery_info)
65
+ allow(subject).to receive_message_chain(:logger, :debug)
66
+ allow(subject).to receive_message_chain(:logger, :warn)
67
+ expect(subject).to receive_message_chain(:logger, :fatal)
68
+
69
+ msgbus.publish :protocol_message, protocol_message
70
+ end
71
+ end
72
+ end
35
73
  end
36
74
  end
@@ -14,6 +14,10 @@ describe Ably::Rest::Channel do
14
14
 
15
15
  subject { Ably::Rest::Channel.new(client, channel_name) }
16
16
 
17
+ it 'should return Ably::Rest::Channel::MAX_MESSAGE_SIZE equal 65536 (TO3l8)' do
18
+ expect(Ably::Rest::Channel::MAX_MESSAGE_SIZE).to eq(65536)
19
+ end
20
+
17
21
  describe '#initializer' do
18
22
  let(:channel_name) { random_str.encode(encoding) }
19
23
 
@@ -126,5 +130,11 @@ describe Ably::Rest::Channel do
126
130
  expect { subject.publish(encoded_value, 'data') }.to raise_error ArgumentError, /must be a String/
127
131
  end
128
132
  end
133
+
134
+ context 'max message size exceeded' do
135
+ it 'should raise Ably::Exceptions::MaxMessageSizeExceeded' do
136
+ expect { subject.publish('x' * 65537, 'data') }.to raise_error Ably::Exceptions::MaxMessageSizeExceeded
137
+ end
138
+ end
129
139
  end
130
140
  end
@@ -38,6 +38,26 @@ describe Ably::Rest::Client do
38
38
  end
39
39
  end
40
40
 
41
+ context 'use agent' do
42
+ context 'set agent to non-default value' do
43
+ context 'default agent' do
44
+ let(:client_options) { { key: 'appid.keyuid:keysecret' } }
45
+
46
+ it 'should return default ably agent' do
47
+ expect(subject.agent).to eq(Ably::AGENT)
48
+ end
49
+ end
50
+
51
+ context 'custom agent' do
52
+ let(:client_options) { { key: 'appid.keyuid:keysecret', agent: 'example-gem/1.1.4 ably-ruby/1.1.5 ruby/3.0.0' } }
53
+
54
+ it 'should overwrite client.agent' do
55
+ expect(subject.agent).to eq('example-gem/1.1.4 ably-ruby/1.1.5 ruby/3.0.0')
56
+ end
57
+ end
58
+ end
59
+ end
60
+
41
61
  context ':use_token_auth' do
42
62
  context 'set to false' do
43
63
  context 'with a key and :tls => false' do
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Ably::Rest::Client do
5
+ subject do
6
+ Ably::Rest::Client.new(client_options)
7
+ end
8
+
9
+ context 'initializer options' do
10
+ context 'default agent' do
11
+ let(:client_options) { { key: 'appid.keyuid:keysecret' } }
12
+
13
+ it 'should return Ably::AGENT identifier' do
14
+ expect(subject.agent).to eq(Ably::AGENT)
15
+ end
16
+
17
+ it 'should show ably-ruby ruby and ably-ruby-rest identifier' do
18
+ expect(subject.agent).to match(/^ably-ruby\/\d.\d.\d ruby\/\d.\d.\d ably-ruby-rest$/)
19
+ end
20
+ end
21
+
22
+ context 'custom agent' do
23
+ let(:client_options) { { key: 'appid.keyuid:keysecret', agent: 'my-custom-agent/1.1' } }
24
+
25
+ it 'should show my-custom-agent/1.1' do
26
+ expect(subject.agent).to eq('my-custom-agent/1.1')
27
+ end
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ably-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew O'Riordan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-25 00:00:00.000000000 Z
11
+ date: 2021-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -285,6 +285,7 @@ files:
285
285
  - lib/submodules/ably-ruby/SPEC.md
286
286
  - lib/submodules/ably-ruby/ably.gemspec
287
287
  - lib/submodules/ably-ruby/lib/ably.rb
288
+ - lib/submodules/ably-ruby/lib/ably/agent.rb
288
289
  - lib/submodules/ably-ruby/lib/ably/auth.rb
289
290
  - lib/submodules/ably-ruby/lib/ably/exceptions.rb
290
291
  - lib/submodules/ably-ruby/lib/ably/logger.rb
@@ -472,6 +473,7 @@ files:
472
473
  - spec/acceptance/rest_spec.rb
473
474
  - spec/spec_helper.rb
474
475
  - spec/unit/base_spec.rb
476
+ - spec/unit/client_spec.rb
475
477
  - spec/unit/models_spec.rb
476
478
  - spec/unit/modules_spec.rb
477
479
  - spec/unit/rest_spec.rb
@@ -503,6 +505,7 @@ test_files:
503
505
  - spec/acceptance/rest_spec.rb
504
506
  - spec/spec_helper.rb
505
507
  - spec/unit/base_spec.rb
508
+ - spec/unit/client_spec.rb
506
509
  - spec/unit/models_spec.rb
507
510
  - spec/unit/modules_spec.rb
508
511
  - spec/unit/rest_spec.rb