pubnub 3.5.14 → 3.6.7

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.

Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/3.5_to_3.6_upgrade_notes.md +148 -0
  3. data/{CHANGELOG → CHANGELOG.txt} +15 -0
  4. data/Gemfile.lock +5 -4
  5. data/LICENSE.txt +28 -0
  6. data/README.md +164 -19
  7. data/Rakefile +1 -6
  8. data/examples/demo_console.rb +370 -329
  9. data/fixtures/vcr_cassettes/grant-multiple-channels-presence-multi-1.yml +44 -0
  10. data/fixtures/vcr_cassettes/grant-multiple-channels-presence-multi-2.yml +44 -0
  11. data/fixtures/vcr_cassettes/grant-multiple-channels-presence-multi-3.yml +44 -0
  12. data/fixtures/vcr_cassettes/grant-multiple-channels-presence-multi-4.yml +44 -0
  13. data/fixtures/vcr_cassettes/grant-multiple-channels-presence.yml +44 -0
  14. data/fixtures/vcr_cassettes/heartbeated-subscribe.yml +1 -1
  15. data/fixtures/vcr_cassettes/here_now-nonssl-block-valid-200-async.yml +1 -1
  16. data/fixtures/vcr_cassettes/here_now-nonssl-block-valid-200-sync.yml +1 -1
  17. data/fixtures/vcr_cassettes/here_now-nonssl-block-valid-non-200-async.yml +1 -1
  18. data/fixtures/vcr_cassettes/here_now-nonssl-block-valid-non-200-sync.yml +1 -1
  19. data/fixtures/vcr_cassettes/here_now-nonssl-parameter-valid-200-async.yml +1 -1
  20. data/fixtures/vcr_cassettes/here_now-nonssl-parameter-valid-200-sync.yml +1 -1
  21. data/fixtures/vcr_cassettes/here_now-nonssl-parameter-valid-non-200-async.yml +1 -1
  22. data/fixtures/vcr_cassettes/here_now-nonssl-parameter-valid-non-200-sync.yml +1 -1
  23. data/fixtures/vcr_cassettes/here_now-ssl-block-valid-200-async.yml +1 -1
  24. data/fixtures/vcr_cassettes/here_now-ssl-block-valid-200-sync.yml +1 -1
  25. data/fixtures/vcr_cassettes/here_now-ssl-block-valid-non-200-async.yml +1 -1
  26. data/fixtures/vcr_cassettes/here_now-ssl-block-valid-non-200-sync.yml +1 -1
  27. data/fixtures/vcr_cassettes/here_now-ssl-parameter-valid-200-async.yml +1 -1
  28. data/fixtures/vcr_cassettes/here_now-ssl-parameter-valid-200-sync.yml +1 -1
  29. data/fixtures/vcr_cassettes/here_now-ssl-parameter-valid-non-200-async.yml +1 -1
  30. data/fixtures/vcr_cassettes/here_now-ssl-parameter-valid-non-200-sync.yml +1 -1
  31. data/fixtures/vcr_cassettes/leave-nonssl-block-valid-200-async.yml +1 -1
  32. data/fixtures/vcr_cassettes/leave-nonssl-block-valid-200-sync.yml +1 -1
  33. data/fixtures/vcr_cassettes/leave-nonssl-block-valid-non-200-async.yml +1 -1
  34. data/fixtures/vcr_cassettes/leave-nonssl-block-valid-non-200-sync.yml +1 -1
  35. data/fixtures/vcr_cassettes/leave-nonssl-parameter-valid-200-async.yml +1 -1
  36. data/fixtures/vcr_cassettes/leave-nonssl-parameter-valid-200-sync.yml +1 -1
  37. data/fixtures/vcr_cassettes/leave-nonssl-parameter-valid-non-200-async.yml +1 -1
  38. data/fixtures/vcr_cassettes/leave-nonssl-parameter-valid-non-200-sync.yml +1 -1
  39. data/fixtures/vcr_cassettes/leave-ssl-block-valid-200-async.yml +1 -1
  40. data/fixtures/vcr_cassettes/leave-ssl-block-valid-200-sync.yml +1 -1
  41. data/fixtures/vcr_cassettes/leave-ssl-block-valid-non-200-async.yml +1 -1
  42. data/fixtures/vcr_cassettes/leave-ssl-block-valid-non-200-sync.yml +1 -1
  43. data/fixtures/vcr_cassettes/leave-ssl-parameter-valid-200-async.yml +1 -1
  44. data/fixtures/vcr_cassettes/leave-ssl-parameter-valid-200-sync.yml +1 -1
  45. data/fixtures/vcr_cassettes/leave-ssl-parameter-valid-non-200-async.yml +1 -1
  46. data/fixtures/vcr_cassettes/leave-ssl-parameter-valid-non-200-sync.yml +1 -1
  47. data/fixtures/vcr_cassettes/state-async-set-state-via-subbedclient-2.yml +140 -0
  48. data/fixtures/vcr_cassettes/state-async-set-state-via-subbedclient.yml +131 -0
  49. data/fixtures/vcr_cassettes/state-async-set-state-via-subscribe.yml +90 -0
  50. data/fixtures/vcr_cassettes/state-set-state-via-client-2.yml +140 -0
  51. data/fixtures/vcr_cassettes/state-set-state-via-client.yml +90 -0
  52. data/fixtures/vcr_cassettes/state-set-state-via-subscribe.yml +90 -0
  53. data/fixtures/vcr_cassettes/where_now-ssl-block-invalid-200-async.yml +49 -0
  54. data/fixtures/vcr_cassettes/where_now-ssl-block-invalid-200-sync.yml +49 -0
  55. data/fixtures/vcr_cassettes/where_now-ssl-block-invalid-non-200-async.yml +49 -0
  56. data/fixtures/vcr_cassettes/where_now-ssl-block-invalid-non-200-sync.yml +49 -0
  57. data/fixtures/vcr_cassettes/where_now-ssl-block-valid-200-async.yml +49 -0
  58. data/fixtures/vcr_cassettes/where_now-ssl-block-valid-200-sync.yml +49 -0
  59. data/fixtures/vcr_cassettes/where_now-ssl-block-valid-non-200-async.yml +49 -0
  60. data/fixtures/vcr_cassettes/where_now-ssl-block-valid-non-200-sync.yml +49 -0
  61. data/fixtures/vcr_cassettes/where_now-ssl-parameter-invalid-200-async.yml +49 -0
  62. data/fixtures/vcr_cassettes/where_now-ssl-parameter-invalid-200-sync.yml +49 -0
  63. data/fixtures/vcr_cassettes/where_now-ssl-parameter-invalid-non-200-async.yml +49 -0
  64. data/fixtures/vcr_cassettes/where_now-ssl-parameter-invalid-non-200-sync.yml +49 -0
  65. data/fixtures/vcr_cassettes/where_now-ssl-parameter-valid-200-async.yml +49 -0
  66. data/fixtures/vcr_cassettes/where_now-ssl-parameter-valid-200-sync.yml +49 -0
  67. data/fixtures/vcr_cassettes/where_now-ssl-parameter-valid-non-200-async.yml +49 -0
  68. data/fixtures/vcr_cassettes/where_now-ssl-parameter-valid-non-200-sync.yml +49 -0
  69. data/lib/pubnub.rb +1 -2
  70. data/lib/pubnub/client.rb +97 -21
  71. data/lib/pubnub/configuration.rb +1 -1
  72. data/lib/pubnub/envelope.rb +3 -2
  73. data/lib/pubnub/event.rb +9 -5
  74. data/lib/pubnub/events/audit.rb +1 -1
  75. data/lib/pubnub/events/grant.rb +1 -1
  76. data/lib/pubnub/events/heartbeat.rb +7 -3
  77. data/lib/pubnub/events/here_now.rb +7 -4
  78. data/lib/pubnub/events/history.rb +1 -1
  79. data/lib/pubnub/events/leave.rb +10 -4
  80. data/lib/pubnub/events/presence.rb +1 -1
  81. data/lib/pubnub/events/publish.rb +6 -2
  82. data/lib/pubnub/events/revoke.rb +1 -1
  83. data/lib/pubnub/events/set_state.rb +77 -0
  84. data/lib/pubnub/events/state.rb +63 -0
  85. data/lib/pubnub/events/subscribe.rb +7 -0
  86. data/lib/pubnub/events/where_now.rb +55 -0
  87. data/lib/pubnub/pam.rb +10 -16
  88. data/lib/pubnub/version.rb +2 -2
  89. data/pubnub.gemspec +21 -19
  90. data/spec/lib/channel_presence_concat_pam_spec.rb +94 -0
  91. data/spec/lib/client_spec.rb +3 -4
  92. data/spec/lib/heartbeat_spec.rb +16 -16
  93. data/spec/lib/integration/global_here_now_dpc_spec.rb +10 -10
  94. data/spec/lib/integration/global_here_now_spec.rb +8 -8
  95. data/spec/lib/integration/here_now_dpc_spec.rb +24 -24
  96. data/spec/lib/integration/here_now_spec.rb +24 -24
  97. data/spec/lib/integration/leave_dpc_spec.rb +24 -25
  98. data/spec/lib/integration/leave_spec.rb +24 -24
  99. data/spec/lib/integration/publish_spec.rb +5 -0
  100. data/spec/lib/integration/state_spec.rb +84 -0
  101. data/spec/lib/integration/where_now_spec.rb +312 -0
  102. metadata +108 -26
  103. data/LICENSE +0 -27
  104. data/VERSION +0 -1
  105. data/examples/demo_console_new.rb +0 -286
  106. data/fixtures/vcr_cassettes/heartbeat-non200.yml +0 -667
  107. data/spec/tools/pam-test-generator.rb +0 -367
  108. data/spec/tools/test-generator.rb +0 -310
@@ -1,367 +0,0 @@
1
- # Easy to use and non-complex test scaffold generator
2
- # TODO: improve and make rake task?
3
- # BEWARE: It's not fully automated! You have to record VCRs first!
4
- # You can do it by creating some simple tests that will pass by default
5
- # and set :record to :all
6
-
7
- #actions = %w(subscribe publish presence history here_now time leave)
8
- actions = %w(audit grant revoke)
9
- ssl = [true, false]
10
- block_cb = [true, false]
11
- valid_json = [true, false]
12
- status_200 = [true, false]
13
- http_sync = [true, false]
14
-
15
- puts "require 'spec_helper'
16
-
17
- VCR.configure do |c|
18
- c.cassette_library_dir = 'fixtures/vcr_cassettes/pam-test'
19
- c.hook_into :webmock
20
- end"
21
-
22
- actions.each do |action|
23
-
24
- puts "describe \"##{action}\" do"
25
-
26
- puts "before(:each) do
27
- @response_output = StringIO.new
28
- @message_output = StringIO.new
29
-
30
- @callback = lambda { |envelope|
31
- $logger.debug 'FIRING CALLBACK FROM TEST'
32
- @response_output.write envelope.response
33
- @message_output.write envelope.msg
34
- @after_callback = true
35
- if EM.reactor_running? && envelope.is_last?
36
- EM.stop
37
- end
38
- }
39
-
40
- @error_callback = lambda { |envelope|
41
- $logger.debug 'FIRING ERROR CALLBACK FROM TEST'
42
- @response_output.write envelope.response
43
- @message_output.write envelope.msg
44
- @after_error_callback = true
45
- if EM.reactor_running? && envelope.is_last?
46
- EM.stop
47
- end
48
- }
49
-
50
- @pn = Pubnub.new(:max_retries => 0, :subscribe_key => 'sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe', :publish_key => 'pub-c-15d6fd3c-05de-4abc-8eba-6595a441959d', :secret_key => 'sec-c-ZWYwMGJiZTYtMTQwMC00NDQ5LWI0NmEtMzZiM2M5NThlOTJh', :error_callback => @error_callback)
51
- @pn.uuid = 'f0ac67ef-912f-4797-be67-a59745107306'
52
-
53
- Pubnub::Client.any_instance.stub(:current_time).and_return 1234567890
54
- Pubnub::Client.any_instance.stub(:get_signature).and_return 'kdDh/sFC3rSR%2Bt5AEymIc57d1velIr562V7usa5M4k0='
55
-
56
- end"
57
-
58
- ssl.each do |ssl|
59
- puts "context \"uses #{ssl ? 'ssl' : 'non-ssl'}\" do"
60
- puts "before(:each) { @ssl = #{ssl.to_s} }"
61
- block_cb.each do |block_cb|
62
- puts "context \"passess callback as #{block_cb ? 'block' : 'parameter'}\" do"
63
- valid_json.each do |valid_json|
64
- puts "context \"gets #{valid_json ? 'valid' : 'invalid'} json in response\" do"
65
- status_200.each do |status_200|
66
- puts "context \"gets status #{status_200 ? '200' : 'non-200'} in response\" do"
67
- http_sync.each do |http_sync|
68
- puts "context \"uses #{http_sync ? 'sync' : 'async'} connection\" do"
69
- puts "it 'works fine' do"
70
- puts "VCR.use_cassette(\"#{action}-#{ssl ? 'ssl' : 'nonssl'}-#{block_cb ? 'block' : 'parameter'}-#{valid_json ? 'valid' : 'invalid'}-#{status_200 ? '200' : 'non-200'}-#{http_sync ? 'sync' : 'async'}\", :record => :none) do"
71
-
72
- # Default options for every action
73
- options = {
74
- :ssl => ssl,
75
- :http_sync => http_sync
76
- }
77
-
78
- # Let's add some specific parameters for some actions
79
- merge = case action #subscribe publish presence history here_now time leave revoke audit grant
80
- when 'subscribe'
81
- {
82
- :channel => 'demo'
83
- }
84
- when 'publish'
85
- {
86
- :channel => 'demo',
87
- :message => {:text => 'hey'}
88
- }
89
- when 'presence'
90
- {
91
- :channel => 'demo'
92
- }
93
- when 'history'
94
- {
95
- :channel => 'demo'
96
- }
97
- when 'here_now'
98
- {
99
- :channel => 'demo'
100
- }
101
- when 'time'
102
- {}
103
- when 'leave'
104
- {
105
- :channel => 'demo'
106
- }
107
- when 'revoke'
108
- {
109
- :channel => 'demo',
110
- :auth_key => 'authkey',
111
- :write => true,
112
- :read => true
113
- }
114
- when 'audit'
115
- {
116
- :channel => 'demo',
117
- :auth_key => 'authkey'
118
- }
119
- when 'grant'
120
- {
121
- :channel => 'demo',
122
- :auth_key => 'authkey',
123
- :write => true,
124
- :read => true
125
- }
126
-
127
- end
128
- options.merge!(merge)
129
-
130
- # Cuts {}
131
- inspected = options.inspect[1...options.inspect.size-1]
132
-
133
- # Add to options callback as block or parameter
134
- inspected << ', :callback => @callback' unless block_cb
135
- inspected << ', &@callback' if block_cb
136
-
137
- puts "@pn.#{action}(#{inspected})"
138
- #puts "@pn.#{action}(#{inspected})" if http_sync && (action == 'subscribe' || action == 'presence')
139
- #
140
- ## Infinite loop until reactor is down so test will wait for callback TODO: improve to fail after some time so it won't hang
141
- puts "while EM.reactor_running? do end"
142
-
143
- puts "@after_callback.should eq true" if valid_json && status_200
144
- puts "@after_error_callback.should eq true" if !valid_json || !status_200
145
-
146
- # Determine messages in output
147
- case action
148
- when 'here_now'
149
- if valid_json
150
- puts "@response_output.seek 0"
151
- puts "@response_output.read.should eq '{\"uuids\":[\"rubytests\"],\"occupancy\":1}'"
152
- if status_200
153
- puts "@message_output.seek 0"
154
- puts "@message_output.read.should eq '{\"uuids\"=>[\"rubytests\"], \"occupancy\"=>1}'"
155
- else
156
- puts "@message_output.seek 0"
157
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
158
- end
159
- else
160
- puts "@response_output.seek 0"
161
- puts "@response_output.read.should eq '{\"uuids\":[\"rubytests\"],\"occupancy\":1'"
162
-
163
- puts "@message_output.seek 0"
164
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
165
- end
166
-
167
- when 'history'
168
- if valid_json
169
- if status_200
170
- puts "@response_output.seek 0"
171
- puts "@response_output.read.should eq ('[[{\"text\":\"hey\"},{\"text\":\"howdy\"},{\"text\":\"hello\"}],13904298660188334,13904300138214858]'*3)"
172
-
173
- puts "@message_output.seek 0"
174
- puts "@message_output.read.should eq '{\"text\"=>\"hey\"}{\"text\"=>\"howdy\"}{\"text\"=>\"hello\"}'"
175
- else
176
- puts "@response_output.seek 0"
177
- puts "@response_output.read.should eq '[[{\"text\":\"hey\"},{\"text\":\"howdy\"},{\"text\":\"hello\"}],13904298660188334,13904300138214858]'"
178
-
179
- puts "@message_output.seek 0"
180
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
181
- end
182
- else
183
- puts "@response_output.seek 0"
184
- puts "@response_output.read.should eq '[[{\"text\":\"hey'"
185
-
186
- puts "@message_output.seek 0"
187
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
188
- end
189
-
190
- when 'leave'
191
- if valid_json
192
- puts "@response_output.seek 0"
193
- puts "@response_output.read.should eq '{\"action\": \"leave\"}'"
194
- if status_200
195
- puts "@message_output.seek 0"
196
- puts "@message_output.read.should eq '{\"action\"=>\"leave\"}'"
197
- else
198
- puts "@message_output.seek 0"
199
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
200
- end
201
- else
202
- puts "@response_output.seek 0"
203
- puts "@response_output.read.should eq '{\"action\": \"leav'"
204
-
205
- puts "@message_output.seek 0"
206
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
207
- end
208
-
209
- when 'presence'
210
- if valid_json
211
- if status_200
212
- puts "@response_output.seek 0"
213
- puts "@response_output.read.should eq '[[{\"action\": \"leave\", \"timestamp\": 1390430008, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\": 1},{\"action\": \"join\", \"timestamp\": 1390430008, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\": 2}],\"13904300089348992\"][[{\"action\": \"leave\", \"timestamp\": 1390430008, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\": 1},{\"action\": \"join\", \"timestamp\": 1390430008, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\": 2}],\"13904300089348992\"]'"
214
-
215
- puts "@message_output.seek 0"
216
- puts "@message_output.read.should eq '{\"action\"=>\"leave\", \"timestamp\"=>1390430008, \"uuid\"=>\"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\"=>1}{\"action\"=>\"join\", \"timestamp\"=>1390430008, \"uuid\"=>\"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\"=>2}'"
217
- else
218
- puts "@response_output.seek 0"
219
- puts "@response_output.read.should eq '[[{\"action\": \"leave\", \"timestamp\": 1390430008, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\": 1},{\"action\": \"join\", \"timestamp\": 1390430008, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\": 2}],\"13904300089348992\"]'"
220
-
221
- puts "@message_output.seek 0"
222
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
223
- end
224
- else
225
- puts "@response_output.seek 0"
226
- puts "@response_output.read.should eq '[[{\"action\": \"leave\", \"timestamp\": 1390430067, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\",'"
227
-
228
- puts "@message_output.seek 0"
229
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
230
- end
231
-
232
- when 'publish'
233
- if valid_json
234
- puts "@response_output.seek 0"
235
- puts "@response_output.read.should eq '[1,\"Sent\",\"13904299694449458\"]'"
236
- if status_200
237
- puts "@message_output.seek 0"
238
- puts "@message_output.read.should eq 'Sent'"
239
- else
240
- puts "@message_output.seek 0"
241
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
242
- end
243
- else
244
- puts "@response_output.seek 0"
245
- puts "@response_output.read.should eq '[1,\"Sent\",\"'"
246
-
247
- puts "@message_output.seek 0"
248
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
249
- end
250
-
251
- when 'subscribe'
252
- if valid_json
253
- if status_200
254
- puts "@response_output.seek 0"
255
- puts "@response_output.read.should eq '[[{\"text\":\"hey\"},{\"text\":\"hey\"}],\"13904299332319098\"][[{\"text\":\"hey\"},{\"text\":\"hey\"}],\"13904299332319098\"]'"
256
-
257
- puts "@message_output.seek 0"
258
- puts "@message_output.read.should eq '{\"text\"=>\"hey\"}{\"text\"=>\"hey\"}'"
259
- else
260
- puts "@response_output.seek 0"
261
- puts "@response_output.read.should eq '[[{\"text\":\"hey\"},{\"text\":\"hey\"}],\"13904299332319098\"]'"
262
-
263
- puts "@message_output.seek 0"
264
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
265
- end
266
- else
267
- puts "@response_output.seek 0"
268
- puts "@response_output.read.should eq '[[{\"text\":\"hey\"},{\"text\":\"hey\"}],\"'"
269
-
270
- puts "@message_output.seek 0"
271
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
272
- end
273
-
274
- when 'time'
275
- if valid_json
276
- puts "@response_output.seek 0"
277
- puts "@response_output.read.should eq '[13904301930718907]'"
278
- if status_200
279
- puts "@message_output.seek 0"
280
- puts "@message_output.read.should eq '13904301930718907'"
281
- else
282
- puts "@message_output.seek 0"
283
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
284
- end
285
- else
286
- puts "@response_output.seek 0"
287
- puts "@response_output.read.should eq '[13904301869920523'"
288
-
289
- puts "@message_output.seek 0"
290
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
291
- end
292
-
293
- when 'audit'
294
- if valid_json
295
- puts "@response_output.seek 0"
296
- puts "@response_output.read.should eq '{\"status\":200,\"message\":\"Success\",\"payload\":{\"auths\":{},\"subscribe_key\":\"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe\",\"channel\":\"demo\",\"level\":\"user\"},\"service\":\"Access Manager\"}'"
297
- if status_200
298
- puts "@message_output.seek 0"
299
- puts "@message_output.read.should eq 'Success'"
300
- else
301
- puts "@message_output.seek 0"
302
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
303
- end
304
- else
305
- puts "@response_output.seek 0"
306
- puts "@response_output.read.should eq '{\"status\":200,'"
307
-
308
- puts "@message_output.seek 0"
309
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
310
- end
311
-
312
- when 'grant'
313
- if valid_json
314
- puts "@response_output.seek 0"
315
- puts "@response_output.read.should eq '{\"status\":200,\"message\":\"Success\",\"payload\":{\"auths\":{\"authkey\":{\"r\":1,\"w\":1}},\"subscribe_key\":\"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe\",\"ttl\":3600,\"channel\":\"demo\",\"level\":\"user\"},\"service\":\"Access Manager\"}'"
316
- if status_200
317
- puts "@message_output.seek 0"
318
- puts "@message_output.read.should eq 'Success'"
319
- else
320
- puts "@message_output.seek 0"
321
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
322
- end
323
- else
324
- puts "@response_output.seek 0"
325
- puts "@response_output.read.should eq '{\"status\":200,'"
326
-
327
- puts "@message_output.seek 0"
328
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
329
- end
330
-
331
- when 'revoke'
332
- if valid_json
333
- puts "@response_output.seek 0"
334
- puts "@response_output.read.should eq '{\"status\":200,\"message\":\"Success\",\"payload\":{\"auths\":{\"authkey\":{\"r\":0,\"w\":0}},\"subscribe_key\":\"sub-c-53c3d30a-4135-11e3-9970-02ee2ddab7fe\",\"ttl\":1,\"channel\":\"demo\",\"level\":\"user\"},\"service\":\"Access Manager\"}'"
335
- if status_200
336
- puts "@message_output.seek 0"
337
- puts "@message_output.read.should eq 'Success'"
338
- else
339
- puts "@message_output.seek 0"
340
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
341
- end
342
- else
343
- puts "@response_output.seek 0"
344
- puts "@response_output.read.should eq '{\"status\":200,'"
345
-
346
- puts "@message_output.seek 0"
347
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
348
- end
349
-
350
- end
351
-
352
-
353
-
354
- puts "end"
355
- puts "end"
356
- puts "end"
357
- end
358
- puts "end"
359
- end
360
- puts "end"
361
- end
362
- puts "end"
363
- end
364
- puts "end"
365
- end
366
- puts "end"
367
- end
@@ -1,310 +0,0 @@
1
- # Easy to use and non-complex test scaffold generator
2
- # TODO: improve and make rake task?
3
- # BEWARE: It's not fully automated! You have to record VCRs first!
4
- # You can do it by creating some simple tests that will pass by default
5
- # and set :record to :all
6
-
7
- actions = %w(subscribe publish presence history here_now time leave)
8
- #actions = %w(revoke audit grant)
9
- ssl = [true, false]
10
- block_cb = [true, false]
11
- valid_json = [true, false]
12
- status_200 = [true, false]
13
- http_sync = [true, false]
14
-
15
- puts "require 'spec_helper'
16
-
17
- VCR.configure do |c|
18
- c.cassette_library_dir = 'fixtures/vcr_cassettes/test'
19
- c.hook_into :webmock
20
- end"
21
-
22
- actions.each do |action|
23
-
24
- puts "describe \"##{action}\" do"
25
-
26
- puts "before(:each) do
27
- @response_output = StringIO.new
28
- @message_output = StringIO.new
29
-
30
- @callback = lambda { |envelope|
31
- $logger.debug 'FIRING CALLBACK FROM TEST'
32
- @response_output.write envelope.response
33
- @message_output.write envelope.msg
34
- @after_callback = true
35
- if EM.reactor_running? && envelope.is_last?
36
- EM.stop
37
- end
38
- }
39
-
40
- @error_callback = lambda { |envelope|
41
- $logger.debug 'FIRING ERROR CALLBACK FROM TEST'
42
- @response_output.write envelope.response
43
- @message_output.write envelope.msg
44
- @after_error_callback = true
45
- if EM.reactor_running? && envelope.is_last?
46
- EM.stop
47
- end
48
- }
49
-
50
- @pn = Pubnub.new(:max_retries => 0, :subscribe_key => :demo, :publish_key => :demo, :auth_key => :demoish_authkey, :secret_key => 'some_secret_key', :error_callback => @error_callback)
51
- @pn.uuid = 'rubytests'
52
-
53
- end"
54
-
55
- ssl.each do |ssl|
56
- puts "context \"uses #{ssl ? 'ssl' : 'non-ssl'}\" do"
57
- puts "before(:each) { @ssl = #{ssl.to_s} }"
58
- block_cb.each do |block_cb|
59
- puts "context \"passess callback as #{block_cb ? 'block' : 'parameter'}\" do"
60
- valid_json.each do |valid_json|
61
- puts "context \"gets #{valid_json ? 'valid' : 'invalid'} json in response\" do"
62
- status_200.each do |status_200|
63
- puts "context \"gets status #{status_200 ? '200' : 'non-200'} in response\" do"
64
- http_sync.each do |http_sync|
65
- puts "context \"uses #{http_sync ? 'sync' : 'async'} connection\" do"
66
- puts "it 'works fine' do"
67
- puts "VCR.use_cassette(\"#{action}-#{ssl ? 'ssl' : 'nonssl'}-#{block_cb ? 'block' : 'parameter'}-#{valid_json ? 'valid' : 'invalid'}-#{status_200 ? '200' : 'non-200'}-#{http_sync ? 'sync' : 'async'}\", :record => :none) do"
68
-
69
- # Default options for every action
70
- options = {
71
- :ssl => ssl,
72
- :http_sync => http_sync
73
- }
74
-
75
- # Let's add some specific parameters for some actions
76
- merge = case action #subscribe publish presence history here_now time leave revoke audit grant
77
- when 'subscribe'
78
- {
79
- :channel => 'demo'
80
- }
81
- when 'publish'
82
- {
83
- :channel => 'demo',
84
- :message => {:text => 'hey'}
85
- }
86
- when 'presence'
87
- {
88
- :channel => 'demo'
89
- }
90
- when 'history'
91
- {
92
- :channel => 'demo'
93
- }
94
- when 'here_now'
95
- {
96
- :channel => 'demo'
97
- }
98
- when 'time'
99
- {}
100
- when 'leave'
101
- {
102
- :channel => 'demo'
103
- }
104
- when 'revoke'
105
- {
106
- :channel => 'demo',
107
- :auth_key => 'authkey',
108
- :write => true,
109
- :read => true
110
- }
111
- when 'audit'
112
- {
113
- :channel => 'demo',
114
- :auth_key => 'authkey'
115
- }
116
- when 'grant'
117
- {
118
- :channel => 'demo',
119
- :auth_key => 'authkey',
120
- :write => true,
121
- :read => true
122
- }
123
-
124
- end
125
- options.merge!(merge)
126
-
127
- # Cuts {}
128
- inspected = options.inspect[1...options.inspect.size-1]
129
-
130
- # Add to options callback as block or parameter
131
- inspected << ', :callback => @callback' unless block_cb
132
- inspected << ', &@callback' if block_cb
133
-
134
- puts "@pn.#{action}(#{inspected})"
135
- puts "@pn.#{action}(#{inspected})" if http_sync && (action == 'subscribe' || action == 'presence')
136
-
137
- # Infinite loop until reactor is down so test will wait for callback TODO: improve to fail after some time so it won't hang
138
- puts "while EM.reactor_running? do end"
139
-
140
- #puts "sleep 10" if action == 'history' && status_200 && valid_json # :( Callback is called for more than one envelope...
141
-
142
- # Determine which callback should be called basing on valid_json and status_2000
143
- puts "@after_callback.should eq true" if valid_json && status_200
144
- puts "@after_error_callback.should eq true" if !valid_json || !status_200
145
-
146
- # Determine messages in output
147
- case action
148
- when 'here_now'
149
- if valid_json
150
- puts "@response_output.seek 0"
151
- puts "@response_output.read.should eq '{\"uuids\":[\"rubytests\"],\"occupancy\":1}'"
152
- if status_200
153
- puts "@message_output.seek 0"
154
- puts "@message_output.read.should eq '{\"uuids\"=>[\"rubytests\"], \"occupancy\"=>1}'"
155
- else
156
- puts "@message_output.seek 0"
157
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
158
- end
159
- else
160
- puts "@response_output.seek 0"
161
- puts "@response_output.read.should eq '{\"uuids\":[\"rubytests\"],\"occupancy\":1'"
162
-
163
- puts "@message_output.seek 0"
164
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
165
- end
166
-
167
- when 'history'
168
- if valid_json
169
- if status_200
170
- puts "@response_output.seek 0"
171
- puts "@response_output.read.should eq ('[[{\"text\":\"hey\"},{\"text\":\"howdy\"},{\"text\":\"hello\"}],13904298660188334,13904300138214858]'*3)"
172
-
173
- puts "@message_output.seek 0"
174
- puts "@message_output.read.should eq '{\"text\"=>\"hey\"}{\"text\"=>\"howdy\"}{\"text\"=>\"hello\"}'"
175
- else
176
- puts "@response_output.seek 0"
177
- puts "@response_output.read.should eq '[[{\"text\":\"hey\"},{\"text\":\"howdy\"},{\"text\":\"hello\"}],13904298660188334,13904300138214858]'"
178
-
179
- puts "@message_output.seek 0"
180
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
181
- end
182
- else
183
- puts "@response_output.seek 0"
184
- puts "@response_output.read.should eq '[[{\"text\":\"hey'"
185
-
186
- puts "@message_output.seek 0"
187
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
188
- end
189
-
190
- when 'leave'
191
- if valid_json
192
- puts "@response_output.seek 0"
193
- puts "@response_output.read.should eq '{\"action\": \"leave\"}'"
194
- if status_200
195
- puts "@message_output.seek 0"
196
- puts "@message_output.read.should eq '{\"action\"=>\"leave\"}'"
197
- else
198
- puts "@message_output.seek 0"
199
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
200
- end
201
- else
202
- puts "@response_output.seek 0"
203
- puts "@response_output.read.should eq '{\"action\": \"leav'"
204
-
205
- puts "@message_output.seek 0"
206
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
207
- end
208
-
209
- when 'presence'
210
- if valid_json
211
- if status_200
212
- puts "@response_output.seek 0"
213
- puts "@response_output.read.should eq '[[{\"action\": \"leave\", \"timestamp\": 1390430008, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\": 1},{\"action\": \"join\", \"timestamp\": 1390430008, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\": 2}],\"13904300089348992\"][[{\"action\": \"leave\", \"timestamp\": 1390430008, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\": 1},{\"action\": \"join\", \"timestamp\": 1390430008, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\": 2}],\"13904300089348992\"]'"
214
-
215
- puts "@message_output.seek 0"
216
- puts "@message_output.read.should eq '{\"action\"=>\"leave\", \"timestamp\"=>1390430008, \"uuid\"=>\"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\"=>1}{\"action\"=>\"join\", \"timestamp\"=>1390430008, \"uuid\"=>\"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\"=>2}'"
217
- else
218
- puts "@response_output.seek 0"
219
- puts "@response_output.read.should eq '[[{\"action\": \"leave\", \"timestamp\": 1390430008, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\": 1},{\"action\": \"join\", \"timestamp\": 1390430008, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\", \"occupancy\": 2}],\"13904300089348992\"]'"
220
-
221
- puts "@message_output.seek 0"
222
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
223
- end
224
- else
225
- puts "@response_output.seek 0"
226
- puts "@response_output.read.should eq '[[{\"action\": \"leave\", \"timestamp\": 1390430067, \"uuid\": \"3bad4360-2b9f-470f-aaf7-dac04454b1fb\",'"
227
-
228
- puts "@message_output.seek 0"
229
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
230
- end
231
-
232
- when 'publish'
233
- if valid_json
234
- puts "@response_output.seek 0"
235
- puts "@response_output.read.should eq '[1,\"Sent\",\"13904299694449458\"]'"
236
- if status_200
237
- puts "@message_output.seek 0"
238
- puts "@message_output.read.should eq 'Sent'"
239
- else
240
- puts "@message_output.seek 0"
241
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
242
- end
243
- else
244
- puts "@response_output.seek 0"
245
- puts "@response_output.read.should eq '[1,\"Sent\",\"'"
246
-
247
- puts "@message_output.seek 0"
248
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
249
- end
250
-
251
- when 'subscribe'
252
- if valid_json
253
- if status_200
254
- puts "@response_output.seek 0"
255
- puts "@response_output.read.should eq '[[{\"text\":\"hey\"},{\"text\":\"hey\"}],\"13904299332319098\"][[{\"text\":\"hey\"},{\"text\":\"hey\"}],\"13904299332319098\"]'"
256
-
257
- puts "@message_output.seek 0"
258
- puts "@message_output.read.should eq '{\"text\"=>\"hey\"}{\"text\"=>\"hey\"}'"
259
- else
260
- puts "@response_output.seek 0"
261
- puts "@response_output.read.should eq '[[{\"text\":\"hey\"},{\"text\":\"hey\"}],\"13904299332319098\"]'"
262
-
263
- puts "@message_output.seek 0"
264
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
265
- end
266
- else
267
- puts "@response_output.seek 0"
268
- puts "@response_output.read.should eq '[[{\"text\":\"hey\"},{\"text\":\"hey\"}],\"'"
269
-
270
- puts "@message_output.seek 0"
271
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
272
- end
273
-
274
- when 'time'
275
- if valid_json
276
- puts "@response_output.seek 0"
277
- puts "@response_output.read.should eq '[13904301930718907]'"
278
- if status_200
279
- puts "@message_output.seek 0"
280
- puts "@message_output.read.should eq '13904301930718907'"
281
- else
282
- puts "@message_output.seek 0"
283
- puts "@message_output.read.should eq '[0,\"Non 2xx server response.\"]'"
284
- end
285
- else
286
- puts "@response_output.seek 0"
287
- puts "@response_output.read.should eq '[13904301869920523'"
288
-
289
- puts "@message_output.seek 0"
290
- puts "@message_output.read.should eq '[0,\"Invalid JSON in response.\"]'"
291
- end
292
-
293
- end
294
-
295
-
296
-
297
- puts "end"
298
- puts "end"
299
- puts "end"
300
- end
301
- puts "end"
302
- end
303
- puts "end"
304
- end
305
- puts "end"
306
- end
307
- puts "end"
308
- end
309
- puts "end"
310
- end