ably 0.7.5 → 0.7.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 +5 -13
- data/.gitignore +1 -0
- data/.gitmodules +3 -0
- data/README.md +46 -22
- data/SPEC.md +345 -240
- data/ably.gemspec +4 -2
- data/lib/ably/auth.rb +18 -14
- data/lib/ably/models/message.rb +1 -1
- data/lib/ably/models/paginated_resource.rb +31 -44
- data/lib/ably/models/presence_message.rb +1 -1
- data/lib/ably/models/stat.rb +67 -24
- data/lib/ably/models/stats_types.rb +131 -0
- data/lib/ably/modules/async_wrapper.rb +3 -2
- data/lib/ably/modules/message_emitter.rb +2 -2
- data/lib/ably/realtime.rb +1 -1
- data/lib/ably/realtime/channel.rb +24 -3
- data/lib/ably/realtime/channel/channel_manager.rb +1 -0
- data/lib/ably/realtime/client.rb +2 -2
- data/lib/ably/realtime/connection.rb +1 -1
- data/lib/ably/realtime/presence.rb +12 -1
- data/lib/ably/rest.rb +1 -1
- data/lib/ably/rest/channel.rb +4 -5
- data/lib/ably/rest/client.rb +5 -5
- data/lib/ably/rest/presence.rb +2 -2
- data/lib/ably/version.rb +1 -1
- data/spec/acceptance/realtime/channel_history_spec.rb +74 -23
- data/spec/acceptance/realtime/channel_spec.rb +3 -3
- data/spec/acceptance/realtime/client_spec.rb +3 -3
- data/spec/acceptance/realtime/connection_failures_spec.rb +2 -2
- data/spec/acceptance/realtime/connection_spec.rb +4 -4
- data/spec/acceptance/realtime/message_spec.rb +5 -5
- data/spec/acceptance/realtime/presence_history_spec.rb +56 -13
- data/spec/acceptance/realtime/presence_spec.rb +8 -8
- data/spec/acceptance/realtime/stats_spec.rb +1 -1
- data/spec/acceptance/realtime/time_spec.rb +1 -1
- data/spec/acceptance/rest/auth_spec.rb +31 -4
- data/spec/acceptance/rest/base_spec.rb +3 -3
- data/spec/acceptance/rest/channel_spec.rb +19 -19
- data/spec/acceptance/rest/channels_spec.rb +1 -1
- data/spec/acceptance/rest/client_spec.rb +9 -6
- data/spec/acceptance/rest/encoders_spec.rb +1 -1
- data/spec/acceptance/rest/message_spec.rb +10 -10
- data/spec/acceptance/rest/presence_spec.rb +81 -51
- data/spec/acceptance/rest/stats_spec.rb +46 -41
- data/spec/acceptance/rest/time_spec.rb +1 -1
- data/spec/shared/client_initializer_behaviour.rb +30 -19
- data/spec/spec_helper.rb +3 -0
- data/spec/support/markdown_spec_formatter.rb +1 -1
- data/spec/support/test_app.rb +11 -24
- data/spec/unit/auth_spec.rb +1 -1
- data/spec/unit/models/paginated_resource_spec.rb +81 -72
- data/spec/unit/models/stats_spec.rb +289 -0
- data/spec/unit/modules/async_wrapper_spec.rb +1 -1
- data/spec/unit/realtime/client_spec.rb +1 -1
- data/spec/unit/realtime/realtime_spec.rb +1 -1
- data/spec/unit/rest/channel_spec.rb +1 -1
- data/spec/unit/rest/client_spec.rb +8 -8
- data/spec/unit/rest/rest_spec.rb +1 -1
- data/spec/unit/util/crypto_spec.rb +1 -1
- metadata +55 -43
- data/spec/resources/crypto-data-128.json +0 -56
- data/spec/resources/crypto-data-256.json +0 -56
- data/spec/unit/models/stat_spec.rb +0 -113
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
describe Ably::Realtime::Client, :event_machine do
|
5
5
|
vary_by_protocol do
|
6
6
|
let(:default_options) do
|
7
|
-
{
|
7
|
+
{ key: api_key, environment: environment, protocol: protocol }
|
8
8
|
end
|
9
9
|
|
10
10
|
let(:client_options) { default_options }
|
@@ -15,7 +15,7 @@ describe Ably::Realtime::Client, :event_machine do
|
|
15
15
|
|
16
16
|
context 'initialization' do
|
17
17
|
context 'basic auth' do
|
18
|
-
it 'is enabled by default with a provided :
|
18
|
+
it 'is enabled by default with a provided :key option' do
|
19
19
|
connection.on(:connected) do
|
20
20
|
expect(auth_params[:key_id]).to_not be_nil
|
21
21
|
expect(auth_params[:access_token]).to be_nil
|
@@ -58,7 +58,7 @@ describe Ably::Realtime::Client, :event_machine do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
context 'with valid :
|
61
|
+
context 'with valid :key and :use_token_auth option set to true' do
|
62
62
|
let(:client_options) { default_options.merge(use_token_auth: true) }
|
63
63
|
|
64
64
|
it 'automatically authorises on connect and generates a token' do
|
@@ -6,7 +6,7 @@ describe Ably::Realtime::Connection, 'failures', :event_machine do
|
|
6
6
|
|
7
7
|
vary_by_protocol do
|
8
8
|
let(:default_options) do
|
9
|
-
{
|
9
|
+
{ key: api_key, environment: environment, protocol: protocol }
|
10
10
|
end
|
11
11
|
|
12
12
|
let(:client_options) { default_options }
|
@@ -16,7 +16,7 @@ describe Ably::Realtime::Connection, 'failures', :event_machine do
|
|
16
16
|
|
17
17
|
context 'authentication failure' do
|
18
18
|
let(:client_options) do
|
19
|
-
default_options.merge(
|
19
|
+
default_options.merge(key: invalid_key, log_level: :none)
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'when API key is invalid' do
|
@@ -7,7 +7,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
7
7
|
|
8
8
|
vary_by_protocol do
|
9
9
|
let(:default_options) do
|
10
|
-
{
|
10
|
+
{ key: api_key, environment: environment, protocol: protocol }
|
11
11
|
end
|
12
12
|
|
13
13
|
let(:client_options) { default_options }
|
@@ -138,11 +138,11 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
138
138
|
|
139
139
|
context 'when connected with a valid non-expired token' do
|
140
140
|
context 'that then expires following the connection being opened' do
|
141
|
-
let(:ttl) {
|
141
|
+
let(:ttl) { 5 }
|
142
142
|
let(:channel) { client.channel('test') }
|
143
143
|
|
144
144
|
context 'the server' do
|
145
|
-
it 'disconnects the client, and the client automatically renews the token and then reconnects', em_timeout:
|
145
|
+
it 'disconnects the client, and the client automatically renews the token and then reconnects', em_timeout: 15 do
|
146
146
|
original_token = client.auth.current_token
|
147
147
|
expect(original_token).to_not be_expired
|
148
148
|
|
@@ -177,7 +177,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
177
177
|
end
|
178
178
|
|
179
179
|
context 'opening a new connection' do
|
180
|
-
let(:client_options) { default_options.merge(
|
180
|
+
let(:client_options) { default_options.merge(key: nil, token_id: expired_token.id, log_level: :none) }
|
181
181
|
|
182
182
|
it 'transitions state to failed', em_timeout: 10 do
|
183
183
|
EventMachine.add_timer(1) do # wait for token to expire
|
@@ -6,7 +6,7 @@ require 'securerandom'
|
|
6
6
|
|
7
7
|
describe 'Ably::Realtime::Channel Message', :event_machine do
|
8
8
|
vary_by_protocol do
|
9
|
-
let(:default_options) { options.merge(
|
9
|
+
let(:default_options) { options.merge(key: api_key, environment: environment, protocol: protocol) }
|
10
10
|
let(:client_options) { default_options }
|
11
11
|
let(:client) do
|
12
12
|
Ably::Realtime::Client.new(client_options)
|
@@ -77,8 +77,8 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
77
77
|
context 'when retrieved over REST' do
|
78
78
|
it 'matches the sender connection#id' do
|
79
79
|
channel.publish('event', payload) do
|
80
|
-
channel.history do |
|
81
|
-
expect(
|
80
|
+
channel.history do |page|
|
81
|
+
expect(page.items.first.connection_id).to eql(client.connection.id)
|
82
82
|
stop_reactor
|
83
83
|
end
|
84
84
|
end
|
@@ -175,7 +175,7 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
175
175
|
|
176
176
|
context 'without suitable publishing permissions' do
|
177
177
|
let(:restricted_client) do
|
178
|
-
Ably::Realtime::Client.new(options.merge(
|
178
|
+
Ably::Realtime::Client.new(options.merge(key: restricted_api_key, environment: environment, protocol: protocol))
|
179
179
|
end
|
180
180
|
let(:restricted_channel) { restricted_client.channel("cansubscribe:example") }
|
181
181
|
let(:payload) { 'Test message without permission to publish' }
|
@@ -293,7 +293,7 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
293
293
|
end
|
294
294
|
end
|
295
295
|
|
296
|
-
resources_root = File.expand_path('
|
296
|
+
resources_root = File.expand_path('../../../../lib/submodules/ably-common/test-resources', __FILE__)
|
297
297
|
|
298
298
|
def self.add_tests_for_data(data)
|
299
299
|
data['items'].each_with_index do |item, index|
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Ably::Realtime::Presence, 'history', :event_machine do
|
5
5
|
vary_by_protocol do
|
6
|
-
let(:default_options) { {
|
6
|
+
let(:default_options) { { key: api_key, environment: environment, protocol: protocol } }
|
7
7
|
|
8
8
|
let(:channel_name) { "persisted:#{random_str(2)}" }
|
9
9
|
|
@@ -21,16 +21,16 @@ describe Ably::Realtime::Presence, 'history', :event_machine do
|
|
21
21
|
it 'provides up to the moment presence history' do
|
22
22
|
presence_client_one.enter(data: data) do
|
23
23
|
presence_client_one.leave(data: leave_data) do
|
24
|
-
presence_client_one.history do |
|
25
|
-
expect(
|
24
|
+
presence_client_one.history do |history_page|
|
25
|
+
expect(history_page.items.count).to eql(2)
|
26
26
|
|
27
|
-
expect(
|
28
|
-
expect(
|
29
|
-
expect(
|
27
|
+
expect(history_page.items[1].action).to eq(:enter)
|
28
|
+
expect(history_page.items[1].client_id).to eq(client_one.client_id)
|
29
|
+
expect(history_page.items[1].data).to eql(data)
|
30
30
|
|
31
|
-
expect(
|
32
|
-
expect(
|
33
|
-
expect(
|
31
|
+
expect(history_page.items[0].action).to eq(:leave)
|
32
|
+
expect(history_page.items[0].client_id).to eq(client_one.client_id)
|
33
|
+
expect(history_page.items[0].data).to eql(leave_data)
|
34
34
|
|
35
35
|
stop_reactor
|
36
36
|
end
|
@@ -40,16 +40,59 @@ describe Ably::Realtime::Presence, 'history', :event_machine do
|
|
40
40
|
|
41
41
|
it 'ensures REST presence history message IDs match ProtocolMessage wrapped message and connection IDs via Realtime' do
|
42
42
|
presence_client_one.subscribe(:enter) do |message|
|
43
|
-
presence_client_one.history do |
|
44
|
-
expect(
|
43
|
+
presence_client_one.history do |history_page|
|
44
|
+
expect(history_page.items.count).to eql(1)
|
45
45
|
|
46
|
-
expect(
|
47
|
-
expect(
|
46
|
+
expect(history_page.items[0].id).to eql(message.id)
|
47
|
+
expect(history_page.items[0].connection_id).to eql(message.connection_id)
|
48
48
|
stop_reactor
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
presence_client_one.enter(data: data)
|
53
53
|
end
|
54
|
+
|
55
|
+
context 'with option until_attach: true' do
|
56
|
+
let(:event) { random_str }
|
57
|
+
let(:presence_data_before_attach) { random_str }
|
58
|
+
let(:presence_data_after_attach) { random_str }
|
59
|
+
|
60
|
+
it 'retrieves all presence messages before channel was attached' do
|
61
|
+
presence_client_two.enter(data: presence_data_before_attach) do
|
62
|
+
presence_client_one.enter(data: presence_data_after_attach) do
|
63
|
+
presence_client_one.history(until_attach: true) do |presence_page|
|
64
|
+
expect(presence_page.items.count).to eql(1)
|
65
|
+
expect(presence_page.items.first.data).to eql(presence_data_before_attach)
|
66
|
+
stop_reactor
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'and two pages of messages' do
|
73
|
+
it 'retrieves two pages of messages before channel was attached' do
|
74
|
+
when_all(*10.times.map { |i| presence_client_two.enter_client("client:#{i}", data: presence_data_before_attach) }) do
|
75
|
+
when_all(*10.times.map { |i| presence_client_one.enter_client("client:#{i}", data: presence_data_after_attach) }) do
|
76
|
+
presence_client_one.history(until_attach: true, limit: 5) do |presence_page|
|
77
|
+
expect(presence_page.items.count).to eql(5)
|
78
|
+
expect(presence_page.items.map(&:data).uniq.first).to eql(presence_data_before_attach)
|
79
|
+
|
80
|
+
presence_page.next do |presence_next_page|
|
81
|
+
expect(presence_next_page.items.count).to eql(5)
|
82
|
+
expect(presence_next_page.items.map(&:data).uniq.first).to eql(presence_data_before_attach)
|
83
|
+
expect(presence_next_page).to be_last
|
84
|
+
stop_reactor
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'raises an exception unless state is attached' do
|
93
|
+
expect { presence_client_one.history(until_attach: true) }.to raise_error(ArgumentError, /not attached/)
|
94
|
+
stop_reactor
|
95
|
+
end
|
96
|
+
end
|
54
97
|
end
|
55
98
|
end
|
@@ -5,7 +5,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
5
5
|
include Ably::Modules::Conversions
|
6
6
|
|
7
7
|
vary_by_protocol do
|
8
|
-
let(:default_options) { {
|
8
|
+
let(:default_options) { { key: api_key, environment: environment, protocol: protocol } }
|
9
9
|
let(:client_options) { default_options }
|
10
10
|
|
11
11
|
let(:anonymous_client) { Ably::Realtime::Client.new(client_options) }
|
@@ -487,7 +487,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
487
487
|
|
488
488
|
context 'without necessary capabilities to join presence' do
|
489
489
|
let(:restricted_client) do
|
490
|
-
Ably::Realtime::Client.new(default_options.merge(
|
490
|
+
Ably::Realtime::Client.new(default_options.merge(key: restricted_api_key, log_level: :fatal))
|
491
491
|
end
|
492
492
|
let(:restricted_channel) { restricted_client.channel("cansubscribe:channel") }
|
493
493
|
let(:restricted_presence) { restricted_channel.presence }
|
@@ -688,7 +688,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
688
688
|
|
689
689
|
context 'without necessary capabilities to enter on behalf of another client' do
|
690
690
|
let(:restricted_client) do
|
691
|
-
Ably::Realtime::Client.new(default_options.merge(
|
691
|
+
Ably::Realtime::Client.new(default_options.merge(key: restricted_api_key, log_level: :fatal))
|
692
692
|
end
|
693
693
|
let(:restricted_channel) { restricted_client.channel("cansubscribe:channel") }
|
694
694
|
let(:restricted_presence) { restricted_channel.presence }
|
@@ -1123,8 +1123,8 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1123
1123
|
context 'REST #get' do
|
1124
1124
|
it 'returns current members' do
|
1125
1125
|
presence_client_one.enter(data: data_payload) do
|
1126
|
-
|
1127
|
-
this_member =
|
1126
|
+
members_page = channel_rest_client_one.presence.get
|
1127
|
+
this_member = members_page.items.first
|
1128
1128
|
|
1129
1129
|
expect(this_member).to be_a(Ably::Models::PresenceMessage)
|
1130
1130
|
expect(this_member.client_id).to eql(client_one.client_id)
|
@@ -1137,8 +1137,8 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1137
1137
|
it 'returns no members once left' do
|
1138
1138
|
presence_client_one.enter(data: data_payload) do
|
1139
1139
|
presence_client_one.leave do
|
1140
|
-
|
1141
|
-
expect(
|
1140
|
+
members_page = channel_rest_client_one.presence.get
|
1141
|
+
expect(members_page.items.count).to eql(0)
|
1142
1142
|
stop_reactor
|
1143
1143
|
end
|
1144
1144
|
end
|
@@ -1264,7 +1264,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1264
1264
|
context 'REST #get' do
|
1265
1265
|
it 'returns a list of members with decrypted data' do
|
1266
1266
|
encrypted_channel.presence.enter(data: data) do
|
1267
|
-
member = channel_rest_client_one.presence.get.first
|
1267
|
+
member = channel_rest_client_one.presence.get.items.first
|
1268
1268
|
expect(member.encoding).to be_nil
|
1269
1269
|
expect(member.data).to eql(data)
|
1270
1270
|
stop_reactor
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Ably::Realtime::Client, '#stats', :event_machine do
|
4
4
|
vary_by_protocol do
|
5
5
|
let(:client) do
|
6
|
-
Ably::Realtime::Client.new(
|
6
|
+
Ably::Realtime::Client.new(key: api_key, environment: environment, protocol: protocol)
|
7
7
|
end
|
8
8
|
|
9
9
|
describe 'fetching stats' do
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Ably::Realtime::Client, '#time', :event_machine do
|
4
4
|
vary_by_protocol do
|
5
5
|
let(:client) do
|
6
|
-
Ably::Realtime::Client.new(
|
6
|
+
Ably::Realtime::Client.new(key: api_key, environment: environment, protocol: protocol)
|
7
7
|
end
|
8
8
|
|
9
9
|
describe 'fetching the service time' do
|
@@ -23,7 +23,7 @@ describe Ably::Auth do
|
|
23
23
|
|
24
24
|
vary_by_protocol do
|
25
25
|
let(:client) do
|
26
|
-
Ably::Rest::Client.new(
|
26
|
+
Ably::Rest::Client.new(key: api_key, environment: environment, protocol: protocol)
|
27
27
|
end
|
28
28
|
let(:auth) { client.auth }
|
29
29
|
let(:content_type) do
|
@@ -349,6 +349,15 @@ describe Ably::Auth do
|
|
349
349
|
end
|
350
350
|
end
|
351
351
|
end
|
352
|
+
|
353
|
+
context 'with client_id' do
|
354
|
+
let(:client_id) { random_str }
|
355
|
+
let(:token) { auth.request_token(client_id: client_id) }
|
356
|
+
|
357
|
+
it 'returns a token with the client_id' do
|
358
|
+
expect(token.client_id).to eql(client_id)
|
359
|
+
end
|
360
|
+
end
|
352
361
|
end
|
353
362
|
|
354
363
|
context 'before #authorise has been called' do
|
@@ -587,7 +596,7 @@ describe Ably::Auth do
|
|
587
596
|
context 'when implicit as a result of using :client id' do
|
588
597
|
let(:client_id) { '999' }
|
589
598
|
let(:client) do
|
590
|
-
Ably::Rest::Client.new(
|
599
|
+
Ably::Rest::Client.new(key: api_key, client_id: client_id, environment: environment, protocol: protocol)
|
591
600
|
end
|
592
601
|
let(:token_id) { 'unique-token-id' }
|
593
602
|
let(:token_response) do
|
@@ -632,7 +641,7 @@ describe Ably::Auth do
|
|
632
641
|
expect(token).to be_a(Ably::Models::Token)
|
633
642
|
capability_with_str_key = Ably::Models::Token::DEFAULTS[:capability]
|
634
643
|
capability = Hash[capability_with_str_key.keys.map(&:to_sym).zip(capability_with_str_key.values)]
|
635
|
-
expect(token.capability).to eq(capability)
|
644
|
+
expect(token.capability).to eq(JSON.dump(capability))
|
636
645
|
expect(token.expires_at.to_i).to be_within(2).of(Time.now.to_i + Ably::Models::Token::DEFAULTS[:ttl])
|
637
646
|
expect(token.client_id).to eq(client_id)
|
638
647
|
end
|
@@ -640,14 +649,32 @@ describe Ably::Auth do
|
|
640
649
|
end
|
641
650
|
end
|
642
651
|
|
643
|
-
context 'when using an :
|
652
|
+
context 'when using an :key and basic auth' do
|
644
653
|
specify '#using_token_auth? is false' do
|
645
654
|
expect(auth).to_not be_using_token_auth
|
646
655
|
end
|
647
656
|
|
657
|
+
specify '#key attribute contains the key string' do
|
658
|
+
expect(auth.key).to eql(api_key)
|
659
|
+
end
|
660
|
+
|
648
661
|
specify '#using_basic_auth? is true' do
|
649
662
|
expect(auth).to be_using_basic_auth
|
650
663
|
end
|
651
664
|
end
|
665
|
+
|
666
|
+
context 'when using legacy :api_key option and basic auth' do
|
667
|
+
let(:client) do
|
668
|
+
Ably::Rest::Client.new(api_key: api_key, environment: environment, protocol: protocol)
|
669
|
+
end
|
670
|
+
|
671
|
+
specify '#using_token_auth? is false' do
|
672
|
+
expect(auth).to_not be_using_token_auth
|
673
|
+
end
|
674
|
+
|
675
|
+
specify '#key attribute contains the key string' do
|
676
|
+
expect(auth.key).to eql(api_key)
|
677
|
+
end
|
678
|
+
end
|
652
679
|
end
|
653
680
|
end
|
@@ -7,7 +7,7 @@ describe Ably::Rest do
|
|
7
7
|
|
8
8
|
let(:client_options) { {} }
|
9
9
|
let(:client) do
|
10
|
-
Ably::Rest::Client.new(client_options.merge(
|
10
|
+
Ably::Rest::Client.new(client_options.merge(key: 'appid.keyuid:keysecret'))
|
11
11
|
end
|
12
12
|
|
13
13
|
let(:now) { Time.now - 1000 }
|
@@ -67,13 +67,13 @@ describe Ably::Rest do
|
|
67
67
|
|
68
68
|
vary_by_protocol do
|
69
69
|
let(:client) do
|
70
|
-
Ably::Rest::Client.new(
|
70
|
+
Ably::Rest::Client.new(key: api_key, environment: environment, protocol: protocol)
|
71
71
|
end
|
72
72
|
|
73
73
|
describe 'failed requests' do
|
74
74
|
context 'due to invalid Auth' do
|
75
75
|
it 'should raise an InvalidRequest exception with a valid error message and code' do
|
76
|
-
invalid_client = Ably::Rest::Client.new(
|
76
|
+
invalid_client = Ably::Rest::Client.new(key: 'appid.keyuid:keysecret', environment: environment)
|
77
77
|
expect { invalid_client.channel('test').publish('foo', 'choo') }.to raise_error do |error|
|
78
78
|
expect(error).to be_a(Ably::Exceptions::InvalidRequest)
|
79
79
|
expect(error.message).to match(/invalid credentials/)
|
@@ -6,7 +6,7 @@ describe Ably::Rest::Channel do
|
|
6
6
|
|
7
7
|
vary_by_protocol do
|
8
8
|
let(:client) do
|
9
|
-
Ably::Rest::Client.new(
|
9
|
+
Ably::Rest::Client.new(key: api_key, environment: environment, protocol: protocol)
|
10
10
|
end
|
11
11
|
|
12
12
|
describe '#publish' do
|
@@ -14,7 +14,7 @@ describe Ably::Rest::Channel do
|
|
14
14
|
let(:event) { 'foo' }
|
15
15
|
let(:message) { 'woop!' }
|
16
16
|
|
17
|
-
it 'should publish the message
|
17
|
+
it 'should publish the message and return true indicating success' do
|
18
18
|
expect(channel.publish(event, message)).to eql(true)
|
19
19
|
end
|
20
20
|
end
|
@@ -37,20 +37,20 @@ describe Ably::Rest::Channel do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'should return the current message history for the channel' do
|
40
|
-
|
40
|
+
actual_history_items = channel.history.items
|
41
41
|
|
42
|
-
expect(
|
42
|
+
expect(actual_history_items.size).to eql(3)
|
43
43
|
|
44
44
|
expected_history.each do |message|
|
45
45
|
message_name, message_data = message[:name], message[:data]
|
46
|
-
matching_message =
|
46
|
+
matching_message = actual_history_items.find { |message| message.name == message_name && message.data == message_data }
|
47
47
|
expect(matching_message).to be_a(Ably::Models::Message)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
context 'message timestamps' do
|
52
52
|
it 'should all be after the messages were published' do
|
53
|
-
channel.history.each do |message|
|
53
|
+
channel.history.items.each do |message|
|
54
54
|
expect(before_published.to_f).to be < message.timestamp.to_f
|
55
55
|
end
|
56
56
|
end
|
@@ -58,7 +58,7 @@ describe Ably::Rest::Channel do
|
|
58
58
|
|
59
59
|
context 'message IDs' do
|
60
60
|
it 'should be unique' do
|
61
|
-
message_ids = channel.history.map(&:id).compact
|
61
|
+
message_ids = channel.history.items.map(&:id).compact
|
62
62
|
expect(message_ids.count).to eql(3)
|
63
63
|
expect(message_ids.uniq.count).to eql(3)
|
64
64
|
end
|
@@ -66,25 +66,25 @@ describe Ably::Rest::Channel do
|
|
66
66
|
|
67
67
|
it 'should return paged history using the PaginatedResource model' do
|
68
68
|
page_1 = channel.history(limit: 1)
|
69
|
-
page_2 = page_1.
|
70
|
-
page_3 = page_2.
|
69
|
+
page_2 = page_1.next
|
70
|
+
page_3 = page_2.next
|
71
71
|
|
72
|
-
all_items = [page_1[0].id, page_2[0].id, page_3[0].id]
|
72
|
+
all_items = [page_1.items[0].id, page_2.items[0].id, page_3.items[0].id]
|
73
73
|
expect(all_items.uniq).to eql(all_items)
|
74
74
|
|
75
|
-
expect(page_1.size).to eql(1)
|
76
|
-
expect(page_1).to_not
|
77
|
-
expect(page_1).to
|
75
|
+
expect(page_1.items.size).to eql(1)
|
76
|
+
expect(page_1).to_not be_last
|
77
|
+
expect(page_1).to be_first
|
78
78
|
|
79
79
|
# Page 2
|
80
|
-
expect(page_2.size).to eql(1)
|
81
|
-
expect(page_2).to_not
|
82
|
-
expect(page_2).to_not
|
80
|
+
expect(page_2.items.size).to eql(1)
|
81
|
+
expect(page_2).to_not be_last
|
82
|
+
expect(page_2).to_not be_first
|
83
83
|
|
84
84
|
# Page 3
|
85
|
-
expect(page_3.size).to eql(1)
|
86
|
-
expect(page_3).to
|
87
|
-
expect(page_3).to_not
|
85
|
+
expect(page_3.items.size).to eql(1)
|
86
|
+
expect(page_3).to be_last
|
87
|
+
expect(page_3).to_not be_first
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|