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,557 @@
1
+ require 'spec_helper'
2
+
3
+ describe "#presence" do
4
+ before(:each) do
5
+
6
+ EM.stop if EM.reactor_running?
7
+ while EM.reactor_running? do end
8
+ sleep(0.1)
9
+
10
+ @response_output = StringIO.new
11
+ @message_output = StringIO.new
12
+
13
+ @callback = lambda { |envelope|
14
+ $logger.debug 'FIRING CALLBACK FROM TEST'
15
+ @response_output.write envelope.response
16
+ @message_output.write envelope.msg
17
+ @after_callback = true
18
+ }
19
+
20
+ @error_callback = lambda { |envelope|
21
+ $logger.debug 'FIRING ERROR CALLBACK FROM TEST'
22
+ @response_output.write envelope.response
23
+ @message_output.write envelope.msg
24
+ @after_error_callback = true
25
+ }
26
+
27
+ @pn = Pubnub.new(:disable_persistent_connection => true, :max_retries => 0, :subscribe_key => 'demo-36', :publish_key => 'demo-36', :auth_key => :demoish_authkey, :secret_key => 'some_secret_key', :error_callback => @error_callback)
28
+ @pn.uuid = 'rubytests'
29
+
30
+ end
31
+ context "uses ssl" do
32
+ before(:each) { @ssl = true }
33
+ context "passess callback as block" do
34
+ context "gets valid json in response" do
35
+ context "gets status 200 in response" do
36
+ context "uses sync connection" do
37
+ it 'works fine' do
38
+ VCR.use_cassette("v3-presence-ssl-block-valid-200-sync", :record => :none) do
39
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
40
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
41
+
42
+ @after_callback.should eq true
43
+ @response_output.seek 0
44
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
45
+ @message_output.seek 0
46
+ @message_output.read.should eq '{"action"=>"join", "timestamp"=>1396891554, "uuid"=>"a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy"=>1}'
47
+ end
48
+ end
49
+ end
50
+ context "uses async connection" do
51
+ it 'works fine' do
52
+ VCR.use_cassette("v3-presence-ssl-block-valid-200-async", :record => :none) do
53
+ @pn.presence(:ssl => true, :http_sync => false, :channel => "demo", &@callback)
54
+
55
+ eventually do
56
+ @after_callback.should eq true
57
+ @response_output.seek 0
58
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
59
+ @message_output.seek 0
60
+ @message_output.read.should eq '{"action"=>"join", "timestamp"=>1396891554, "uuid"=>"a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy"=>1}'
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ context "gets status non-200 in response" do
67
+ context "uses sync connection" do
68
+ it 'works fine' do
69
+ VCR.use_cassette("v3-presence-ssl-block-valid-non-200-sync", :record => :none) do
70
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
71
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
72
+
73
+ @after_error_callback.should eq true
74
+ @response_output.seek 0
75
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
76
+ @message_output.seek 0
77
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
78
+ end
79
+ end
80
+ end
81
+ context "uses async connection" do
82
+ it 'works fine' do
83
+ VCR.use_cassette("v3-presence-ssl-block-valid-non-200-async", :record => :none) do
84
+ @pn.presence(:ssl => true, :http_sync => false, :channel => "demo", &@callback)
85
+
86
+ eventually do
87
+ @after_error_callback.should eq true
88
+ @response_output.seek 0
89
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
90
+ @message_output.seek 0
91
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ context "gets invalid json in response" do
99
+ context "gets status 200 in response" do
100
+ context "uses sync connection" do
101
+ it 'works fine' do
102
+ VCR.use_cassette("v3-presence-ssl-block-invalid-200-sync", :record => :none) do
103
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
104
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
105
+
106
+ @after_error_callback.should eq true
107
+ @response_output.seek 0
108
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
109
+ @message_output.seek 0
110
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
111
+ end
112
+ end
113
+ end
114
+ context "uses async connection" do
115
+ it 'works fine' do
116
+ VCR.use_cassette("v3-presence-ssl-block-invalid-200-async", :record => :none) do
117
+ @pn.presence(:ssl => true, :http_sync => false, :channel => "demo", &@callback)
118
+
119
+ eventually do
120
+ @after_error_callback.should eq true
121
+ @response_output.seek 0
122
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
123
+ @message_output.seek 0
124
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+ context "gets status non-200 in response" do
131
+ context "uses sync connection" do
132
+ it 'works fine' do
133
+ VCR.use_cassette("v3-presence-ssl-block-invalid-non-200-sync", :record => :none) do
134
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
135
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", &@callback)
136
+
137
+ @after_error_callback.should eq true
138
+ @response_output.seek 0
139
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
140
+ @message_output.seek 0
141
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
142
+ end
143
+ end
144
+ end
145
+ context "uses async connection" do
146
+ it 'works fine' do
147
+ VCR.use_cassette("v3-presence-ssl-block-invalid-non-200-async", :record => :none) do
148
+ @pn.presence(:ssl => true, :http_sync => false, :channel => "demo", &@callback)
149
+
150
+ eventually do
151
+ @after_error_callback.should eq true
152
+ @response_output.seek 0
153
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
154
+ @message_output.seek 0
155
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
163
+ context "passess callback as parameter" do
164
+ context "gets valid json in response" do
165
+ context "gets status 200 in response" do
166
+ context "uses sync connection" do
167
+ it 'works fine' do
168
+ VCR.use_cassette("v3-presence-ssl-parameter-valid-200-sync", :record => :none) do
169
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
170
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
171
+
172
+ @after_callback.should eq true
173
+ @response_output.seek 0
174
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
175
+ @message_output.seek 0
176
+ @message_output.read.should eq '{"action"=>"join", "timestamp"=>1396891554, "uuid"=>"a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy"=>1}'
177
+ end
178
+ end
179
+ end
180
+ context "uses async connection" do
181
+ it 'works fine' do
182
+ VCR.use_cassette("v3-presence-ssl-parameter-valid-200-async", :record => :none) do
183
+ @pn.presence(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
184
+
185
+ eventually do
186
+ @after_callback.should eq true
187
+ @response_output.seek 0
188
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
189
+ @message_output.seek 0
190
+ @message_output.read.should eq '{"action"=>"join", "timestamp"=>1396891554, "uuid"=>"a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy"=>1}'
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
196
+ context "gets status non-200 in response" do
197
+ context "uses sync connection" do
198
+ it 'works fine' do
199
+ VCR.use_cassette("v3-presence-ssl-parameter-valid-non-200-sync", :record => :none) do
200
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
201
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
202
+
203
+ @after_error_callback.should eq true
204
+ @response_output.seek 0
205
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
206
+ @message_output.seek 0
207
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
208
+ end
209
+ end
210
+ end
211
+ context "uses async connection" do
212
+ it 'works fine' do
213
+ VCR.use_cassette("v3-presence-ssl-parameter-valid-non-200-async", :record => :none) do
214
+ @pn.presence(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
215
+
216
+ eventually do
217
+ @after_error_callback.should eq true
218
+ @response_output.seek 0
219
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
220
+ @message_output.seek 0
221
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
222
+ end
223
+ end
224
+ end
225
+ end
226
+ end
227
+ end
228
+ context "gets invalid json in response" do
229
+ context "gets status 200 in response" do
230
+ context "uses sync connection" do
231
+ it 'works fine' do
232
+ VCR.use_cassette("v3-presence-ssl-parameter-invalid-200-sync", :record => :none) do
233
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
234
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
235
+
236
+ @after_error_callback.should eq true
237
+ @response_output.seek 0
238
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
239
+ @message_output.seek 0
240
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
241
+ end
242
+ end
243
+ end
244
+ context "uses async connection" do
245
+ it 'works fine' do
246
+ VCR.use_cassette("v3-presence-ssl-parameter-invalid-200-async", :record => :none) do
247
+ @pn.presence(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
248
+
249
+ eventually do
250
+ @after_error_callback.should eq true
251
+ @response_output.seek 0
252
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
253
+ @message_output.seek 0
254
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
255
+ end
256
+ end
257
+ end
258
+ end
259
+ end
260
+ context "gets status non-200 in response" do
261
+ context "uses sync connection" do
262
+ it 'works fine' do
263
+ VCR.use_cassette("v3-presence-ssl-parameter-invalid-non-200-sync", :record => :none) do
264
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
265
+ @pn.presence(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
266
+
267
+ @after_error_callback.should eq true
268
+ @response_output.seek 0
269
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
270
+ @message_output.seek 0
271
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
272
+ end
273
+ end
274
+ end
275
+ context "uses async connection" do
276
+ it 'works fine' do
277
+ VCR.use_cassette("v3-presence-ssl-parameter-invalid-non-200-async", :record => :none) do
278
+ @pn.presence(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
279
+
280
+ eventually do
281
+ @after_error_callback.should eq true
282
+ @response_output.seek 0
283
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
284
+ @message_output.seek 0
285
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
286
+ end
287
+ end
288
+ end
289
+ end
290
+ end
291
+ end
292
+ end
293
+ end
294
+ context "uses non-ssl" do
295
+ before(:each) { @ssl = false }
296
+ context "passess callback as block" do
297
+ context "gets valid json in response" do
298
+ context "gets status 200 in response" do
299
+ context "uses sync connection" do
300
+ it 'works fine' do
301
+ VCR.use_cassette("v3-presence-nonssl-block-valid-200-sync", :record => :none) do
302
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
303
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
304
+
305
+ @after_callback.should eq true
306
+ @response_output.seek 0
307
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
308
+ @message_output.seek 0
309
+ @message_output.read.should eq '{"action"=>"join", "timestamp"=>1396891554, "uuid"=>"a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy"=>1}'
310
+ end
311
+ end
312
+ end
313
+ context "uses async connection" do
314
+ it 'works fine' do
315
+ VCR.use_cassette("v3-presence-nonssl-block-valid-200-async", :record => :none) do
316
+ @pn.presence(:ssl => false, :http_sync => false, :channel => "demo", &@callback)
317
+
318
+ eventually do
319
+ @after_callback.should eq true
320
+ @response_output.seek 0
321
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
322
+ @message_output.seek 0
323
+ @message_output.read.should eq '{"action"=>"join", "timestamp"=>1396891554, "uuid"=>"a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy"=>1}'
324
+ end
325
+ end
326
+ end
327
+ end
328
+ end
329
+ context "gets status non-200 in response" do
330
+ context "uses sync connection" do
331
+ it 'works fine' do
332
+ VCR.use_cassette("v3-presence-nonssl-block-valid-non-200-sync", :record => :none) do
333
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
334
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
335
+
336
+ @after_error_callback.should eq true
337
+ @response_output.seek 0
338
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
339
+ @message_output.seek 0
340
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
341
+ end
342
+ end
343
+ end
344
+ context "uses async connection" do
345
+ it 'works fine' do
346
+ VCR.use_cassette("v3-presence-nonssl-block-valid-non-200-async", :record => :none) do
347
+ @pn.presence(:ssl => false, :http_sync => false, :channel => "demo", &@callback)
348
+
349
+ eventually do
350
+ @after_error_callback.should eq true
351
+ @response_output.seek 0
352
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
353
+ @message_output.seek 0
354
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
355
+ end
356
+ end
357
+ end
358
+ end
359
+ end
360
+ end
361
+ context "gets invalid json in response" do
362
+ context "gets status 200 in response" do
363
+ context "uses sync connection" do
364
+ it 'works fine' do
365
+ VCR.use_cassette("v3-presence-nonssl-block-invalid-200-sync", :record => :none) do
366
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
367
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
368
+
369
+ @after_error_callback.should eq true
370
+ @response_output.seek 0
371
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
372
+ @message_output.seek 0
373
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
374
+ end
375
+ end
376
+ end
377
+ context "uses async connection" do
378
+ it 'works fine' do
379
+ VCR.use_cassette("v3-presence-nonssl-block-invalid-200-async", :record => :none) do
380
+ @pn.presence(:ssl => false, :http_sync => false, :channel => "demo", &@callback)
381
+
382
+ eventually do
383
+ @after_error_callback.should eq true
384
+ @response_output.seek 0
385
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
386
+ @message_output.seek 0
387
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
388
+ end
389
+ end
390
+ end
391
+ end
392
+ end
393
+ context "gets status non-200 in response" do
394
+ context "uses sync connection" do
395
+ it 'works fine' do
396
+ VCR.use_cassette("v3-presence-nonssl-block-invalid-non-200-sync", :record => :none) do
397
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
398
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", &@callback)
399
+
400
+ @after_error_callback.should eq true
401
+ @response_output.seek 0
402
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
403
+ @message_output.seek 0
404
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
405
+ end
406
+ end
407
+ end
408
+ context "uses async connection" do
409
+ it 'works fine' do
410
+ VCR.use_cassette("v3-presence-nonssl-block-invalid-non-200-async", :record => :none) do
411
+ @pn.presence(:ssl => false, :http_sync => false, :channel => "demo", &@callback)
412
+
413
+ eventually do
414
+ @after_error_callback.should eq true
415
+ @response_output.seek 0
416
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
417
+ @message_output.seek 0
418
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
419
+ end
420
+ end
421
+ end
422
+ end
423
+ end
424
+ end
425
+ end
426
+ context "passess callback as parameter" do
427
+ context "gets valid json in response" do
428
+ context "gets status 200 in response" do
429
+ context "uses sync connection" do
430
+ it 'works fine' do
431
+ VCR.use_cassette("v3-presence-nonssl-parameter-valid-200-sync", :record => :none) do
432
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
433
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
434
+
435
+ @after_callback.should eq true
436
+ @response_output.seek 0
437
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
438
+ @message_output.seek 0
439
+ @message_output.read.should eq '{"action"=>"join", "timestamp"=>1396891554, "uuid"=>"a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy"=>1}'
440
+ end
441
+ end
442
+ end
443
+ context "uses async connection" do
444
+ it 'works fine' do
445
+ VCR.use_cassette("v3-presence-nonssl-parameter-valid-200-async", :record => :none) do
446
+ @pn.presence(:ssl => false, :http_sync => false, :channel => "demo", :callback => @callback)
447
+
448
+ eventually do
449
+ @after_callback.should eq true
450
+ @response_output.seek 0
451
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
452
+ @message_output.seek 0
453
+ @message_output.read.should eq '{"action"=>"join", "timestamp"=>1396891554, "uuid"=>"a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy"=>1}'
454
+ end
455
+ end
456
+ end
457
+ end
458
+ end
459
+ context "gets status non-200 in response" do
460
+ context "uses sync connection" do
461
+ it 'works fine' do
462
+ VCR.use_cassette("v3-presence-nonssl-parameter-valid-non-200-sync", :record => :none) do
463
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
464
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
465
+
466
+ @after_error_callback.should eq true
467
+ @response_output.seek 0
468
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
469
+ @message_output.seek 0
470
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
471
+ end
472
+ end
473
+ end
474
+ context "uses async connection" do
475
+ it 'works fine' do
476
+ VCR.use_cassette("v3-presence-nonssl-parameter-valid-non-200-async", :record => :none) do
477
+ @pn.presence(:ssl => false, :http_sync => false, :channel => "demo", :callback => @callback)
478
+
479
+ eventually do
480
+ @after_error_callback.should eq true
481
+ @response_output.seek 0
482
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"]'
483
+ @message_output.seek 0
484
+ @message_output.read.should eq '[0,"Non 2xx server response."]'
485
+ end
486
+ end
487
+ end
488
+ end
489
+ end
490
+ end
491
+ context "gets invalid json in response" do
492
+ context "gets status 200 in response" do
493
+ context "uses sync connection" do
494
+ it 'works fine' do
495
+ VCR.use_cassette("v3-presence-nonssl-parameter-invalid-200-sync", :record => :none) do
496
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
497
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
498
+
499
+ @after_error_callback.should eq true
500
+ @response_output.seek 0
501
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
502
+ @message_output.seek 0
503
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
504
+ end
505
+ end
506
+ end
507
+ context "uses async connection" do
508
+ it 'works fine' do
509
+ VCR.use_cassette("v3-presence-nonssl-parameter-invalid-200-async", :record => :none) do
510
+ @pn.presence(:ssl => false, :http_sync => false, :channel => "demo", :callback => @callback)
511
+
512
+ eventually do
513
+ @after_error_callback.should eq true
514
+ @response_output.seek 0
515
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
516
+ @message_output.seek 0
517
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
518
+ end
519
+ end
520
+ end
521
+ end
522
+ end
523
+ context "gets status non-200 in response" do
524
+ context "uses sync connection" do
525
+ it 'works fine' do
526
+ VCR.use_cassette("v3-presence-nonssl-parameter-invalid-non-200-sync", :record => :none) do
527
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
528
+ @pn.presence(:ssl => false, :http_sync => true, :channel => "demo", :callback => @callback)
529
+
530
+ @after_error_callback.should eq true
531
+ @response_output.seek 0
532
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
533
+ @message_output.seek 0
534
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
535
+ end
536
+ end
537
+ end
538
+ context "uses async connection" do
539
+ it 'works fine' do
540
+ VCR.use_cassette("v3-presence-nonssl-parameter-invalid-non-200-async", :record => :none) do
541
+ @pn.presence(:ssl => false, :http_sync => false, :channel => "demo", :callback => @callback)
542
+
543
+ eventually do
544
+ @after_error_callback.should eq true
545
+ @response_output.seek 0
546
+ @response_output.read.should eq '[[{"action": "join", "timestamp": 1396891554, "uuid": "a1259d2d-7a7c-485f-8076-028a327e976d", "occupancy": 1}],"13968915543625014"'
547
+ @message_output.seek 0
548
+ @message_output.read.should eq '[0,"Invalid JSON in response."]'
549
+ end
550
+ end
551
+ end
552
+ end
553
+ end
554
+ end
555
+ end
556
+ end
557
+ end