ably 0.8.3 → 0.8.4

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -3
  3. data/lib/ably/auth.rb +1 -1
  4. data/lib/ably/exceptions.rb +3 -0
  5. data/lib/ably/models/channel_state_change.rb +41 -0
  6. data/lib/ably/models/connection_state_change.rb +43 -0
  7. data/lib/ably/models/message.rb +1 -1
  8. data/lib/ably/models/presence_message.rb +1 -1
  9. data/lib/ably/models/protocol_message.rb +2 -1
  10. data/lib/ably/modules/state_emitter.rb +4 -1
  11. data/lib/ably/modules/uses_state_machine.rb +28 -4
  12. data/lib/ably/realtime/channel.rb +11 -3
  13. data/lib/ably/realtime/channel/channel_manager.rb +24 -4
  14. data/lib/ably/realtime/channel/channel_state_machine.rb +20 -11
  15. data/lib/ably/realtime/client/incoming_message_dispatcher.rb +4 -4
  16. data/lib/ably/realtime/connection.rb +1 -0
  17. data/lib/ably/realtime/connection/connection_manager.rb +33 -21
  18. data/lib/ably/realtime/connection/connection_state_machine.rb +24 -16
  19. data/lib/ably/rest/channel.rb +3 -2
  20. data/lib/ably/util/crypto.rb +15 -0
  21. data/lib/ably/version.rb +1 -1
  22. data/spec/acceptance/realtime/channel_spec.rb +155 -9
  23. data/spec/acceptance/realtime/client_spec.rb +2 -2
  24. data/spec/acceptance/realtime/connection_failures_spec.rb +8 -4
  25. data/spec/acceptance/realtime/connection_spec.rb +122 -11
  26. data/spec/acceptance/realtime/message_spec.rb +119 -3
  27. data/spec/acceptance/realtime/presence_spec.rb +34 -13
  28. data/spec/acceptance/rest/channel_spec.rb +9 -0
  29. data/spec/acceptance/rest/client_spec.rb +10 -0
  30. data/spec/unit/models/channel_state_change_spec.rb +44 -0
  31. data/spec/unit/models/connection_state_change_spec.rb +54 -0
  32. data/spec/unit/util/crypto_spec.rb +18 -0
  33. metadata +8 -2
@@ -22,6 +22,15 @@ describe Ably::Rest::Channel do
22
22
  expect(channel.history.items.first.name).to eql(name)
23
23
  expect(channel.history.items.first.data).to eql(data)
24
24
  end
25
+
26
+ context 'and additional attributes' do
27
+ let(:client_id) { random_str }
28
+
29
+ it 'publishes the message with the attributes and return true indicating success' do
30
+ expect(channel.publish(name, data, client_id: client_id)).to eql(true)
31
+ expect(channel.history.items.first.client_id).to eql(client_id)
32
+ end
33
+ end
25
34
  end
26
35
 
27
36
  context 'with an array of Hash objects with :name and :data attributes' do
@@ -63,6 +63,16 @@ describe Ably::Rest::Client do
63
63
  end
64
64
  end
65
65
 
66
+ context 'with an :auth_callback Proc (clientId provided in library options instead of as a token_request param)' do
67
+ let(:client) { Ably::Rest::Client.new(client_options.merge(client_id: client_id, auth_callback: Proc.new { token_request })) }
68
+ let(:token_request) { client.auth.create_token_request(key_name: key_name, key_secret: key_secret) }
69
+
70
+ it 'correctly sets the clientId on the token' do
71
+ expect { client.channel('channel_name').publish('event', 'message') }.to change { client.auth.current_token_details }
72
+ expect(client.auth.current_token_details.client_id).to eql(client_id)
73
+ end
74
+ end
75
+
66
76
  context 'with an auth URL' do
67
77
  let(:client_options) { default_options.merge(key: api_key, auth_url: token_request_url, auth_method: :get) }
68
78
  let(:token_request_url) { 'http://get.token.request.com/' }
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'shared/model_behaviour'
3
+
4
+ describe Ably::Models::ChannelStateChange do
5
+ let(:unique) { random_str }
6
+
7
+ subject { Ably::Models::ChannelStateChange }
8
+
9
+ context '#current' do
10
+ it 'is required' do
11
+ expect { subject.new(previous: true) }.to raise_error ArgumentError
12
+ end
13
+
14
+ it 'is an attribute' do
15
+ expect(subject.new(current: unique, previous: true).current).to eql(unique)
16
+ end
17
+ end
18
+
19
+ context '#previous' do
20
+ it 'is required' do
21
+ expect { subject.new(current: true) }.to raise_error ArgumentError
22
+ end
23
+
24
+ it 'is an attribute' do
25
+ expect(subject.new(previous: unique, current: true).previous).to eql(unique)
26
+ end
27
+ end
28
+
29
+ context '#reason' do
30
+ it 'is not required' do
31
+ expect { subject.new(previous: true, current: true) }.to_not raise_error
32
+ end
33
+
34
+ it 'is an attribute' do
35
+ expect(subject.new(reason: unique, previous: unique, current: true).reason).to eql(unique)
36
+ end
37
+ end
38
+
39
+ context 'invalid attributes' do
40
+ it 'raises an argument error' do
41
+ expect { subject.new(invalid: true, current: true, previous: true) }.to raise_error ArgumentError
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require 'shared/model_behaviour'
3
+
4
+ describe Ably::Models::ConnectionStateChange do
5
+ let(:unique) { random_str }
6
+
7
+ subject { Ably::Models::ConnectionStateChange }
8
+
9
+ context '#current' do
10
+ it 'is required' do
11
+ expect { subject.new(previous: true) }.to raise_error ArgumentError
12
+ end
13
+
14
+ it 'is an attribute' do
15
+ expect(subject.new(current: unique, previous: true).current).to eql(unique)
16
+ end
17
+ end
18
+
19
+ context '#previous' do
20
+ it 'is required' do
21
+ expect { subject.new(current: true) }.to raise_error ArgumentError
22
+ end
23
+
24
+ it 'is an attribute' do
25
+ expect(subject.new(previous: unique, current: true).previous).to eql(unique)
26
+ end
27
+ end
28
+
29
+ context '#retry_in' do
30
+ it 'is not required' do
31
+ expect { subject.new(previous: true, current: true) }.to_not raise_error
32
+ end
33
+
34
+ it 'is an attribute' do
35
+ expect(subject.new(retry_in: unique, previous: unique, current: true).retry_in).to eql(unique)
36
+ end
37
+ end
38
+
39
+ context '#reason' do
40
+ it 'is not required' do
41
+ expect { subject.new(previous: true, current: true) }.to_not raise_error
42
+ end
43
+
44
+ it 'is an attribute' do
45
+ expect(subject.new(reason: unique, previous: unique, current: true).reason).to eql(unique)
46
+ end
47
+ end
48
+
49
+ context 'invalid attributes' do
50
+ it 'raises an argument error' do
51
+ expect { subject.new(invalid: true, current: true, previous: true) }.to raise_error ArgumentError
52
+ end
53
+ end
54
+ end
@@ -21,6 +21,24 @@ describe Ably::Util::Crypto do
21
21
  end
22
22
  end
23
23
 
24
+ context 'get_default_params' do
25
+ it 'uses the defaults and generates a key if not provided' do
26
+ expect(Ably::Util::Crypto.get_default_params[:algorithm]).to eql('AES')
27
+ expect(Ably::Util::Crypto.get_default_params[:mode]).to eql('CBC')
28
+ expect(Ably::Util::Crypto.get_default_params[:key_length]).to eql(128)
29
+ expect(Ably::Util::Crypto.get_default_params[:key].unpack('b*').first.length).to eql(128)
30
+ end
31
+
32
+ it 'uses the defaults and sets the key size when key is provided' do
33
+ key_192 = '123456781234567812345678'
34
+ params = Ably::Util::Crypto.get_default_params(key_192)
35
+ expect(params[:algorithm]).to eql('AES')
36
+ expect(params[:mode]).to eql('CBC')
37
+ expect(params[:key_length]).to eql(192)
38
+ expect(params[:key]).to eql(key_192)
39
+ end
40
+ end
41
+
24
42
  context 'encrypts & decrypt' do
25
43
  let(:string) { random_str }
26
44
  let(:byte_array) { random_str.to_msgpack.unpack('C*') }
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: 0.8.3
4
+ version: 0.8.4
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: 2015-08-19 00:00:00.000000000 Z
12
+ date: 2015-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -244,6 +244,8 @@ files:
244
244
  - lib/ably/auth.rb
245
245
  - lib/ably/exceptions.rb
246
246
  - lib/ably/logger.rb
247
+ - lib/ably/models/channel_state_change.rb
248
+ - lib/ably/models/connection_state_change.rb
247
249
  - lib/ably/models/error_info.rb
248
250
  - lib/ably/models/idiomatic_ruby_wrapper.rb
249
251
  - lib/ably/models/message.rb
@@ -350,6 +352,8 @@ files:
350
352
  - spec/support/test_app.rb
351
353
  - spec/unit/auth_spec.rb
352
354
  - spec/unit/logger_spec.rb
355
+ - spec/unit/models/channel_state_change_spec.rb
356
+ - spec/unit/models/connection_state_change_spec.rb
353
357
  - spec/unit/models/error_info_spec.rb
354
358
  - spec/unit/models/idiomatic_ruby_wrapper_spec.rb
355
359
  - spec/unit/models/message_encoders/base64_spec.rb
@@ -446,6 +450,8 @@ test_files:
446
450
  - spec/support/test_app.rb
447
451
  - spec/unit/auth_spec.rb
448
452
  - spec/unit/logger_spec.rb
453
+ - spec/unit/models/channel_state_change_spec.rb
454
+ - spec/unit/models/connection_state_change_spec.rb
449
455
  - spec/unit/models/error_info_spec.rb
450
456
  - spec/unit/models/idiomatic_ruby_wrapper_spec.rb
451
457
  - spec/unit/models/message_encoders/base64_spec.rb