ably-rest 0.8.1 → 0.8.2
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/CHANGELOG.md +45 -0
- data/LICENSE +15 -0
- data/README.md +14 -1
- data/lib/submodules/ably-ruby/CHANGELOG.md +45 -0
- data/lib/submodules/ably-ruby/LICENSE +15 -0
- data/lib/submodules/ably-ruby/README.md +18 -14
- data/lib/submodules/ably-ruby/SPEC.md +482 -336
- data/lib/submodules/ably-ruby/ably.gemspec +1 -1
- data/lib/submodules/ably-ruby/lib/ably.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/exceptions.rb +4 -1
- data/lib/submodules/ably-ruby/lib/ably/models/{paginated_resource.rb → paginated_result.rb} +8 -8
- data/lib/submodules/ably-ruby/lib/ably/models/presence_message.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/modules/conversions.rb +15 -0
- data/lib/submodules/ably-ruby/lib/ably/modules/encodeable.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/modules/event_emitter.rb +8 -8
- data/lib/submodules/ably-ruby/lib/ably/modules/safe_deferrable.rb +15 -3
- data/lib/submodules/ably-ruby/lib/ably/modules/state_emitter.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/modules/state_machine.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/realtime/channel.rb +2 -4
- data/lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/realtime/client.rb +4 -4
- data/lib/submodules/ably-ruby/lib/ably/realtime/client/incoming_message_dispatcher.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/realtime/connection.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/realtime/connection/connection_manager.rb +3 -3
- data/lib/submodules/ably-ruby/lib/ably/realtime/connection/connection_state_machine.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/realtime/connection/websocket_transport.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/realtime/presence.rb +23 -5
- data/lib/submodules/ably-ruby/lib/ably/realtime/presence/members_map.rb +16 -13
- data/lib/submodules/ably-ruby/lib/ably/rest/channel.rb +3 -2
- data/lib/submodules/ably-ruby/lib/ably/rest/client.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/rest/presence.rb +4 -4
- data/lib/submodules/ably-ruby/lib/ably/util/pub_sub.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/util/safe_deferrable.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/version.rb +1 -1
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_history_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_spec.rb +5 -15
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_failures_spec.rb +2 -2
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_spec.rb +16 -14
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/message_spec.rb +91 -8
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_spec.rb +190 -71
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/stats_spec.rb +2 -2
- data/lib/submodules/ably-ruby/spec/acceptance/rest/channel_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/acceptance/rest/encoders_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/acceptance/rest/message_spec.rb +73 -1
- data/lib/submodules/ably-ruby/spec/acceptance/rest/presence_spec.rb +4 -2
- data/lib/submodules/ably-ruby/spec/unit/models/{paginated_resource_spec.rb → paginated_result_spec.rb} +18 -18
- data/lib/submodules/ably-ruby/spec/unit/modules/event_emitter_spec.rb +27 -27
- data/lib/submodules/ably-ruby/spec/unit/modules/state_emitter_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/unit/realtime/channel_spec.rb +2 -2
- data/lib/submodules/ably-ruby/spec/unit/realtime/connection_spec.rb +3 -3
- data/lib/submodules/ably-ruby/spec/unit/realtime/presence_spec.rb +2 -2
- metadata +35 -33
- data/LICENSE.txt +0 -22
- data/lib/submodules/ably-ruby/LICENSE.txt +0 -22
@@ -26,10 +26,6 @@ module Ably::Realtime
|
|
26
26
|
)
|
27
27
|
include Ably::Modules::StateEmitter
|
28
28
|
|
29
|
-
# Number of absent members to cache internally whilst channel is in sync.
|
30
|
-
# Cache is unlimited until initial sync is complete ensuring users who have left are never reported as present.
|
31
|
-
MAX_ABSENT_MEMBER_CACHE = 100
|
32
|
-
|
33
29
|
def initialize(presence)
|
34
30
|
@presence = presence
|
35
31
|
|
@@ -66,14 +62,14 @@ module Ably::Realtime
|
|
66
62
|
# @param [Hash,String] options an options Hash to filter members
|
67
63
|
# @option options [String] :client_id optional client_id for the member
|
68
64
|
# @option options [String] :connection_id optional connection_id for the member
|
69
|
-
# @option options [String] :wait_for_sync defaults to
|
65
|
+
# @option options [String] :wait_for_sync defaults to false, if true the get method waits for the initial presence sync following channel attachment to complete before returning the members present
|
70
66
|
#
|
71
67
|
# @yield [Array<Ably::Models::PresenceMessage>] array of present members
|
72
68
|
#
|
73
69
|
# @return [Ably::Util::SafeDeferrable] Deferrable that supports both success (callback) and failure (errback) callbacks
|
74
70
|
#
|
75
71
|
def get(options = {}, &block)
|
76
|
-
wait_for_sync = options.fetch(:wait_for_sync,
|
72
|
+
wait_for_sync = options.fetch(:wait_for_sync, false)
|
77
73
|
deferrable = Ably::Util::SafeDeferrable.new(logger)
|
78
74
|
|
79
75
|
result_block = proc do
|
@@ -164,6 +160,10 @@ module Ably::Realtime
|
|
164
160
|
once(:in_sync, :failed) do
|
165
161
|
connection.off_resume &resume_sync_proc
|
166
162
|
end
|
163
|
+
|
164
|
+
once(:in_sync) do
|
165
|
+
clean_up_absent_members
|
166
|
+
end
|
167
167
|
end
|
168
168
|
|
169
169
|
# Trigger a manual SYNC operation to resume member synchronisation from last known cursor position
|
@@ -198,8 +198,6 @@ module Ably::Realtime
|
|
198
198
|
else
|
199
199
|
Ably::Exceptions::ProtocolError.new("Protocol error, unknown presence action #{presence_message.action}", 400, 80013)
|
200
200
|
end
|
201
|
-
|
202
|
-
clean_up_absent_members
|
203
201
|
end
|
204
202
|
|
205
203
|
def ensure_presence_message_is_valid(presence_message)
|
@@ -207,7 +205,7 @@ module Ably::Realtime
|
|
207
205
|
|
208
206
|
error = Ably::Exceptions::ProtocolError.new("Protocol error, presence message is missing connectionId", 400, 80013)
|
209
207
|
logger.error "PresenceMap: On channel '#{channel.name}' error: #{error}"
|
210
|
-
channel.
|
208
|
+
channel.emit :error, error
|
211
209
|
end
|
212
210
|
|
213
211
|
# If the message received is older than the last known event for presence
|
@@ -234,8 +232,14 @@ module Ably::Realtime
|
|
234
232
|
|
235
233
|
def remove_presence_member(presence_message)
|
236
234
|
logger.debug "#{self.class.name}: Member '#{presence_message.member_key}' removed.\n#{presence_message.to_json}"
|
237
|
-
|
238
|
-
|
235
|
+
|
236
|
+
if in_sync?
|
237
|
+
members.delete presence_message.member_key
|
238
|
+
else
|
239
|
+
members[presence_message.member_key] = { present: false, message: presence_message }
|
240
|
+
absent_member_cleanup_queue << presence_message.member_key
|
241
|
+
end
|
242
|
+
|
239
243
|
presence.emit_message presence_message.action, presence_message
|
240
244
|
end
|
241
245
|
|
@@ -256,8 +260,7 @@ module Ably::Realtime
|
|
256
260
|
end
|
257
261
|
|
258
262
|
def clean_up_absent_members
|
259
|
-
|
260
|
-
members.delete absent_member_cleanup_queue.shift until absent_member_cleanup_queue.count <= MAX_ABSENT_MEMBER_CACHE
|
263
|
+
members.delete absent_member_cleanup_queue.shift
|
261
264
|
end
|
262
265
|
end
|
263
266
|
end
|
@@ -37,6 +37,7 @@ module Ably
|
|
37
37
|
# @return [Boolean] true if the message was published, otherwise false
|
38
38
|
def publish(name, data)
|
39
39
|
ensure_utf_8 :name, name
|
40
|
+
ensure_supported_payload data
|
40
41
|
|
41
42
|
payload = {
|
42
43
|
name: name,
|
@@ -60,7 +61,7 @@ module Ably
|
|
60
61
|
# @option options [Symbol] :direction +:forwards+ or +:backwards+, defaults to +:backwards+
|
61
62
|
# @option options [Integer] :limit Maximum number of messages to retrieve up to 1,000, defaults to 100
|
62
63
|
#
|
63
|
-
# @return [Ably::Models::
|
64
|
+
# @return [Ably::Models::PaginatedResult<Ably::Models::Message>] First {Ably::Models::PaginatedResult page} of {Ably::Models::Message} objects accessible with {Ably::Models::PaginatedResult#items #items}.
|
64
65
|
#
|
65
66
|
def history(options = {})
|
66
67
|
url = "#{base_path}/messages"
|
@@ -78,7 +79,7 @@ module Ably
|
|
78
79
|
|
79
80
|
response = client.get(url, options)
|
80
81
|
|
81
|
-
Ably::Models::
|
82
|
+
Ably::Models::PaginatedResult.new(response, url, client, paginated_options) do |message|
|
82
83
|
message.tap do |message|
|
83
84
|
decode_message message
|
84
85
|
end
|
@@ -150,7 +150,7 @@ module Ably
|
|
150
150
|
# @option options [Integer] :limit Maximum number of messages to retrieve up to 1,000, defaults to 100
|
151
151
|
# @option options [Symbol] :unit `:minute`, `:hour`, `:day` or `:month`. Defaults to `:minute`
|
152
152
|
#
|
153
|
-
# @return [Ably::Models::
|
153
|
+
# @return [Ably::Models::PaginatedResult<Ably::Models::Stats>] An Array of Stats
|
154
154
|
#
|
155
155
|
def stats(options = {})
|
156
156
|
options = {
|
@@ -168,7 +168,7 @@ module Ably
|
|
168
168
|
url = '/stats'
|
169
169
|
response = get(url, options)
|
170
170
|
|
171
|
-
Ably::Models::
|
171
|
+
Ably::Models::PaginatedResult.new(response, url, self, paginated_options)
|
172
172
|
end
|
173
173
|
|
174
174
|
# Retrieve the Ably service time
|
@@ -25,7 +25,7 @@ module Ably
|
|
25
25
|
# @param [Hash] options the options for the set of members present
|
26
26
|
# @option options [Integer] :limit Maximum number of members to retrieve up to 1,000, defaults to 100
|
27
27
|
#
|
28
|
-
# @return [Ably::Models::
|
28
|
+
# @return [Ably::Models::PaginatedResult<Ably::Models::PresenceMessage>] First {Ably::Models::PaginatedResult page} of {Ably::Models::PresenceMessage} objects accessible with {Ably::Models::PaginatedResult#items #items}.
|
29
29
|
#
|
30
30
|
def get(options = {})
|
31
31
|
options = options = {
|
@@ -39,7 +39,7 @@ module Ably
|
|
39
39
|
|
40
40
|
response = client.get(base_path, options)
|
41
41
|
|
42
|
-
Ably::Models::
|
42
|
+
Ably::Models::PaginatedResult.new(response, base_path, client, paginated_options) do |presence_message|
|
43
43
|
presence_message.tap do |presence_message|
|
44
44
|
decode_message presence_message
|
45
45
|
end
|
@@ -54,7 +54,7 @@ module Ably
|
|
54
54
|
# @option options [Symbol] :direction +:forwards+ or +:backwards+, defaults to +:backwards+
|
55
55
|
# @option options [Integer] :limit Maximum number of messages to retrieve up to 1,000, defaults to 100
|
56
56
|
#
|
57
|
-
# @return [Ably::Models::
|
57
|
+
# @return [Ably::Models::PaginatedResult<Ably::Models::PresenceMessage>] First {Ably::Models::PaginatedResult page} of {Ably::Models::PresenceMessage} objects accessible with {Ably::Models::PaginatedResult#items #items}.
|
58
58
|
#
|
59
59
|
def history(options = {})
|
60
60
|
url = "#{base_path}/history"
|
@@ -72,7 +72,7 @@ module Ably
|
|
72
72
|
|
73
73
|
response = client.get(url, options)
|
74
74
|
|
75
|
-
Ably::Models::
|
75
|
+
Ably::Models::PaginatedResult.new(response, url, client, paginated_options) do |presence_message|
|
76
76
|
presence_message.tap do |presence_message|
|
77
77
|
decode_message presence_message
|
78
78
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Ably::Util
|
2
2
|
# SafeDeferrable class provides a Deferrable that is safe to use for for public interfaces
|
3
|
-
# of this client library. Any exceptions raised in the success or failure callbacks
|
3
|
+
# of this client library. Any exceptions raised in the success or failure callbacks are
|
4
4
|
# caught and logged to the provided logger.
|
5
5
|
#
|
6
6
|
# An exception in a callback provided by a developer should not break this client library
|
@@ -24,7 +24,7 @@ describe Ably::Realtime::Channel, '#history', :event_machine do
|
|
24
24
|
expect(history).to be_a(Ably::Util::SafeDeferrable)
|
25
25
|
history.callback do |page|
|
26
26
|
expect(page.items.count).to eql(1)
|
27
|
-
expect(page).to be_a(Ably::Models::
|
27
|
+
expect(page).to be_a(Ably::Models::PaginatedResult)
|
28
28
|
stop_reactor
|
29
29
|
end
|
30
30
|
end
|
@@ -13,9 +13,9 @@ describe Ably::Realtime::Channel, :event_machine do
|
|
13
13
|
let(:messages) { [] }
|
14
14
|
|
15
15
|
describe 'initialization' do
|
16
|
-
context 'with :
|
16
|
+
context 'with :auto_connect option set to false on connection' do
|
17
17
|
let(:client) do
|
18
|
-
Ably::Realtime::Client.new(default_options.merge(
|
18
|
+
Ably::Realtime::Client.new(default_options.merge(auto_connect: false))
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'remains initialized when accessing a channel' do
|
@@ -32,16 +32,6 @@ describe Ably::Realtime::Channel, :event_machine do
|
|
32
32
|
stop_reactor
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
36
|
-
it 'opens a connection implicitly when accessing #presence' do
|
37
|
-
client.channel('test').tap do |channel|
|
38
|
-
channel.on(:attached) do
|
39
|
-
expect(client.connection).to be_connected
|
40
|
-
stop_reactor
|
41
|
-
end
|
42
|
-
channel.presence
|
43
|
-
end
|
44
|
-
end
|
45
35
|
end
|
46
36
|
end
|
47
37
|
|
@@ -162,7 +152,7 @@ describe Ably::Realtime::Channel, :event_machine do
|
|
162
152
|
end
|
163
153
|
let(:restricted_channel) { restricted_client.channel("cannot_subscribe") }
|
164
154
|
|
165
|
-
it '
|
155
|
+
it 'emits failed event' do
|
166
156
|
restricted_channel.attach
|
167
157
|
restricted_channel.on(:failed) do |error|
|
168
158
|
expect(restricted_channel.state).to eq(:failed)
|
@@ -179,7 +169,7 @@ describe Ably::Realtime::Channel, :event_machine do
|
|
179
169
|
end
|
180
170
|
end
|
181
171
|
|
182
|
-
it '
|
172
|
+
it 'emits an error event' do
|
183
173
|
restricted_channel.attach
|
184
174
|
restricted_channel.on(:error) do |error|
|
185
175
|
expect(restricted_channel.state).to eq(:failed)
|
@@ -458,7 +448,7 @@ describe Ably::Realtime::Channel, :event_machine do
|
|
458
448
|
end
|
459
449
|
end
|
460
450
|
|
461
|
-
it '
|
451
|
+
it 'emits an error event on the channel' do
|
462
452
|
channel.attach do
|
463
453
|
channel.on(:error) do |error|
|
464
454
|
expect(error).to eql(connection_error)
|
@@ -319,7 +319,7 @@ describe Ably::Realtime::Connection, 'failures', :event_machine do
|
|
319
319
|
disconnected: { retry_every: retry_every, max_time_in_state: 60 })
|
320
320
|
end
|
321
321
|
|
322
|
-
it "retries every CONNECT_RETRY_CONFIG[:disconnected][:retry_every] seconds" do
|
322
|
+
it "retries every #{Ably::Realtime::Connection::ConnectionManager::CONNECT_RETRY_CONFIG[:disconnected][:retry_every]} seconds" do
|
323
323
|
fail_if_suspended_or_failed
|
324
324
|
|
325
325
|
stubbed_first_attempt = false
|
@@ -415,7 +415,7 @@ describe Ably::Realtime::Connection, 'failures', :event_machine do
|
|
415
415
|
end
|
416
416
|
end
|
417
417
|
|
418
|
-
it '
|
418
|
+
it 'executes the resume callback', api_private: true do
|
419
419
|
channel.attach do
|
420
420
|
connection.transport.close_connection_after_writing
|
421
421
|
connection.on_resume do
|
@@ -27,9 +27,9 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
context 'with :
|
30
|
+
context 'with :auto_connect option set to false' do
|
31
31
|
let(:client) do
|
32
|
-
Ably::Realtime::Client.new(default_options.merge(
|
32
|
+
Ably::Realtime::Client.new(default_options.merge(auto_connect: false))
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'does not connect automatically' do
|
@@ -201,10 +201,10 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
201
201
|
|
202
202
|
context 'initialization state changes' do
|
203
203
|
let(:phases) { [:connecting, :connected] }
|
204
|
-
let(:
|
204
|
+
let(:events_emitted) { [] }
|
205
205
|
let(:test_expectation) do
|
206
206
|
Proc.new do
|
207
|
-
expect(
|
207
|
+
expect(events_emitted).to eq(phases)
|
208
208
|
stop_reactor
|
209
209
|
end
|
210
210
|
end
|
@@ -212,20 +212,20 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
212
212
|
def expect_ordered_phases
|
213
213
|
phases.each do |phase|
|
214
214
|
connection.on(phase) do
|
215
|
-
|
216
|
-
test_expectation.call if
|
215
|
+
events_emitted << phase
|
216
|
+
test_expectation.call if events_emitted.length == phases.length
|
217
217
|
end
|
218
218
|
end
|
219
219
|
end
|
220
220
|
|
221
221
|
context 'with implicit #connect' do
|
222
|
-
it 'are
|
222
|
+
it 'are emitted in order' do
|
223
223
|
expect_ordered_phases
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
227
227
|
context 'with explicit #connect' do
|
228
|
-
it 'are
|
228
|
+
it 'are emitted in order' do
|
229
229
|
expect_ordered_phases
|
230
230
|
connection.connect
|
231
231
|
end
|
@@ -542,10 +542,10 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
542
542
|
let(:states) { Hash.new }
|
543
543
|
let(:client_options) { default_options.merge(log_level: :none) }
|
544
544
|
|
545
|
-
it 'is composed of connection
|
545
|
+
it 'is composed of connection key and serial that is kept up to date with each message ACK received' do
|
546
546
|
connection.on(:connected) do
|
547
547
|
expected_serial = -1
|
548
|
-
expect(connection.
|
548
|
+
expect(connection.key).to_not be_nil
|
549
549
|
expect(connection.serial).to eql(expected_serial)
|
550
550
|
|
551
551
|
client.channel('test').attach do |channel|
|
@@ -556,6 +556,8 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
556
556
|
channel.publish('event', 'data') do
|
557
557
|
expected_serial += 1 # attach message received
|
558
558
|
expect(connection.serial).to eql(expected_serial)
|
559
|
+
|
560
|
+
expect(connection.recovery_key).to eql("#{connection.key}:#{connection.serial}")
|
559
561
|
stop_reactor
|
560
562
|
end
|
561
563
|
end
|
@@ -621,7 +623,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
621
623
|
end
|
622
624
|
end
|
623
625
|
|
624
|
-
it 'does not
|
626
|
+
it 'does not call a resume callback', api_private: true do
|
625
627
|
connection.once(:connected) do
|
626
628
|
connection.transition_state_machine! :failed
|
627
629
|
end
|
@@ -629,7 +631,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
629
631
|
connection.once(:failed) do
|
630
632
|
recover_client = Ably::Realtime::Client.new(default_options.merge(recover: client.connection.recovery_key))
|
631
633
|
recover_client.connection.on_resume do
|
632
|
-
raise 'Should not
|
634
|
+
raise 'Should not call the resume callback'
|
633
635
|
end
|
634
636
|
recover_client.connection.on(:connected) do
|
635
637
|
EventMachine.add_timer(0.5) { stop_reactor }
|
@@ -676,7 +678,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
676
678
|
context 'with invalid formatted value sent to server' do
|
677
679
|
let(:client_options) { default_options.merge(recover: 'not-a-valid-connection-key:1', log_level: :none) }
|
678
680
|
|
679
|
-
it '
|
681
|
+
it 'emits a fatal error on the connection object, sets the #error_reason and disconnects' do
|
680
682
|
connection.once(:error) do |error|
|
681
683
|
expect(connection.state).to eq(:failed)
|
682
684
|
expect(error.message).to match(/Invalid connection key/)
|
@@ -691,7 +693,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
691
693
|
context 'with expired (missing) value sent to server' do
|
692
694
|
let(:client_options) { default_options.merge(recover: '0123456789abcdef:0', log_level: :fatal) }
|
693
695
|
|
694
|
-
it '
|
696
|
+
it 'emits an error on the connection object, sets the #error_reason, yet will connect anyway' do
|
695
697
|
connection.once(:error) do |error|
|
696
698
|
expect(connection.state).to eq(:connected)
|
697
699
|
expect(error.message).to match(/Invalid connection key/i)
|
@@ -32,6 +32,87 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
context 'with supported data payload content type' do
|
36
|
+
def publish_and_check_data(data)
|
37
|
+
channel.attach
|
38
|
+
channel.publish 'event', data
|
39
|
+
channel.subscribe do |message|
|
40
|
+
expect(message.data).to eql(data)
|
41
|
+
stop_reactor
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'JSON Object (Hash)' do
|
46
|
+
let(:data) { { 'Hash' => 'true' } }
|
47
|
+
|
48
|
+
it 'is encoded and decoded to the same hash' do
|
49
|
+
publish_and_check_data data
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'JSON Array' do
|
54
|
+
let(:data) { [ nil, true, false, 55, 'string', { 'Hash' => true }, ['array'] ] }
|
55
|
+
|
56
|
+
it 'is encoded and decoded to the same Array' do
|
57
|
+
publish_and_check_data data
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'String' do
|
62
|
+
let(:data) { random_str }
|
63
|
+
|
64
|
+
it 'is encoded and decoded to the same Array' do
|
65
|
+
publish_and_check_data data
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'Binary' do
|
70
|
+
let(:data) { Base64.encode64(random_str) }
|
71
|
+
|
72
|
+
it 'is encoded and decoded to the same Array' do
|
73
|
+
publish_and_check_data data
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'with unsupported data payload content type' do
|
79
|
+
context 'Integer' do
|
80
|
+
let(:data) { 1 }
|
81
|
+
|
82
|
+
it 'is raises an UnsupportedDataTypeError 40011 exception' do
|
83
|
+
expect { channel.publish 'event', data }.to raise_error(Ably::Exceptions::UnsupportedDataTypeError)
|
84
|
+
stop_reactor
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'Float' do
|
89
|
+
let(:data) { 1.1 }
|
90
|
+
|
91
|
+
it 'is raises an UnsupportedDataTypeError 40011 exception' do
|
92
|
+
expect { channel.publish 'event', data }.to raise_error(Ably::Exceptions::UnsupportedDataTypeError)
|
93
|
+
stop_reactor
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'Boolean' do
|
98
|
+
let(:data) { true }
|
99
|
+
|
100
|
+
it 'is raises an UnsupportedDataTypeError 40011 exception' do
|
101
|
+
expect { channel.publish 'event', data }.to raise_error(Ably::Exceptions::UnsupportedDataTypeError)
|
102
|
+
stop_reactor
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'False' do
|
107
|
+
let(:data) { false }
|
108
|
+
|
109
|
+
it 'is raises an UnsupportedDataTypeError 40011 exception' do
|
110
|
+
expect { channel.publish 'event', data }.to raise_error(Ably::Exceptions::UnsupportedDataTypeError)
|
111
|
+
stop_reactor
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
35
116
|
context 'with ASCII_8BIT message name' do
|
36
117
|
let(:message_name) { random_str.encode(Encoding::ASCII_8BIT) }
|
37
118
|
it 'is converted into UTF_8' do
|
@@ -410,7 +491,7 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
410
491
|
end
|
411
492
|
end
|
412
493
|
|
413
|
-
it '
|
494
|
+
it 'emits a Cipher error on the channel' do
|
414
495
|
unencrypted_channel_client2.attach do
|
415
496
|
encrypted_channel_client1.publish 'example', payload
|
416
497
|
unencrypted_channel_client2.on(:error) do |error|
|
@@ -441,7 +522,7 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
441
522
|
end
|
442
523
|
end
|
443
524
|
|
444
|
-
it '
|
525
|
+
it 'emits a Cipher error on the channel' do
|
445
526
|
encrypted_channel_client2.attach do
|
446
527
|
encrypted_channel_client1.publish 'example', payload
|
447
528
|
encrypted_channel_client2.on(:error) do |error|
|
@@ -464,15 +545,17 @@ describe 'Ably::Realtime::Channel Message', :event_machine do
|
|
464
545
|
let(:payload) { MessagePack.pack({ 'key' => random_str }) }
|
465
546
|
|
466
547
|
it 'delivers the message but still encrypted with the cipher details in the #encoding attribute' do
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
548
|
+
encrypted_channel_client2.attach do
|
549
|
+
encrypted_channel_client1.publish 'example', payload
|
550
|
+
encrypted_channel_client2.subscribe do |message|
|
551
|
+
expect(message.data).to_not eql(payload)
|
552
|
+
expect(message.encoding).to match(/^cipher\+aes-256-cbc/)
|
553
|
+
stop_reactor
|
554
|
+
end
|
472
555
|
end
|
473
556
|
end
|
474
557
|
|
475
|
-
it '
|
558
|
+
it 'emits a Cipher error on the channel' do
|
476
559
|
encrypted_channel_client2.attach do
|
477
560
|
encrypted_channel_client1.publish 'example', payload
|
478
561
|
encrypted_channel_client2.on(:error) do |error|
|