ably 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/Rakefile +1 -1
  4. data/lib/ably/auth.rb +23 -19
  5. data/lib/ably/models/token_details.rb +8 -6
  6. data/lib/ably/modules/conversions.rb +4 -0
  7. data/lib/ably/modules/state_emitter.rb +1 -1
  8. data/lib/ably/modules/uses_state_machine.rb +8 -1
  9. data/lib/ably/realtime/auth.rb +13 -13
  10. data/lib/ably/realtime/channel.rb +2 -2
  11. data/lib/ably/realtime/channel/channel_manager.rb +3 -3
  12. data/lib/ably/realtime/channel/channel_state_machine.rb +2 -1
  13. data/lib/ably/realtime/client/incoming_message_dispatcher.rb +13 -7
  14. data/lib/ably/realtime/client/outgoing_message_dispatcher.rb +6 -0
  15. data/lib/ably/realtime/connection.rb +4 -4
  16. data/lib/ably/realtime/connection/connection_manager.rb +9 -3
  17. data/lib/ably/realtime/connection/connection_state_machine.rb +1 -1
  18. data/lib/ably/realtime/presence.rb +4 -4
  19. data/lib/ably/rest/client.rb +2 -2
  20. data/lib/ably/version.rb +1 -1
  21. data/spec/acceptance/realtime/auth_spec.rb +9 -9
  22. data/spec/acceptance/realtime/channel_history_spec.rb +2 -2
  23. data/spec/acceptance/realtime/channel_spec.rb +13 -12
  24. data/spec/acceptance/realtime/channels_spec.rb +6 -2
  25. data/spec/acceptance/realtime/client_spec.rb +4 -3
  26. data/spec/acceptance/realtime/connection_failures_spec.rb +21 -15
  27. data/spec/acceptance/realtime/connection_spec.rb +31 -27
  28. data/spec/acceptance/realtime/message_spec.rb +31 -24
  29. data/spec/acceptance/realtime/presence_history_spec.rb +2 -2
  30. data/spec/acceptance/realtime/presence_spec.rb +10 -11
  31. data/spec/acceptance/realtime/stats_spec.rb +1 -1
  32. data/spec/acceptance/realtime/time_spec.rb +1 -1
  33. data/spec/acceptance/rest/auth_spec.rb +77 -46
  34. data/spec/acceptance/rest/channel_spec.rb +22 -3
  35. data/spec/acceptance/rest/client_spec.rb +6 -6
  36. data/spec/acceptance/rest/presence_spec.rb +9 -7
  37. data/spec/support/event_machine_helper.rb +30 -4
  38. data/spec/support/protocol_helper.rb +9 -6
  39. data/spec/unit/auth_spec.rb +1 -1
  40. data/spec/unit/models/token_details_spec.rb +8 -0
  41. data/spec/unit/modules/async_wrapper_spec.rb +1 -1
  42. metadata +2 -2
@@ -12,9 +12,10 @@ describe Ably::Rest::Channel do
12
12
  end
13
13
 
14
14
  describe '#publish' do
15
- let(:channel) { client.channel(random_str) }
16
- let(:name) { 'foo' }
17
- let(:data) { 'woop!' }
15
+ let(:channel_name) { random_str }
16
+ let(:channel) { client.channel(channel_name) }
17
+ let(:name) { 'foo' }
18
+ let(:data) { 'woop!' }
18
19
 
19
20
  context 'with name and data arguments' do
20
21
  it 'publishes the message and return true indicating success' do
@@ -33,6 +34,24 @@ describe Ably::Rest::Channel do
33
34
  end
34
35
  end
35
36
 
37
+ context 'with a client_id configured in the ClientOptions' do
38
+ let(:client_id) { random_str }
39
+ let(:client_options) { default_options.merge(client_id: client_id) }
40
+
41
+ it 'publishes the message without a client_id' do
42
+ expect(client).to receive(:post).
43
+ with("/channels/#{channel_name}/publish", hash_excluding(client_id: client_id)).
44
+ and_return(double('response', status: 201))
45
+
46
+ expect(channel.publish(name, data)).to eql(true)
47
+ end
48
+
49
+ it 'expects a client_id to be added by the realtime service' do
50
+ channel.publish name, data
51
+ expect(channel.history.items.first.client_id).to eql(client_id)
52
+ end
53
+ end
54
+
36
55
  context 'with an array of Hash objects with :name and :data attributes' do
37
56
  let(:messages) do
38
57
  10.times.map do |index|
@@ -16,7 +16,7 @@ describe Ably::Rest::Client do
16
16
 
17
17
  context '#initialize' do
18
18
  let(:client_id) { random_str }
19
- let(:token_request) { client.auth.create_token_request(key_name: key_name, key_secret: key_secret, client_id: client_id) }
19
+ let(:token_request) { client.auth.create_token_request({}, key_name: key_name, key_secret: key_secret, client_id: client_id) }
20
20
 
21
21
  context 'with only an API key' do
22
22
  let(:client) { Ably::Rest::Client.new(client_options.merge(key: api_key)) }
@@ -65,7 +65,7 @@ describe Ably::Rest::Client do
65
65
 
66
66
  context 'with an :auth_callback Proc (clientId provided in library options instead of as a token_request param)' do
67
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) }
68
+ let(:token_request) { client.auth.create_token_request({}, key_name: key_name, key_secret: key_secret) }
69
69
 
70
70
  it 'correctly sets the clientId on the token' do
71
71
  expect { client.channel('channel_name').publish('event', 'message') }.to change { client.auth.current_token_details }
@@ -84,7 +84,7 @@ describe Ably::Rest::Client do
84
84
  context 'before any REST request' do
85
85
  before do
86
86
  expect(client.auth).to receive(:token_request_from_auth_url).with(token_request_url, hash_including(:auth_method => :get)).once do
87
- client.auth.create_token_request(token_params: { client_id: client_id })
87
+ client.auth.create_token_request(client_id: client_id)
88
88
  end
89
89
  end
90
90
 
@@ -154,11 +154,11 @@ describe Ably::Rest::Client do
154
154
  send("token_request_#{@request_index > 2 ? 'next' : @request_index}")
155
155
  end))
156
156
  end
157
- let(:token_request_1) { client.auth.create_token_request(token_request_options.merge(client_id: random_str)) }
158
- let(:token_request_2) { client.auth.create_token_request(token_request_options.merge(client_id: random_str)) }
157
+ let(:token_request_1) { client.auth.create_token_request({}, token_request_options.merge(client_id: random_str)) }
158
+ let(:token_request_2) { client.auth.create_token_request({}, token_request_options.merge(client_id: random_str)) }
159
159
 
160
160
  # If token expires against whilst runnig tests in a slower CI environment then use this token
161
- let(:token_request_next) { client.auth.create_token_request(token_request_options.merge(client_id: random_str)) }
161
+ let(:token_request_next) { client.auth.create_token_request({}, token_request_options.merge(client_id: random_str)) }
162
162
 
163
163
  context 'when expired' do
164
164
  before do
@@ -93,23 +93,25 @@ describe Ably::Rest::Presence do
93
93
 
94
94
  context 'with :client_id option' do
95
95
  let(:client_id) { non_encoded_fixtures.first[:client_id] }
96
- let(:presence_page) { fixtures_channel.presence.get(client_id: client_id) }
96
+ let(:presence_page) { fixtures_channel.presence.get(client_id: client_id) }
97
97
 
98
98
  it 'returns a list members filtered by the provided client ID' do
99
- pending 'not implemented in the REST API yet' # TODO realtime/issues/243
100
99
  expect(presence_page.items.count).to eql(1)
101
100
  expect(presence_page.items.first.client_id).to eql(client_id)
102
101
  end
103
102
  end
104
103
 
105
104
  context 'with :connection_id option' do
106
- let(:connection_id) { fixtures_channel.presence.get.first.connection_id }
107
- let(:presence_page) { fixtures_channel.presence.get(connection_id: connection_id) }
105
+ let(:all_members) { fixtures_channel.presence.get.items }
106
+ let(:connection_id) { all_members.first.connection_id }
107
+ let(:presence_page) { fixtures_channel.presence.get(connection_id: connection_id) }
108
108
 
109
109
  it 'returns a list members filtered by the provided connection ID' do
110
- pending 'not implemented in the REST API yet' # TODO realtime/issues/243
111
- expect(presence_page.items.count).to eql(1)
112
- expect(presence_page.items.first.connetion_id).to eql(connetion_id)
110
+ expect(presence_page.items.all? { |member| member.connection_id == connection_id }).to eql(true)
111
+ end
112
+
113
+ it 'returns a list members filtered by the provided connection ID' do
114
+ expect(fixtures_channel.presence.get(connection_id: 'does.not.exist').items).to be_empty
113
115
  end
114
116
  end
115
117
  end
@@ -17,11 +17,34 @@ module RSpec
17
17
  end
18
18
 
19
19
  def stop_reactor
20
+ unless realtime_clients.empty?
21
+ realtime_clients.shift.tap do |client|
22
+ # Ensure close appens outside of the caller as this can cause errbacks on Deferrables
23
+ # e.g. connection.connect { connection.close } => # Error as calling close within the connected callback
24
+ ::EventMachine.add_timer(0.05) do
25
+ client.close if client.connection.can_transition_to?(:closing)
26
+ ::EventMachine.add_timer(0.1) { stop_reactor }
27
+ end
28
+ end
29
+ return
30
+ end
31
+
20
32
  ::EventMachine.next_tick do
21
33
  ::EventMachine.stop
22
34
  end
23
35
  end
24
36
 
37
+ # Ensures that any clients used in tests will have their connections
38
+ # explicitly closed when stop_reactor is called
39
+ def auto_close(realtime_client)
40
+ realtime_clients << realtime_client
41
+ realtime_client
42
+ end
43
+
44
+ def realtime_clients
45
+ @realtime_clients ||= []
46
+ end
47
+
25
48
  # Allows multiple Deferrables to be passed in and calls the provided block when
26
49
  # all success callbacks have completed
27
50
  def when_all(*deferrables)
@@ -48,7 +71,7 @@ module RSpec
48
71
  end
49
72
 
50
73
  deferrable.errback do |error|
51
- raise RuntimeError, "Deferrable failed: #{error.message}"
74
+ raise RuntimeError, "Error: Deferrable failed: #{error}"
52
75
  end
53
76
  end
54
77
  end
@@ -56,9 +79,12 @@ module RSpec
56
79
  def wait_until(condition_block, &block)
57
80
  raise ArgumentError, 'Block required' unless block_given?
58
81
 
59
- yield if condition_block.call
60
- ::EventMachine.add_timer(0.1) do
61
- wait_until condition_block, &block
82
+ if condition_block.call
83
+ yield
84
+ else
85
+ ::EventMachine.add_timer(0.1) do
86
+ wait_until condition_block, &block
87
+ end
62
88
  end
63
89
  end
64
90
  end
@@ -1,12 +1,15 @@
1
1
  module RSpec
2
2
  module ProtocolHelper
3
- PROTOCOLS = if ENV['TEST_LIMIT_PROTOCOLS']
4
- JSON.parse(ENV['TEST_LIMIT_PROTOCOLS'])
3
+ SUPPORTED_PROTOCOLS = {
4
+ json: 'JSON',
5
+ msgpack: 'MsgPack'
6
+ }
7
+
8
+ PROTOCOLS = if ENV['PROTOCOL']
9
+ protocol = ENV['PROTOCOL'].downcase.to_sym
10
+ { protocol => SUPPORTED_PROTOCOLS[protocol] }
5
11
  else
6
- {
7
- json: 'JSON',
8
- msgpack: 'MsgPack'
9
- }
12
+ SUPPORTED_PROTOCOLS
10
13
  end
11
14
 
12
15
  def vary_by_protocol(&block)
@@ -8,7 +8,7 @@ describe Ably::Auth do
8
8
  let(:token_params) { { } }
9
9
 
10
10
  subject do
11
- Ably::Auth.new(client, auth_options, token_params)
11
+ Ably::Auth.new(client, token_params, auth_options)
12
12
  end
13
13
 
14
14
  describe 'client_id option' do
@@ -70,6 +70,14 @@ describe Ably::Models::TokenDetails do
70
70
  expect(subject.expired?).to eql(false)
71
71
  end
72
72
  end
73
+
74
+ context 'when expires is not available (i.e. string tokens)' do
75
+ subject { Ably::Models::TokenDetails.new() }
76
+
77
+ it 'is always false' do
78
+ expect(subject.expired?).to eql(false)
79
+ end
80
+ end
73
81
  end
74
82
  end
75
83
 
@@ -82,7 +82,7 @@ describe Ably::Modules::AsyncWrapper, :api_private do
82
82
  expect(result).to eql(result)
83
83
  EventMachine.add_timer(sleep_time * 2) { stop_reactor }
84
84
  end
85
- deferrable.errback do |result|
85
+ deferrable.errback do |error|
86
86
  raise 'Errback should not have been called'
87
87
  end
88
88
  end
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.4
4
+ version: 0.8.5
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-09-08 00:00:00.000000000 Z
12
+ date: 2015-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine