pubnub 3.5.8 → 3.5.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pubnub might be problematic. Click here for more details.

@@ -0,0 +1,1877 @@
1
+ require 'spec_helper'
2
+
3
+ describe '#publish' do
4
+ before(:each) do
5
+ @envelopes = Array.new
6
+ @error_envelopes = Array.new
7
+
8
+ @callback = lambda do |envelope|
9
+ @envelopes << envelope
10
+ end
11
+
12
+ @error_callback = lambda do |envelope|
13
+ @error_envelopes << envelope
14
+ end
15
+ end
16
+
17
+ context 'uses http' do
18
+ context 'with auth_key provided' do
19
+ context 'without encrypting message' do
20
+
21
+ before(:each) do
22
+ @pubnub = Pubnub.new(
23
+ :max_retries => 0,
24
+ :subscribe_key => :demo,
25
+ :publish_key => :demo,
26
+ :auth_key => :demoish_authkey,
27
+ :secret_key => 'some_secret_key',
28
+ :error_callback => @error_callback,
29
+ :disable_persistent_connection => true
30
+ )
31
+
32
+ @pubnub.uuid = 'tester'
33
+ end
34
+
35
+ context 'gets status 200 response' do
36
+ context 'with valid json' do
37
+ context 'its asynchronous' do
38
+ it 'publishes valid message' do
39
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-200-valid', :record => :none) do
40
+
41
+ @pubnub.publish(
42
+ :message => {:text => 'sometext'},
43
+ :channel => 'ruby_demo_channel',
44
+ :callback => @callback
45
+ )
46
+
47
+ eventually do
48
+ @envelopes.size.should eq 1
49
+ @envelopes.first.response_message.should eq 'Sent'
50
+ @envelopes.first.status.should eq 200
51
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
52
+ @envelopes.first.message.should eq({:text => 'sometext'})
53
+ @envelopes.first.timetoken.blank?.should eq false
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+
60
+ context 'its synchronous' do
61
+ it 'publishes valid message' do
62
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-200-valid', :record => :none) do
63
+
64
+ @pubnub.publish(
65
+ :message => {:text => 'sometext'},
66
+ :channel => 'ruby_demo_channel',
67
+ :callback => @callback,
68
+ :http_sync => true
69
+ )
70
+
71
+ @envelopes.size.should eq 1
72
+ @envelopes.first.response_message.should eq 'Sent'
73
+ @envelopes.first.status.should eq 200
74
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
75
+ @envelopes.first.message.should eq({:text => 'sometext'})
76
+ @envelopes.first.timetoken.blank?.should eq false
77
+
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ context 'with invalid json' do
84
+ context 'its asynchronous' do
85
+ it 'handles invalid json gracefully' do
86
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-200-invalid', :record => :none) do
87
+
88
+ @pubnub.publish(
89
+ :message => {:text => 'sometext'},
90
+ :channel => 'ruby_demo_channel',
91
+ :callback => @callback
92
+ )
93
+
94
+ eventually do
95
+ @envelopes.size.should eq 0
96
+ @error_envelopes.size.should eq 1
97
+ @error_envelopes.first.response_message.should eq nil
98
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
99
+ @error_envelopes.first.status.should eq 200
100
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
101
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
102
+ @error_envelopes.first.timetoken.blank?.should eq true
103
+ end
104
+
105
+ end
106
+ end
107
+ end
108
+
109
+ context 'its synchronous' do
110
+ it 'handles invalid json gracefully' do
111
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-200-invalid', :record => :none) do
112
+
113
+ @pubnub.publish(
114
+ :message => {:text => 'sometext'},
115
+ :channel => 'ruby_demo_channel',
116
+ :callback => @callback,
117
+ :http_sync => true
118
+ )
119
+
120
+ @envelopes.size.should eq 0
121
+ @error_envelopes.size.should eq 1
122
+ @error_envelopes.first.response_message.should eq nil
123
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
124
+ @error_envelopes.first.status.should eq 200
125
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
126
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
127
+ @error_envelopes.first.timetoken.blank?.should eq true
128
+
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ context 'gets status non200 response' do
136
+ context 'with valid json' do
137
+ context 'its asynchronous' do
138
+ it 'handles non200 response gracefully' do
139
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-non200-valid', :record => :none) do
140
+
141
+ @pubnub.publish(
142
+ :message => {:text => 'sometext'},
143
+ :channel => 'ruby_demo_channel',
144
+ :callback => @callback
145
+ )
146
+
147
+ eventually do
148
+ @envelopes.size.should eq 0
149
+ @error_envelopes.size.should eq 1
150
+ @error_envelopes.first.response_message.should eq 'Sent'
151
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
152
+ @error_envelopes.first.status.should eq 500
153
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
154
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
155
+ @error_envelopes.first.timetoken.blank?.should eq false
156
+ end
157
+
158
+ end
159
+ end
160
+ end
161
+
162
+ context 'its synchronous' do
163
+ it 'handles non200 response gracefully' do
164
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-non200-valid', :record => :none) do
165
+
166
+ @pubnub.publish(
167
+ :message => {:text => 'sometext'},
168
+ :channel => 'ruby_demo_channel',
169
+ :callback => @callback,
170
+ :http_sync => true
171
+ )
172
+
173
+ @envelopes.size.should eq 0
174
+ @error_envelopes.size.should eq 1
175
+ @error_envelopes.first.response_message.should eq 'Sent'
176
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
177
+ @error_envelopes.first.status.should eq 500
178
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
179
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
180
+ @error_envelopes.first.timetoken.blank?.should eq false
181
+
182
+ end
183
+ end
184
+ end
185
+ end
186
+
187
+ context 'with invalid json' do
188
+ context 'its asynchronous' do
189
+ it 'handles invalid json and non200 response gracefully' do
190
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-non200-invalid', :record => :none) do
191
+
192
+ @pubnub.publish(
193
+ :message => {:text => 'sometext'},
194
+ :channel => 'ruby_demo_channel',
195
+ :callback => @callback
196
+ )
197
+
198
+ eventually do
199
+ @envelopes.size.should eq 0
200
+ @error_envelopes.size.should eq 1
201
+ @error_envelopes.first.response_message.should eq nil
202
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
203
+ @error_envelopes.first.status.should eq 500
204
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
205
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
206
+ @error_envelopes.first.timetoken.blank?.should eq true
207
+ end
208
+
209
+ end
210
+ end
211
+ end
212
+
213
+ context 'its synchronous' do
214
+ it 'handles invalid json and non200 response gracefully' do
215
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-non200-invalid', :record => :none) do
216
+
217
+ @pubnub.publish(
218
+ :message => {:text => 'sometext'},
219
+ :channel => 'ruby_demo_channel',
220
+ :callback => @callback,
221
+ :http_sync => true
222
+ )
223
+
224
+ @envelopes.size.should eq 0
225
+ @error_envelopes.size.should eq 1
226
+ @error_envelopes.first.response_message.should eq nil
227
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
228
+ @error_envelopes.first.status.should eq 500
229
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
230
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
231
+ @error_envelopes.first.timetoken.blank?.should eq true
232
+
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end
238
+ end
239
+
240
+ context 'with encrypting message' do
241
+
242
+ before(:each) do
243
+ @pubnub = Pubnub.new(
244
+ :max_retries => 0,
245
+ :subscribe_key => :demo,
246
+ :publish_key => :demo,
247
+ :auth_key => :demoish_authkey,
248
+ :secret_key => 'some_secret_key',
249
+ :cipher_key => 'secret',
250
+ :error_callback => @error_callback,
251
+ :disable_persistent_connection => true
252
+ )
253
+
254
+ @pubnub.uuid = 'tester'
255
+ end
256
+
257
+ context 'gets status 200 response' do
258
+ context 'with valid json' do
259
+ context 'its asynchronous' do
260
+ it 'publishes valid message' do
261
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-200-valid', :record => :none) do
262
+
263
+ @pubnub.publish(
264
+ :message => {:text => 'sometext'},
265
+ :channel => 'ruby_demo_channel',
266
+ :callback => @callback
267
+ )
268
+
269
+ eventually do
270
+ @envelopes.size.should eq 1
271
+ @envelopes.first.response_message.should eq 'Sent'
272
+ @envelopes.first.status.should eq 200
273
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
274
+ @envelopes.first.message.should eq({:text => 'sometext'})
275
+ @envelopes.first.timetoken.blank?.should eq false
276
+ end
277
+
278
+ end
279
+ end
280
+ end
281
+
282
+ context 'its synchronous' do
283
+ it 'publishes valid message' do
284
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-200-valid', :record => :none) do
285
+
286
+ @pubnub.publish(
287
+ :message => {:text => 'sometext'},
288
+ :channel => 'ruby_demo_channel',
289
+ :callback => @callback,
290
+ :http_sync => true
291
+ )
292
+
293
+ @envelopes.size.should eq 1
294
+ @envelopes.first.response_message.should eq 'Sent'
295
+ @envelopes.first.status.should eq 200
296
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
297
+ @envelopes.first.message.should eq({:text => 'sometext'})
298
+ @envelopes.first.timetoken.blank?.should eq false
299
+
300
+ end
301
+ end
302
+ end
303
+ end
304
+
305
+ context 'with invalid json' do
306
+ context 'its asynchronous' do
307
+ it 'handles invalid json gracefully' do
308
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-200-invalid', :record => :none) do
309
+
310
+ @pubnub.publish(
311
+ :message => {:text => 'sometext'},
312
+ :channel => 'ruby_demo_channel',
313
+ :callback => @callback
314
+ )
315
+
316
+ eventually do
317
+ @envelopes.size.should eq 0
318
+ @error_envelopes.size.should eq 1
319
+ @error_envelopes.first.response_message.should eq nil
320
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
321
+ @error_envelopes.first.status.should eq 200
322
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
323
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
324
+ @error_envelopes.first.timetoken.blank?.should eq true
325
+ end
326
+
327
+ end
328
+ end
329
+ end
330
+
331
+ context 'its synchronous' do
332
+ it 'handles invalid json gracefully' do
333
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-200-invalid', :record => :none) do
334
+
335
+ @pubnub.publish(
336
+ :message => {:text => 'sometext'},
337
+ :channel => 'ruby_demo_channel',
338
+ :callback => @callback,
339
+ :http_sync => true
340
+ )
341
+
342
+ @envelopes.size.should eq 0
343
+ @error_envelopes.size.should eq 1
344
+ @error_envelopes.first.response_message.should eq nil
345
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
346
+ @error_envelopes.first.status.should eq 200
347
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
348
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
349
+ @error_envelopes.first.timetoken.blank?.should eq true
350
+
351
+ end
352
+ end
353
+ end
354
+ end
355
+ end
356
+
357
+ context 'gets status non200 response' do
358
+ context 'with valid json' do
359
+ context 'its asynchronous' do
360
+ it 'handles non200 response gracefully' do
361
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-non200-valid', :record => :none) do
362
+
363
+ @pubnub.publish(
364
+ :message => {:text => 'sometext'},
365
+ :channel => 'ruby_demo_channel',
366
+ :callback => @callback
367
+ )
368
+
369
+ eventually do
370
+ @envelopes.size.should eq 0
371
+ @error_envelopes.size.should eq 1
372
+ @error_envelopes.first.response_message.should eq 'Sent'
373
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
374
+ @error_envelopes.first.status.should eq 500
375
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
376
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
377
+ @error_envelopes.first.timetoken.blank?.should eq false
378
+ end
379
+
380
+ end
381
+ end
382
+ end
383
+
384
+ context 'its synchronous' do
385
+ it 'handles non200 response gracefully' do
386
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-non200-valid', :record => :none) do
387
+
388
+ @pubnub.publish(
389
+ :message => {:text => 'sometext'},
390
+ :channel => 'ruby_demo_channel',
391
+ :callback => @callback,
392
+ :http_sync => true
393
+ )
394
+
395
+ @envelopes.size.should eq 0
396
+ @error_envelopes.size.should eq 1
397
+ @error_envelopes.first.response_message.should eq 'Sent'
398
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
399
+ @error_envelopes.first.status.should eq 500
400
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
401
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
402
+ @error_envelopes.first.timetoken.blank?.should eq false
403
+
404
+ end
405
+ end
406
+ end
407
+ end
408
+
409
+ context 'with invalid json' do
410
+ context 'its asynchronous' do
411
+ it 'handles invalid json and non200 response gracefully' do
412
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-non200-invalid', :record => :none) do
413
+
414
+ @pubnub.publish(
415
+ :message => {:text => 'sometext'},
416
+ :channel => 'ruby_demo_channel',
417
+ :callback => @callback
418
+ )
419
+
420
+ eventually do
421
+ @envelopes.size.should eq 0
422
+ @error_envelopes.size.should eq 1
423
+ @error_envelopes.first.response_message.should eq nil
424
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
425
+ @error_envelopes.first.status.should eq 500
426
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
427
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
428
+ @error_envelopes.first.timetoken.blank?.should eq true
429
+ end
430
+
431
+ end
432
+ end
433
+ end
434
+
435
+ context 'its synchronous' do
436
+ it 'handles invalid json and non200 response gracefully' do
437
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-non200-invalid', :record => :none) do
438
+
439
+ @pubnub.publish(
440
+ :message => {:text => 'sometext'},
441
+ :channel => 'ruby_demo_channel',
442
+ :callback => @callback,
443
+ :http_sync => true
444
+ )
445
+
446
+ @envelopes.size.should eq 0
447
+ @error_envelopes.size.should eq 1
448
+ @error_envelopes.first.response_message.should eq nil
449
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
450
+ @error_envelopes.first.status.should eq 500
451
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
452
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
453
+ @error_envelopes.first.timetoken.blank?.should eq true
454
+
455
+ end
456
+ end
457
+ end
458
+ end
459
+ end
460
+ end
461
+ end
462
+
463
+ context 'without auth_key provided' do
464
+ context 'without encrypting message' do
465
+
466
+ before(:each) do
467
+ @pubnub = Pubnub.new(
468
+ :max_retries => 0,
469
+ :subscribe_key => :demo,
470
+ :publish_key => :demo,
471
+ :secret_key => 'some_secret_key',
472
+ :error_callback => @error_callback,
473
+ :disable_persistent_connection => true
474
+ )
475
+
476
+ @pubnub.uuid = 'tester'
477
+ end
478
+
479
+ context 'gets status 200 response' do
480
+ context 'with valid json' do
481
+ context 'its asynchronous' do
482
+ it 'publishes valid message' do
483
+ VCR.use_cassette('new_ones/publish/publish-http-200-valid', :record => :none) do
484
+
485
+ @pubnub.publish(
486
+ :message => {:text => 'sometext'},
487
+ :channel => 'ruby_demo_channel',
488
+ :callback => @callback
489
+ )
490
+
491
+ eventually do
492
+ @envelopes.size.should eq 1
493
+ @envelopes.first.response_message.should eq 'Sent'
494
+ @envelopes.first.status.should eq 200
495
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
496
+ @envelopes.first.message.should eq({:text => 'sometext'})
497
+ @envelopes.first.timetoken.blank?.should eq false
498
+ end
499
+
500
+ end
501
+ end
502
+ end
503
+
504
+ context 'its synchronous' do
505
+ it 'publishes valid message' do
506
+ VCR.use_cassette('new_ones/publish/publish-http-200-valid', :record => :none) do
507
+
508
+ @pubnub.publish(
509
+ :message => {:text => 'sometext'},
510
+ :channel => 'ruby_demo_channel',
511
+ :callback => @callback,
512
+ :http_sync => true
513
+ )
514
+
515
+ @envelopes.size.should eq 1
516
+ @envelopes.first.response_message.should eq 'Sent'
517
+ @envelopes.first.status.should eq 200
518
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
519
+ @envelopes.first.message.should eq({:text => 'sometext'})
520
+ @envelopes.first.timetoken.blank?.should eq false
521
+
522
+ end
523
+ end
524
+ end
525
+ end
526
+
527
+ context 'with invalid json' do
528
+ context 'its asynchronous' do
529
+ it 'handles invalid json gracefully' do
530
+ VCR.use_cassette('new_ones/publish/publish-http-200-invalid', :record => :none) do
531
+
532
+ @pubnub.publish(
533
+ :message => {:text => 'sometext'},
534
+ :channel => 'ruby_demo_channel',
535
+ :callback => @callback
536
+ )
537
+
538
+ eventually do
539
+ @envelopes.size.should eq 0
540
+ @error_envelopes.size.should eq 1
541
+ @error_envelopes.first.response_message.should eq nil
542
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
543
+ @error_envelopes.first.status.should eq 200
544
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
545
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
546
+ @error_envelopes.first.timetoken.blank?.should eq true
547
+ end
548
+
549
+ end
550
+ end
551
+ end
552
+
553
+ context 'its synchronous' do
554
+ it 'handles invalid json gracefully' do
555
+ VCR.use_cassette('new_ones/publish/publish-http-200-invalid', :record => :none) do
556
+
557
+ @pubnub.publish(
558
+ :message => {:text => 'sometext'},
559
+ :channel => 'ruby_demo_channel',
560
+ :callback => @callback,
561
+ :http_sync => true
562
+ )
563
+
564
+ @envelopes.size.should eq 0
565
+ @error_envelopes.size.should eq 1
566
+ @error_envelopes.first.response_message.should eq nil
567
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
568
+ @error_envelopes.first.status.should eq 200
569
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
570
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
571
+ @error_envelopes.first.timetoken.blank?.should eq true
572
+
573
+ end
574
+ end
575
+ end
576
+ end
577
+ end
578
+
579
+ context 'gets status non200 response' do
580
+ context 'with valid json' do
581
+ context 'its asynchronous' do
582
+ it 'handles non200 response gracefully' do
583
+ VCR.use_cassette('new_ones/publish/publish-http-non200-valid', :record => :none) do
584
+
585
+ @pubnub.publish(
586
+ :message => {:text => 'sometext'},
587
+ :channel => 'ruby_demo_channel',
588
+ :callback => @callback
589
+ )
590
+
591
+ eventually do
592
+ @envelopes.size.should eq 0
593
+ @error_envelopes.size.should eq 1
594
+ @error_envelopes.first.response_message.should eq 'Sent'
595
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
596
+ @error_envelopes.first.status.should eq 500
597
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
598
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
599
+ @error_envelopes.first.timetoken.blank?.should eq false
600
+ end
601
+
602
+ end
603
+ end
604
+ end
605
+
606
+ context 'its synchronous' do
607
+ it 'handles non200 response gracefully' do
608
+ VCR.use_cassette('new_ones/publish/publish-http-non200-valid', :record => :none) do
609
+
610
+ @pubnub.publish(
611
+ :message => {:text => 'sometext'},
612
+ :channel => 'ruby_demo_channel',
613
+ :callback => @callback,
614
+ :http_sync => true
615
+ )
616
+
617
+ @envelopes.size.should eq 0
618
+ @error_envelopes.size.should eq 1
619
+ @error_envelopes.first.response_message.should eq 'Sent'
620
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
621
+ @error_envelopes.first.status.should eq 500
622
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
623
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
624
+ @error_envelopes.first.timetoken.blank?.should eq false
625
+
626
+ end
627
+ end
628
+ end
629
+ end
630
+
631
+ context 'with invalid json' do
632
+ context 'its asynchronous' do
633
+ it 'handles invalid json and non200 response gracefully' do
634
+ VCR.use_cassette('new_ones/publish/publish-http-non200-invalid', :record => :none) do
635
+
636
+ @pubnub.publish(
637
+ :message => {:text => 'sometext'},
638
+ :channel => 'ruby_demo_channel',
639
+ :callback => @callback
640
+ )
641
+
642
+ eventually do
643
+ @envelopes.size.should eq 0
644
+ @error_envelopes.size.should eq 1
645
+ @error_envelopes.first.response_message.should eq nil
646
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
647
+ @error_envelopes.first.status.should eq 500
648
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
649
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
650
+ @error_envelopes.first.timetoken.blank?.should eq true
651
+ end
652
+
653
+ end
654
+ end
655
+ end
656
+
657
+ context 'its synchronous' do
658
+ it 'handles invalid json and non200 response gracefully' do
659
+ VCR.use_cassette('new_ones/publish/publish-http-non200-invalid', :record => :none) do
660
+
661
+ @pubnub.publish(
662
+ :message => {:text => 'sometext'},
663
+ :channel => 'ruby_demo_channel',
664
+ :callback => @callback,
665
+ :http_sync => true
666
+ )
667
+
668
+ @envelopes.size.should eq 0
669
+ @error_envelopes.size.should eq 1
670
+ @error_envelopes.first.response_message.should eq nil
671
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
672
+ @error_envelopes.first.status.should eq 500
673
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
674
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
675
+ @error_envelopes.first.timetoken.blank?.should eq true
676
+
677
+ end
678
+ end
679
+ end
680
+ end
681
+ end
682
+ end
683
+
684
+ context 'with encrypting message' do
685
+
686
+ before(:each) do
687
+ @pubnub = Pubnub.new(
688
+ :max_retries => 0,
689
+ :subscribe_key => :demo,
690
+ :publish_key => :demo,
691
+ :secret_key => 'some_secret_key',
692
+ :cipher_key => 'secret',
693
+ :error_callback => @error_callback,
694
+ :disable_persistent_connection => true
695
+ )
696
+
697
+ @pubnub.uuid = 'tester'
698
+ end
699
+
700
+ context 'gets status 200 response' do
701
+ context 'with valid json' do
702
+ context 'its asynchronous' do
703
+ it 'publishes valid message' do
704
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-200-valid', :record => :none) do
705
+
706
+ @pubnub.publish(
707
+ :message => {:text => 'sometext'},
708
+ :channel => 'ruby_demo_channel',
709
+ :callback => @callback
710
+ )
711
+
712
+ eventually do
713
+ @envelopes.size.should eq 1
714
+ @envelopes.first.response_message.should eq 'Sent'
715
+ @envelopes.first.status.should eq 200
716
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
717
+ @envelopes.first.message.should eq({:text => 'sometext'})
718
+ @envelopes.first.timetoken.blank?.should eq false
719
+ end
720
+
721
+ end
722
+ end
723
+ end
724
+
725
+ context 'its synchronous' do
726
+ it 'publishes valid message' do
727
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-200-valid', :record => :none) do
728
+
729
+ @pubnub.publish(
730
+ :message => {:text => 'sometext'},
731
+ :channel => 'ruby_demo_channel',
732
+ :callback => @callback,
733
+ :http_sync => true
734
+ )
735
+
736
+ @envelopes.size.should eq 1
737
+ @envelopes.first.response_message.should eq 'Sent'
738
+ @envelopes.first.status.should eq 200
739
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
740
+ @envelopes.first.message.should eq({:text => 'sometext'})
741
+ @envelopes.first.timetoken.blank?.should eq false
742
+
743
+ end
744
+ end
745
+ end
746
+ end
747
+
748
+ context 'with invalid json' do
749
+ context 'its asynchronous' do
750
+ it 'handles invalid json gracefully' do
751
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-200-invalid', :record => :none) do
752
+
753
+ @pubnub.publish(
754
+ :message => {:text => 'sometext'},
755
+ :channel => 'ruby_demo_channel',
756
+ :callback => @callback
757
+ )
758
+
759
+ eventually do
760
+ @envelopes.size.should eq 0
761
+ @error_envelopes.size.should eq 1
762
+ @error_envelopes.first.response_message.should eq nil
763
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
764
+ @error_envelopes.first.status.should eq 200
765
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
766
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
767
+ @error_envelopes.first.timetoken.blank?.should eq true
768
+ end
769
+
770
+ end
771
+ end
772
+ end
773
+
774
+ context 'its synchronous' do
775
+ it 'handles invalid json gracefully' do
776
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-200-invalid', :record => :none) do
777
+
778
+ @pubnub.publish(
779
+ :message => {:text => 'sometext'},
780
+ :channel => 'ruby_demo_channel',
781
+ :callback => @callback,
782
+ :http_sync => true
783
+ )
784
+
785
+ @envelopes.size.should eq 0
786
+ @error_envelopes.size.should eq 1
787
+ @error_envelopes.first.response_message.should eq nil
788
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
789
+ @error_envelopes.first.status.should eq 200
790
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
791
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
792
+ @error_envelopes.first.timetoken.blank?.should eq true
793
+
794
+ end
795
+ end
796
+ end
797
+ end
798
+ end
799
+
800
+ context 'gets status non200 response' do
801
+ context 'with valid json' do
802
+ context 'its asynchronous' do
803
+ it 'handles non200 response gracefully' do
804
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-non200-valid', :record => :none) do
805
+
806
+ @pubnub.publish(
807
+ :message => {:text => 'sometext'},
808
+ :channel => 'ruby_demo_channel',
809
+ :callback => @callback
810
+ )
811
+
812
+ eventually do
813
+ @envelopes.size.should eq 0
814
+ @error_envelopes.size.should eq 1
815
+ @error_envelopes.first.response_message.should eq 'Sent'
816
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
817
+ @error_envelopes.first.status.should eq 500
818
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
819
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
820
+ @error_envelopes.first.timetoken.blank?.should eq false
821
+ end
822
+
823
+ end
824
+ end
825
+ end
826
+
827
+ context 'its synchronous' do
828
+ it 'handles non200 response gracefully' do
829
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-non200-valid', :record => :none) do
830
+
831
+ @pubnub.publish(
832
+ :message => {:text => 'sometext'},
833
+ :channel => 'ruby_demo_channel',
834
+ :callback => @callback,
835
+ :http_sync => true
836
+ )
837
+
838
+ @envelopes.size.should eq 0
839
+ @error_envelopes.size.should eq 1
840
+ @error_envelopes.first.response_message.should eq 'Sent'
841
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
842
+ @error_envelopes.first.status.should eq 500
843
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
844
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
845
+ @error_envelopes.first.timetoken.blank?.should eq false
846
+
847
+ end
848
+ end
849
+ end
850
+ end
851
+
852
+ context 'with invalid json' do
853
+ context 'its asynchronous' do
854
+ it 'handles invalid json and non200 response gracefully' do
855
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-non200-invalid', :record => :none) do
856
+
857
+ @pubnub.publish(
858
+ :message => {:text => 'sometext'},
859
+ :channel => 'ruby_demo_channel',
860
+ :callback => @callback
861
+ )
862
+
863
+ eventually do
864
+ @envelopes.size.should eq 0
865
+ @error_envelopes.size.should eq 1
866
+ @error_envelopes.first.response_message.should eq nil
867
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
868
+ @error_envelopes.first.status.should eq 500
869
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
870
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
871
+ @error_envelopes.first.timetoken.blank?.should eq true
872
+ end
873
+
874
+ end
875
+ end
876
+ end
877
+
878
+ context 'its synchronous' do
879
+ it 'handles invalid json and non200 response gracefully' do
880
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-non200-invalid', :record => :none) do
881
+
882
+ @pubnub.publish(
883
+ :message => {:text => 'sometext'},
884
+ :channel => 'ruby_demo_channel',
885
+ :callback => @callback,
886
+ :http_sync => true
887
+ )
888
+
889
+ @envelopes.size.should eq 0
890
+ @error_envelopes.size.should eq 1
891
+ @error_envelopes.first.response_message.should eq nil
892
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
893
+ @error_envelopes.first.status.should eq 500
894
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
895
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
896
+ @error_envelopes.first.timetoken.blank?.should eq true
897
+
898
+ end
899
+ end
900
+ end
901
+ end
902
+ end
903
+ end
904
+ end
905
+ end
906
+
907
+ context 'uses https' do
908
+ context 'with auth_key provided' do
909
+ context 'without encrypting message' do
910
+
911
+ before(:each) do
912
+ @pubnub = Pubnub.new(
913
+ :max_retries => 0,
914
+ :subscribe_key => :demo,
915
+ :publish_key => :demo,
916
+ :auth_key => :demoish_authkey,
917
+ :secret_key => 'some_secret_key',
918
+ :error_callback => @error_callback,
919
+ :ssl => true,
920
+ :disable_persistent_connection => true
921
+ )
922
+
923
+ @pubnub.uuid = 'tester'
924
+ end
925
+
926
+ context 'gets status 200 response' do
927
+ context 'with valid json' do
928
+ context 'its asynchronous' do
929
+ it 'publishes valid message' do
930
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-200-valid', :record => :none) do
931
+
932
+ @pubnub.publish(
933
+ :message => {:text => 'sometext'},
934
+ :channel => 'ruby_demo_channel',
935
+ :callback => @callback
936
+ )
937
+
938
+ eventually do
939
+ @envelopes.size.should eq 1
940
+ @envelopes.first.response_message.should eq 'Sent'
941
+ @envelopes.first.status.should eq 200
942
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
943
+ @envelopes.first.message.should eq({:text => 'sometext'})
944
+ @envelopes.first.timetoken.blank?.should eq false
945
+ end
946
+
947
+ end
948
+ end
949
+ end
950
+
951
+ context 'its synchronous' do
952
+ it 'publishes valid message' do
953
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-200-valid', :record => :none) do
954
+
955
+ @pubnub.publish(
956
+ :message => {:text => 'sometext'},
957
+ :channel => 'ruby_demo_channel',
958
+ :callback => @callback,
959
+ :http_sync => true
960
+ )
961
+
962
+ @envelopes.size.should eq 1
963
+ @envelopes.first.response_message.should eq 'Sent'
964
+ @envelopes.first.status.should eq 200
965
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
966
+ @envelopes.first.message.should eq({:text => 'sometext'})
967
+ @envelopes.first.timetoken.blank?.should eq false
968
+
969
+ end
970
+ end
971
+ end
972
+ end
973
+
974
+ context 'with invalid json' do
975
+ context 'its asynchronous' do
976
+ it 'handles invalid json gracefully' do
977
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-200-invalid', :record => :none) do
978
+
979
+ @pubnub.publish(
980
+ :message => {:text => 'sometext'},
981
+ :channel => 'ruby_demo_channel',
982
+ :callback => @callback
983
+ )
984
+
985
+ eventually do
986
+ @envelopes.size.should eq 0
987
+ @error_envelopes.size.should eq 1
988
+ @error_envelopes.first.response_message.should eq nil
989
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
990
+ @error_envelopes.first.status.should eq 200
991
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
992
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
993
+ @error_envelopes.first.timetoken.blank?.should eq true
994
+ end
995
+
996
+ end
997
+ end
998
+ end
999
+
1000
+ context 'its synchronous' do
1001
+ it 'handles invalid json gracefully' do
1002
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-200-invalid', :record => :none) do
1003
+
1004
+ @pubnub.publish(
1005
+ :message => {:text => 'sometext'},
1006
+ :channel => 'ruby_demo_channel',
1007
+ :callback => @callback,
1008
+ :http_sync => true
1009
+ )
1010
+
1011
+ @envelopes.size.should eq 0
1012
+ @error_envelopes.size.should eq 1
1013
+ @error_envelopes.first.response_message.should eq nil
1014
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1015
+ @error_envelopes.first.status.should eq 200
1016
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1017
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1018
+ @error_envelopes.first.timetoken.blank?.should eq true
1019
+
1020
+ end
1021
+ end
1022
+ end
1023
+ end
1024
+ end
1025
+
1026
+ context 'gets status non200 response' do
1027
+ context 'with valid json' do
1028
+ context 'its asynchronous' do
1029
+ it 'handles non200 response gracefully' do
1030
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-non200-valid', :record => :none) do
1031
+
1032
+ @pubnub.publish(
1033
+ :message => {:text => 'sometext'},
1034
+ :channel => 'ruby_demo_channel',
1035
+ :callback => @callback
1036
+ )
1037
+
1038
+ eventually do
1039
+ @envelopes.size.should eq 0
1040
+ @error_envelopes.size.should eq 1
1041
+ @error_envelopes.first.response_message.should eq 'Sent'
1042
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
1043
+ @error_envelopes.first.status.should eq 500
1044
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1045
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1046
+ @error_envelopes.first.timetoken.blank?.should eq false
1047
+ end
1048
+
1049
+ end
1050
+ end
1051
+ end
1052
+
1053
+ context 'its synchronous' do
1054
+ it 'handles non200 response gracefully' do
1055
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-non200-valid', :record => :none) do
1056
+
1057
+ @pubnub.publish(
1058
+ :message => {:text => 'sometext'},
1059
+ :channel => 'ruby_demo_channel',
1060
+ :callback => @callback,
1061
+ :http_sync => true
1062
+ )
1063
+
1064
+ @envelopes.size.should eq 0
1065
+ @error_envelopes.size.should eq 1
1066
+ @error_envelopes.first.response_message.should eq 'Sent'
1067
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
1068
+ @error_envelopes.first.status.should eq 500
1069
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1070
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1071
+ @error_envelopes.first.timetoken.blank?.should eq false
1072
+
1073
+ end
1074
+ end
1075
+ end
1076
+ end
1077
+
1078
+ context 'with invalid json' do
1079
+ context 'its asynchronous' do
1080
+ it 'handles invalid json and non200 response gracefully' do
1081
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-non200-invalid', :record => :none) do
1082
+
1083
+ @pubnub.publish(
1084
+ :message => {:text => 'sometext'},
1085
+ :channel => 'ruby_demo_channel',
1086
+ :callback => @callback
1087
+ )
1088
+
1089
+ eventually do
1090
+ @envelopes.size.should eq 0
1091
+ @error_envelopes.size.should eq 1
1092
+ @error_envelopes.first.response_message.should eq nil
1093
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1094
+ @error_envelopes.first.status.should eq 500
1095
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1096
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1097
+ @error_envelopes.first.timetoken.blank?.should eq true
1098
+ end
1099
+
1100
+ end
1101
+ end
1102
+ end
1103
+
1104
+ context 'its synchronous' do
1105
+ it 'handles invalid json and non200 response gracefully' do
1106
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-non200-invalid', :record => :none) do
1107
+
1108
+ @pubnub.publish(
1109
+ :message => {:text => 'sometext'},
1110
+ :channel => 'ruby_demo_channel',
1111
+ :callback => @callback,
1112
+ :http_sync => true
1113
+ )
1114
+
1115
+ @envelopes.size.should eq 0
1116
+ @error_envelopes.size.should eq 1
1117
+ @error_envelopes.first.response_message.should eq nil
1118
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1119
+ @error_envelopes.first.status.should eq 500
1120
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1121
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1122
+ @error_envelopes.first.timetoken.blank?.should eq true
1123
+
1124
+ end
1125
+ end
1126
+ end
1127
+ end
1128
+ end
1129
+ end
1130
+
1131
+ context 'with encrypting message' do
1132
+
1133
+ before(:each) do
1134
+ @pubnub = Pubnub.new(
1135
+ :max_retries => 0,
1136
+ :subscribe_key => :demo,
1137
+ :publish_key => :demo,
1138
+ :auth_key => :demoish_authkey,
1139
+ :secret_key => 'some_secret_key',
1140
+ :cipher_key => 'secret',
1141
+ :error_callback => @error_callback,
1142
+ :ssl => true,
1143
+ :disable_persistent_connection => true
1144
+ )
1145
+
1146
+ @pubnub.uuid = 'tester'
1147
+ end
1148
+
1149
+ context 'gets status 200 response' do
1150
+ context 'with valid json' do
1151
+ context 'its asynchronous' do
1152
+ it 'publishes valid message' do
1153
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-200-valid', :record => :none) do
1154
+
1155
+ @pubnub.publish(
1156
+ :message => {:text => 'sometext'},
1157
+ :channel => 'ruby_demo_channel',
1158
+ :callback => @callback
1159
+ )
1160
+
1161
+ eventually do
1162
+ @envelopes.size.should eq 1
1163
+ @envelopes.first.response_message.should eq 'Sent'
1164
+ @envelopes.first.status.should eq 200
1165
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1166
+ @envelopes.first.message.should eq({:text => 'sometext'})
1167
+ @envelopes.first.timetoken.blank?.should eq false
1168
+ end
1169
+
1170
+ end
1171
+ end
1172
+ end
1173
+
1174
+ context 'its synchronous' do
1175
+ it 'publishes valid message' do
1176
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-200-valid', :record => :none) do
1177
+
1178
+ @pubnub.publish(
1179
+ :message => {:text => 'sometext'},
1180
+ :channel => 'ruby_demo_channel',
1181
+ :callback => @callback,
1182
+ :http_sync => true
1183
+ )
1184
+
1185
+ @envelopes.size.should eq 1
1186
+ @envelopes.first.response_message.should eq 'Sent'
1187
+ @envelopes.first.status.should eq 200
1188
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1189
+ @envelopes.first.message.should eq({:text => 'sometext'})
1190
+ @envelopes.first.timetoken.blank?.should eq false
1191
+
1192
+ end
1193
+ end
1194
+ end
1195
+ end
1196
+
1197
+ context 'with invalid json' do
1198
+ context 'its asynchronous' do
1199
+ it 'handles invalid json gracefully' do
1200
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-200-invalid', :record => :none) do
1201
+
1202
+ @pubnub.publish(
1203
+ :message => {:text => 'sometext'},
1204
+ :channel => 'ruby_demo_channel',
1205
+ :callback => @callback
1206
+ )
1207
+
1208
+ eventually do
1209
+ @envelopes.size.should eq 0
1210
+ @error_envelopes.size.should eq 1
1211
+ @error_envelopes.first.response_message.should eq nil
1212
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1213
+ @error_envelopes.first.status.should eq 200
1214
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1215
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1216
+ @error_envelopes.first.timetoken.blank?.should eq true
1217
+ end
1218
+
1219
+ end
1220
+ end
1221
+ end
1222
+
1223
+ context 'its synchronous' do
1224
+ it 'handles invalid json gracefully' do
1225
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-200-invalid', :record => :none) do
1226
+
1227
+ @pubnub.publish(
1228
+ :message => {:text => 'sometext'},
1229
+ :channel => 'ruby_demo_channel',
1230
+ :callback => @callback,
1231
+ :http_sync => true
1232
+ )
1233
+
1234
+ @envelopes.size.should eq 0
1235
+ @error_envelopes.size.should eq 1
1236
+ @error_envelopes.first.response_message.should eq nil
1237
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1238
+ @error_envelopes.first.status.should eq 200
1239
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1240
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1241
+ @error_envelopes.first.timetoken.blank?.should eq true
1242
+
1243
+ end
1244
+ end
1245
+ end
1246
+ end
1247
+ end
1248
+
1249
+ context 'gets status non200 response' do
1250
+ context 'with valid json' do
1251
+ context 'its asynchronous' do
1252
+ it 'handles non200 response gracefully' do
1253
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-non200-valid', :record => :none) do
1254
+
1255
+ @pubnub.publish(
1256
+ :message => {:text => 'sometext'},
1257
+ :channel => 'ruby_demo_channel',
1258
+ :callback => @callback
1259
+ )
1260
+
1261
+ eventually do
1262
+ @envelopes.size.should eq 0
1263
+ @error_envelopes.size.should eq 1
1264
+ @error_envelopes.first.response_message.should eq 'Sent'
1265
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
1266
+ @error_envelopes.first.status.should eq 500
1267
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1268
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1269
+ @error_envelopes.first.timetoken.blank?.should eq false
1270
+ end
1271
+
1272
+ end
1273
+ end
1274
+ end
1275
+
1276
+ context 'its synchronous' do
1277
+ it 'handles non200 response gracefully' do
1278
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-non200-valid', :record => :none) do
1279
+
1280
+ @pubnub.publish(
1281
+ :message => {:text => 'sometext'},
1282
+ :channel => 'ruby_demo_channel',
1283
+ :callback => @callback,
1284
+ :http_sync => true
1285
+ )
1286
+
1287
+ @envelopes.size.should eq 0
1288
+ @error_envelopes.size.should eq 1
1289
+ @error_envelopes.first.response_message.should eq 'Sent'
1290
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
1291
+ @error_envelopes.first.status.should eq 500
1292
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1293
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1294
+ @error_envelopes.first.timetoken.blank?.should eq false
1295
+
1296
+ end
1297
+ end
1298
+ end
1299
+ end
1300
+
1301
+ context 'with invalid json' do
1302
+ context 'its asynchronous' do
1303
+ it 'handles invalid json and non200 response gracefully' do
1304
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-non200-invalid', :record => :none) do
1305
+
1306
+ @pubnub.publish(
1307
+ :message => {:text => 'sometext'},
1308
+ :channel => 'ruby_demo_channel',
1309
+ :callback => @callback
1310
+ )
1311
+
1312
+ eventually do
1313
+ @envelopes.size.should eq 0
1314
+ @error_envelopes.size.should eq 1
1315
+ @error_envelopes.first.response_message.should eq nil
1316
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1317
+ @error_envelopes.first.status.should eq 500
1318
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1319
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1320
+ @error_envelopes.first.timetoken.blank?.should eq true
1321
+ end
1322
+
1323
+ end
1324
+ end
1325
+ end
1326
+
1327
+ context 'its synchronous' do
1328
+ it 'handles invalid json and non200 response gracefully' do
1329
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-non200-invalid', :record => :none) do
1330
+
1331
+ @pubnub.publish(
1332
+ :message => {:text => 'sometext'},
1333
+ :channel => 'ruby_demo_channel',
1334
+ :callback => @callback,
1335
+ :http_sync => true
1336
+ )
1337
+
1338
+ @envelopes.size.should eq 0
1339
+ @error_envelopes.size.should eq 1
1340
+ @error_envelopes.first.response_message.should eq nil
1341
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1342
+ @error_envelopes.first.status.should eq 500
1343
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1344
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1345
+ @error_envelopes.first.timetoken.blank?.should eq true
1346
+
1347
+ end
1348
+ end
1349
+ end
1350
+ end
1351
+ end
1352
+ end
1353
+ end
1354
+
1355
+ context 'without auth_key provided' do
1356
+ context 'without encrypting message' do
1357
+
1358
+ before(:each) do
1359
+ @pubnub = Pubnub.new(
1360
+ :max_retries => 0,
1361
+ :subscribe_key => :demo,
1362
+ :publish_key => :demo,
1363
+ :secret_key => 'some_secret_key',
1364
+ :error_callback => @error_callback,
1365
+ :ssl => true,
1366
+ :disable_persistent_connection => true
1367
+ )
1368
+
1369
+ @pubnub.uuid = 'tester'
1370
+ end
1371
+
1372
+ context 'gets status 200 response' do
1373
+ context 'with valid json' do
1374
+ context 'its asynchronous' do
1375
+ it 'publishes valid message' do
1376
+ VCR.use_cassette('new_ones/publish/publish-https-200-valid', :record => :none) do
1377
+
1378
+ @pubnub.publish(
1379
+ :message => {:text => 'sometext'},
1380
+ :channel => 'ruby_demo_channel',
1381
+ :callback => @callback
1382
+ )
1383
+
1384
+ eventually do
1385
+ @envelopes.size.should eq 1
1386
+ @envelopes.first.response_message.should eq 'Sent'
1387
+ @envelopes.first.status.should eq 200
1388
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1389
+ @envelopes.first.message.should eq({:text => 'sometext'})
1390
+ @envelopes.first.timetoken.blank?.should eq false
1391
+ end
1392
+
1393
+ end
1394
+ end
1395
+ end
1396
+
1397
+ context 'its synchronous' do
1398
+ it 'publishes valid message' do
1399
+ VCR.use_cassette('new_ones/publish/publish-https-200-valid', :record => :none) do
1400
+
1401
+ @pubnub.publish(
1402
+ :message => {:text => 'sometext'},
1403
+ :channel => 'ruby_demo_channel',
1404
+ :callback => @callback,
1405
+ :http_sync => true
1406
+ )
1407
+
1408
+ @envelopes.size.should eq 1
1409
+ @envelopes.first.response_message.should eq 'Sent'
1410
+ @envelopes.first.status.should eq 200
1411
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1412
+ @envelopes.first.message.should eq({:text => 'sometext'})
1413
+ @envelopes.first.timetoken.blank?.should eq false
1414
+
1415
+ end
1416
+ end
1417
+ end
1418
+ end
1419
+
1420
+ context 'with invalid json' do
1421
+ context 'its asynchronous' do
1422
+ it 'handles invalid json gracefully' do
1423
+ VCR.use_cassette('new_ones/publish/publish-https-200-invalid', :record => :none) do
1424
+
1425
+ @pubnub.publish(
1426
+ :message => {:text => 'sometext'},
1427
+ :channel => 'ruby_demo_channel',
1428
+ :callback => @callback
1429
+ )
1430
+
1431
+ eventually do
1432
+ @envelopes.size.should eq 0
1433
+ @error_envelopes.size.should eq 1
1434
+ @error_envelopes.first.response_message.should eq nil
1435
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1436
+ @error_envelopes.first.status.should eq 200
1437
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1438
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1439
+ @error_envelopes.first.timetoken.blank?.should eq true
1440
+ end
1441
+
1442
+ end
1443
+ end
1444
+ end
1445
+
1446
+ context 'its synchronous' do
1447
+ it 'handles invalid json gracefully' do
1448
+ VCR.use_cassette('new_ones/publish/publish-https-200-invalid', :record => :none) do
1449
+
1450
+ @pubnub.publish(
1451
+ :message => {:text => 'sometext'},
1452
+ :channel => 'ruby_demo_channel',
1453
+ :callback => @callback,
1454
+ :http_sync => true
1455
+ )
1456
+
1457
+ @envelopes.size.should eq 0
1458
+ @error_envelopes.size.should eq 1
1459
+ @error_envelopes.first.response_message.should eq nil
1460
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1461
+ @error_envelopes.first.status.should eq 200
1462
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1463
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1464
+ @error_envelopes.first.timetoken.blank?.should eq true
1465
+
1466
+ end
1467
+ end
1468
+ end
1469
+ end
1470
+ end
1471
+
1472
+ context 'gets status non200 response' do
1473
+ context 'with valid json' do
1474
+ context 'its asynchronous' do
1475
+ it 'handles non200 response gracefully' do
1476
+ VCR.use_cassette('new_ones/publish/publish-https-non200-valid', :record => :none) do
1477
+
1478
+ @pubnub.publish(
1479
+ :message => {:text => 'sometext'},
1480
+ :channel => 'ruby_demo_channel',
1481
+ :callback => @callback
1482
+ )
1483
+
1484
+ eventually do
1485
+ @envelopes.size.should eq 0
1486
+ @error_envelopes.size.should eq 1
1487
+ @error_envelopes.first.response_message.should eq 'Sent'
1488
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
1489
+ @error_envelopes.first.status.should eq 500
1490
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1491
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1492
+ @error_envelopes.first.timetoken.blank?.should eq false
1493
+ end
1494
+
1495
+ end
1496
+ end
1497
+ end
1498
+
1499
+ context 'its synchronous' do
1500
+ it 'handles non200 response gracefully' do
1501
+ VCR.use_cassette('new_ones/publish/publish-https-non200-valid', :record => :none) do
1502
+
1503
+ @pubnub.publish(
1504
+ :message => {:text => 'sometext'},
1505
+ :channel => 'ruby_demo_channel',
1506
+ :callback => @callback,
1507
+ :http_sync => true
1508
+ )
1509
+
1510
+ @envelopes.size.should eq 0
1511
+ @error_envelopes.size.should eq 1
1512
+ @error_envelopes.first.response_message.should eq 'Sent'
1513
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
1514
+ @error_envelopes.first.status.should eq 500
1515
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1516
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1517
+ @error_envelopes.first.timetoken.blank?.should eq false
1518
+
1519
+ end
1520
+ end
1521
+ end
1522
+ end
1523
+
1524
+ context 'with invalid json' do
1525
+ context 'its asynchronous' do
1526
+ it 'handles invalid json and non200 response gracefully' do
1527
+ VCR.use_cassette('new_ones/publish/publish-https-non200-invalid', :record => :none) do
1528
+
1529
+ @pubnub.publish(
1530
+ :message => {:text => 'sometext'},
1531
+ :channel => 'ruby_demo_channel',
1532
+ :callback => @callback
1533
+ )
1534
+
1535
+ eventually do
1536
+ @envelopes.size.should eq 0
1537
+ @error_envelopes.size.should eq 1
1538
+ @error_envelopes.first.response_message.should eq nil
1539
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1540
+ @error_envelopes.first.status.should eq 500
1541
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1542
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1543
+ @error_envelopes.first.timetoken.blank?.should eq true
1544
+ end
1545
+
1546
+ end
1547
+ end
1548
+ end
1549
+
1550
+ context 'its synchronous' do
1551
+ it 'handles invalid json and non200 response gracefully' do
1552
+ VCR.use_cassette('new_ones/publish/publish-https-non200-invalid', :record => :none) do
1553
+
1554
+ @pubnub.publish(
1555
+ :message => {:text => 'sometext'},
1556
+ :channel => 'ruby_demo_channel',
1557
+ :callback => @callback,
1558
+ :http_sync => true
1559
+ )
1560
+
1561
+ @envelopes.size.should eq 0
1562
+ @error_envelopes.size.should eq 1
1563
+ @error_envelopes.first.response_message.should eq nil
1564
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1565
+ @error_envelopes.first.status.should eq 500
1566
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1567
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1568
+ @error_envelopes.first.timetoken.blank?.should eq true
1569
+
1570
+ end
1571
+ end
1572
+ end
1573
+ end
1574
+ end
1575
+ end
1576
+
1577
+ context 'with encrypting message' do
1578
+
1579
+ before(:each) do
1580
+ @pubnub = Pubnub.new(
1581
+ :max_retries => 0,
1582
+ :subscribe_key => :demo,
1583
+ :publish_key => :demo,
1584
+ :secret_key => 'some_secret_key',
1585
+ :cipher_key => 'secret',
1586
+ :error_callback => @error_callback,
1587
+ :ssl => true,
1588
+ :disable_persistent_connection => true
1589
+ )
1590
+
1591
+ @pubnub.uuid = 'tester'
1592
+ end
1593
+
1594
+ context 'gets status 200 response' do
1595
+ context 'with valid json' do
1596
+ context 'its asynchronous' do
1597
+ it 'publishes valid message' do
1598
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-200-valid', :record => :none) do
1599
+
1600
+ @pubnub.publish(
1601
+ :message => {:text => 'sometext'},
1602
+ :channel => 'ruby_demo_channel',
1603
+ :callback => @callback
1604
+ )
1605
+
1606
+ eventually do
1607
+ @envelopes.size.should eq 1
1608
+ @envelopes.first.response_message.should eq 'Sent'
1609
+ @envelopes.first.status.should eq 200
1610
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1611
+ @envelopes.first.message.should eq({:text => 'sometext'})
1612
+ @envelopes.first.timetoken.blank?.should eq false
1613
+ end
1614
+
1615
+ end
1616
+ end
1617
+ end
1618
+
1619
+ context 'its synchronous' do
1620
+ it 'publishes valid message' do
1621
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-200-valid', :record => :none) do
1622
+
1623
+ @pubnub.publish(
1624
+ :message => {:text => 'sometext'},
1625
+ :channel => 'ruby_demo_channel',
1626
+ :callback => @callback,
1627
+ :http_sync => true
1628
+ )
1629
+
1630
+ @envelopes.size.should eq 1
1631
+ @envelopes.first.response_message.should eq 'Sent'
1632
+ @envelopes.first.status.should eq 200
1633
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1634
+ @envelopes.first.message.should eq({:text => 'sometext'})
1635
+ @envelopes.first.timetoken.blank?.should eq false
1636
+
1637
+ end
1638
+ end
1639
+ end
1640
+ end
1641
+
1642
+ context 'with invalid json' do
1643
+ context 'its asynchronous' do
1644
+ it 'handles invalid json gracefully' do
1645
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-200-invalid', :record => :none) do
1646
+
1647
+ @pubnub.publish(
1648
+ :message => {:text => 'sometext'},
1649
+ :channel => 'ruby_demo_channel',
1650
+ :callback => @callback
1651
+ )
1652
+
1653
+ eventually do
1654
+ @envelopes.size.should eq 0
1655
+ @error_envelopes.size.should eq 1
1656
+ @error_envelopes.first.response_message.should eq nil
1657
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1658
+ @error_envelopes.first.status.should eq 200
1659
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1660
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1661
+ @error_envelopes.first.timetoken.blank?.should eq true
1662
+ end
1663
+
1664
+ end
1665
+ end
1666
+ end
1667
+
1668
+ context 'its synchronous' do
1669
+ it 'handles invalid json gracefully' do
1670
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-200-invalid', :record => :none) do
1671
+
1672
+ @pubnub.publish(
1673
+ :message => {:text => 'sometext'},
1674
+ :channel => 'ruby_demo_channel',
1675
+ :callback => @callback,
1676
+ :http_sync => true
1677
+ )
1678
+
1679
+ @envelopes.size.should eq 0
1680
+ @error_envelopes.size.should eq 1
1681
+ @error_envelopes.first.response_message.should eq nil
1682
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1683
+ @error_envelopes.first.status.should eq 200
1684
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1685
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1686
+ @error_envelopes.first.timetoken.blank?.should eq true
1687
+
1688
+ end
1689
+ end
1690
+ end
1691
+ end
1692
+ end
1693
+
1694
+ context 'gets status non200 response' do
1695
+ context 'with valid json' do
1696
+ context 'its asynchronous' do
1697
+ it 'handles non200 response gracefully' do
1698
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-non200-valid', :record => :none) do
1699
+
1700
+ @pubnub.publish(
1701
+ :message => {:text => 'sometext'},
1702
+ :channel => 'ruby_demo_channel',
1703
+ :callback => @callback
1704
+ )
1705
+
1706
+ eventually do
1707
+ @envelopes.size.should eq 0
1708
+ @error_envelopes.size.should eq 1
1709
+ @error_envelopes.first.response_message.should eq 'Sent'
1710
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
1711
+ @error_envelopes.first.status.should eq 500
1712
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1713
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1714
+ @error_envelopes.first.timetoken.blank?.should eq false
1715
+ end
1716
+
1717
+ end
1718
+ end
1719
+ end
1720
+
1721
+ context 'its synchronous' do
1722
+ it 'handles non200 response gracefully' do
1723
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-non200-valid', :record => :none) do
1724
+
1725
+ @pubnub.publish(
1726
+ :message => {:text => 'sometext'},
1727
+ :channel => 'ruby_demo_channel',
1728
+ :callback => @callback,
1729
+ :http_sync => true
1730
+ )
1731
+
1732
+ @envelopes.size.should eq 0
1733
+ @error_envelopes.size.should eq 1
1734
+ @error_envelopes.first.response_message.should eq 'Sent'
1735
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
1736
+ @error_envelopes.first.status.should eq 500
1737
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1738
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1739
+ @error_envelopes.first.timetoken.blank?.should eq false
1740
+
1741
+ end
1742
+ end
1743
+ end
1744
+ end
1745
+
1746
+ context 'with invalid json' do
1747
+ context 'its asynchronous' do
1748
+ it 'handles invalid json and non200 response gracefully' do
1749
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-non200-invalid', :record => :none) do
1750
+
1751
+ @pubnub.publish(
1752
+ :message => {:text => 'sometext'},
1753
+ :channel => 'ruby_demo_channel',
1754
+ :callback => @callback
1755
+ )
1756
+
1757
+ eventually do
1758
+ @envelopes.size.should eq 0
1759
+ @error_envelopes.size.should eq 1
1760
+ @error_envelopes.first.response_message.should eq nil
1761
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1762
+ @error_envelopes.first.status.should eq 500
1763
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1764
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1765
+ @error_envelopes.first.timetoken.blank?.should eq true
1766
+ end
1767
+
1768
+ end
1769
+ end
1770
+ end
1771
+
1772
+ context 'its synchronous' do
1773
+ it 'handles invalid json and non200 response gracefully' do
1774
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-non200-invalid', :record => :none) do
1775
+
1776
+ @pubnub.publish(
1777
+ :message => {:text => 'sometext'},
1778
+ :channel => 'ruby_demo_channel',
1779
+ :callback => @callback,
1780
+ :http_sync => true
1781
+ )
1782
+
1783
+ @envelopes.size.should eq 0
1784
+ @error_envelopes.size.should eq 1
1785
+ @error_envelopes.first.response_message.should eq nil
1786
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1787
+ @error_envelopes.first.status.should eq 500
1788
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1789
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1790
+ @error_envelopes.first.timetoken.blank?.should eq true
1791
+
1792
+ end
1793
+ end
1794
+ end
1795
+ end
1796
+ end
1797
+ end
1798
+ end
1799
+ end
1800
+
1801
+ context 'when gets message as' do
1802
+ context 'array of hashes' do
1803
+ context 'and its plain' do
1804
+ it 'publishes it correctly' do
1805
+ @pubnub = Pubnub.new(
1806
+ :max_retries => 0,
1807
+ :subscribe_key => :demo,
1808
+ :publish_key => :demo,
1809
+ :secret_key => 'some_secret_key',
1810
+ :error_callback => @error_callback,
1811
+ :disable_persistent_connection => true
1812
+ )
1813
+
1814
+ @pubnub.uuid = 'tester'
1815
+
1816
+ msg = [{:a => 1}, {:b => 2}, :c => [1,2,3]]
1817
+
1818
+ VCR.use_cassette('new_ones/publish/publish-plain-array-of-hashes', :record => :none) do
1819
+
1820
+ @pubnub.publish(
1821
+ :message => msg,
1822
+ :channel => 'ruby_demo_channel',
1823
+ :callback => @callback
1824
+ )
1825
+
1826
+ eventually do
1827
+ @envelopes.size.should eq 1
1828
+ @envelopes.first.response_message.should eq 'Sent'
1829
+ @envelopes.first.status.should eq 200
1830
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1831
+ @envelopes.first.message.should eq(msg)
1832
+ @envelopes.first.timetoken.blank?.should eq false
1833
+ end
1834
+ end
1835
+
1836
+ end
1837
+ end
1838
+
1839
+ context 'and its encrypted' do
1840
+ it 'publishes it correctly' do
1841
+ @pubnub = Pubnub.new(
1842
+ :max_retries => 0,
1843
+ :subscribe_key => :demo,
1844
+ :publish_key => :demo,
1845
+ :secret_key => 'some_secret_key',
1846
+ :cipher_key => 'secret',
1847
+ :error_callback => @error_callback,
1848
+ :ssl => true,
1849
+ :disable_persistent_connection => true
1850
+ )
1851
+
1852
+ @pubnub.uuid = 'tester'
1853
+
1854
+ msg = [{:a => 1}, {:b => 2}, :c => [1,2,3]]
1855
+
1856
+ VCR.use_cassette('new_ones/publish/publish-encrypted-array-of-hashes', :record => :none) do
1857
+
1858
+ @pubnub.publish(
1859
+ :message => msg,
1860
+ :channel => 'ruby_demo_channel',
1861
+ :callback => @callback
1862
+ )
1863
+
1864
+ eventually do
1865
+ @envelopes.size.should eq 1
1866
+ @envelopes.first.response_message.should eq 'Sent'
1867
+ @envelopes.first.status.should eq 200
1868
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1869
+ @envelopes.first.message.should eq(msg)
1870
+ @envelopes.first.timetoken.blank?.should eq false
1871
+ end
1872
+ end
1873
+ end
1874
+ end
1875
+ end
1876
+ end
1877
+ end