rpush 4.2.0 → 7.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +307 -163
  3. data/README.md +105 -19
  4. data/lib/generators/templates/add_adm.rb +1 -1
  5. data/lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb +2 -2
  6. data/lib/generators/templates/add_app_to_rapns.rb +2 -2
  7. data/lib/generators/templates/add_fail_after_to_rpush_notifications.rb +1 -1
  8. data/lib/generators/templates/add_gcm.rb +11 -25
  9. data/lib/generators/templates/add_rpush.rb +33 -83
  10. data/lib/generators/templates/add_wpns.rb +1 -1
  11. data/lib/generators/templates/create_rapns_apps.rb +1 -1
  12. data/lib/generators/templates/create_rapns_feedback.rb +3 -9
  13. data/lib/generators/templates/create_rapns_notifications.rb +3 -9
  14. data/lib/generators/templates/rename_rapns_to_rpush.rb +9 -33
  15. data/lib/generators/templates/rpush.rb +5 -4
  16. data/lib/generators/templates/rpush_2_0_0_updates.rb +10 -18
  17. data/lib/generators/templates/rpush_2_1_0_updates.rb +1 -1
  18. data/lib/generators/templates/rpush_2_6_0_updates.rb +1 -1
  19. data/lib/generators/templates/rpush_2_7_0_updates.rb +1 -1
  20. data/lib/generators/templates/rpush_3_0_0_updates.rb +1 -1
  21. data/lib/generators/templates/rpush_3_0_1_updates.rb +1 -1
  22. data/lib/generators/templates/rpush_3_1_0_add_pushy.rb +1 -1
  23. data/lib/generators/templates/rpush_3_1_1_updates.rb +1 -1
  24. data/lib/generators/templates/rpush_3_2_0_add_apns_p8.rb +1 -1
  25. data/lib/generators/templates/rpush_3_2_4_updates.rb +1 -1
  26. data/lib/generators/templates/rpush_3_3_0_updates.rb +1 -1
  27. data/lib/generators/templates/rpush_3_3_1_updates.rb +3 -3
  28. data/lib/generators/templates/rpush_4_1_0_updates.rb +1 -1
  29. data/lib/generators/templates/rpush_4_1_1_updates.rb +1 -1
  30. data/lib/generators/templates/rpush_4_2_0_updates.rb +1 -1
  31. data/lib/rpush/cli.rb +1 -1
  32. data/lib/rpush/client/active_model/adm/data_validator.rb +1 -1
  33. data/lib/rpush/client/active_model/apns/app.rb +1 -17
  34. data/lib/rpush/client/active_model/apns/device_token_format_validator.rb +2 -2
  35. data/lib/rpush/client/active_model/apns/notification.rb +13 -1
  36. data/lib/rpush/client/active_model/apns/notification_payload_size_validator.rb +15 -0
  37. data/lib/rpush/client/active_model/apns2/app.rb +7 -1
  38. data/lib/rpush/client/active_model/apns2/notification.rb +14 -0
  39. data/lib/rpush/client/active_model/certificate_private_key_validator.rb +19 -0
  40. data/lib/rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +1 -1
  41. data/lib/rpush/client/active_model/gcm/notification.rb +2 -2
  42. data/lib/rpush/client/active_model/payload_data_size_validator.rb +1 -1
  43. data/lib/rpush/client/active_model/registration_ids_count_validator.rb +1 -1
  44. data/lib/rpush/client/active_model/webpush/app.rb +41 -0
  45. data/lib/rpush/client/active_model/webpush/notification.rb +66 -0
  46. data/lib/rpush/client/active_model.rb +5 -1
  47. data/lib/rpush/client/active_record/apns/active_record_serializable_notification.rb +65 -0
  48. data/lib/rpush/client/active_record/apns/notification.rb +1 -57
  49. data/lib/rpush/client/active_record/apns2/notification.rb +4 -1
  50. data/lib/rpush/client/active_record/apnsp8/notification.rb +1 -0
  51. data/lib/rpush/client/active_record/webpush/app.rb +11 -0
  52. data/lib/rpush/client/active_record/webpush/notification.rb +12 -0
  53. data/lib/rpush/client/active_record.rb +4 -0
  54. data/lib/rpush/client/redis/apns2/notification.rb +1 -0
  55. data/lib/rpush/client/redis/apnsp8/notification.rb +2 -0
  56. data/lib/rpush/client/redis/pushy/notification.rb +0 -1
  57. data/lib/rpush/client/redis/webpush/app.rb +15 -0
  58. data/lib/rpush/client/redis/webpush/notification.rb +15 -0
  59. data/lib/rpush/client/redis.rb +3 -0
  60. data/lib/rpush/configuration.rb +3 -2
  61. data/lib/rpush/daemon/apns/feedback_receiver.rb +1 -1
  62. data/lib/rpush/daemon/apns2/delivery.rb +14 -2
  63. data/lib/rpush/daemon/apnsp8/delivery.rb +14 -3
  64. data/lib/rpush/daemon/app_runner.rb +1 -1
  65. data/lib/rpush/daemon/batch.rb +12 -5
  66. data/lib/rpush/daemon/delivery.rb +1 -2
  67. data/lib/rpush/daemon/store/active_record/reconnectable.rb +1 -1
  68. data/lib/rpush/daemon/store/active_record.rb +11 -7
  69. data/lib/rpush/daemon/store/redis.rb +6 -6
  70. data/lib/rpush/daemon/string_helpers.rb +1 -1
  71. data/lib/rpush/daemon/webpush/delivery.rb +114 -0
  72. data/lib/rpush/daemon/webpush.rb +10 -0
  73. data/lib/rpush/daemon.rb +4 -1
  74. data/lib/rpush/logger.rb +2 -1
  75. data/lib/rpush/version.rb +3 -3
  76. data/spec/functional/apns2_spec.rb +99 -2
  77. data/spec/functional/gcm_priority_spec.rb +40 -0
  78. data/spec/functional/retry_spec.rb +1 -1
  79. data/spec/functional/webpush_spec.rb +31 -0
  80. data/spec/spec_helper.rb +3 -1
  81. data/spec/support/active_record_setup.rb +4 -3
  82. data/spec/support/config/database.yml +4 -4
  83. data/spec/support/simplecov_helper.rb +2 -2
  84. data/spec/unit/client/active_record/adm/app_spec.rb +2 -54
  85. data/spec/unit/client/active_record/adm/notification_spec.rb +2 -39
  86. data/spec/unit/client/active_record/apns/app_spec.rb +3 -26
  87. data/spec/unit/client/active_record/apns/feedback_spec.rb +1 -5
  88. data/spec/unit/client/active_record/apns/notification_spec.rb +29 -293
  89. data/spec/unit/client/active_record/apns2/app_spec.rb +5 -0
  90. data/spec/unit/client/active_record/apns2/notification_spec.rb +65 -0
  91. data/spec/unit/client/active_record/apnsp8/notification_spec.rb +28 -0
  92. data/spec/unit/client/active_record/app_spec.rb +1 -26
  93. data/spec/unit/client/active_record/gcm/app_spec.rb +3 -1
  94. data/spec/unit/client/active_record/gcm/notification_spec.rb +6 -88
  95. data/spec/unit/client/active_record/notification_spec.rb +3 -11
  96. data/spec/unit/client/active_record/pushy/app_spec.rb +2 -13
  97. data/spec/unit/client/active_record/pushy/notification_spec.rb +2 -55
  98. data/spec/unit/client/active_record/shared/app.rb +14 -0
  99. data/spec/unit/{notification_shared.rb → client/active_record/shared/notification.rb} +12 -7
  100. data/spec/unit/client/active_record/webpush/app_spec.rb +6 -0
  101. data/spec/unit/client/active_record/webpush/notification_spec.rb +6 -0
  102. data/spec/unit/client/active_record/wns/badge_notification_spec.rb +1 -11
  103. data/spec/unit/client/active_record/wns/raw_notification_spec.rb +3 -12
  104. data/spec/unit/client/active_record/wpns/app_spec.rb +3 -1
  105. data/spec/unit/client/active_record/wpns/notification_spec.rb +2 -17
  106. data/spec/unit/client/redis/adm/app_spec.rb +5 -0
  107. data/spec/unit/client/redis/adm/notification_spec.rb +5 -0
  108. data/spec/unit/client/redis/apns/app_spec.rb +5 -0
  109. data/spec/unit/client/redis/apns/feedback_spec.rb +5 -0
  110. data/spec/unit/client/redis/apns/notification_spec.rb +50 -0
  111. data/spec/unit/client/redis/apns2/app_spec.rb +4 -0
  112. data/spec/unit/client/redis/apns2/notification_spec.rb +50 -0
  113. data/spec/unit/client/redis/apnsp8/notification_spec.rb +29 -0
  114. data/spec/unit/client/redis/app_spec.rb +5 -0
  115. data/spec/unit/client/redis/gcm/app_spec.rb +5 -0
  116. data/spec/unit/client/redis/gcm/notification_spec.rb +5 -0
  117. data/spec/unit/client/redis/notification_spec.rb +5 -0
  118. data/spec/unit/client/redis/pushy/app_spec.rb +5 -0
  119. data/spec/unit/client/redis/pushy/notification_spec.rb +5 -0
  120. data/spec/unit/client/redis/webpush/app_spec.rb +5 -0
  121. data/spec/unit/client/redis/webpush/notification_spec.rb +5 -0
  122. data/spec/unit/client/redis/wns/badge_notification_spec.rb +5 -0
  123. data/spec/unit/client/redis/wns/raw_notification_spec.rb +22 -0
  124. data/spec/unit/client/redis/wpns/app_spec.rb +5 -0
  125. data/spec/unit/client/redis/wpns/notification_spec.rb +5 -0
  126. data/spec/unit/client/shared/adm/app.rb +51 -0
  127. data/spec/unit/client/shared/adm/notification.rb +39 -0
  128. data/spec/unit/client/shared/apns/app.rb +29 -0
  129. data/spec/unit/client/shared/apns/feedback.rb +9 -0
  130. data/spec/unit/client/shared/apns/notification.rb +277 -0
  131. data/spec/unit/client/shared/app.rb +17 -0
  132. data/spec/unit/client/shared/gcm/app.rb +4 -0
  133. data/spec/unit/client/shared/gcm/notification.rb +77 -0
  134. data/spec/unit/client/shared/notification.rb +10 -0
  135. data/spec/unit/client/shared/pushy/app.rb +17 -0
  136. data/spec/unit/client/shared/pushy/notification.rb +55 -0
  137. data/spec/unit/client/shared/webpush/app.rb +33 -0
  138. data/spec/unit/client/shared/webpush/notification.rb +83 -0
  139. data/spec/unit/client/shared/wns/badge_notification.rb +15 -0
  140. data/spec/unit/client/shared/wns/raw_notification.rb +21 -0
  141. data/spec/unit/client/shared/wpns/app.rb +4 -0
  142. data/spec/unit/client/shared/wpns/notification.rb +18 -0
  143. data/spec/unit/daemon/apnsp8/delivery_spec.rb +53 -0
  144. data/spec/unit/daemon/batch_spec.rb +50 -2
  145. data/spec/unit/daemon/delivery_spec.rb +10 -0
  146. data/spec/unit/daemon/pushy/delivery_spec.rb +5 -3
  147. data/spec/unit/daemon/shared/store.rb +312 -0
  148. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +7 -7
  149. data/spec/unit/daemon/store/active_record_spec.rb +6 -287
  150. data/spec/unit/daemon/store/redis_spec.rb +2 -291
  151. data/spec/unit/daemon/webpush/delivery_spec.rb +144 -0
  152. data/spec/unit_spec_helper.rb +3 -0
  153. metadata +145 -18
  154. data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +0 -16
@@ -1,7 +1,8 @@
1
1
  require 'unit_spec_helper'
2
- require 'rpush/daemon/store/active_record'
3
2
 
4
3
  describe Rpush::Daemon::Store::ActiveRecord do
4
+ it_behaves_like 'Rpush::Daemon::Store'
5
+
5
6
  let(:app) { Rpush::Client::ActiveRecord::Apns::App.create!(name: 'my_app', environment: 'development', certificate: TEST_CERT) }
6
7
  let(:notification) { Rpush::Client::ActiveRecord::Apns::Notification.create!(device_token: "a" * 64, app: app) }
7
8
  let(:store) { Rpush::Daemon::Store::ActiveRecord.new }
@@ -13,34 +14,6 @@ describe Rpush::Daemon::Store::ActiveRecord do
13
14
  allow(Time).to receive_messages(now: time)
14
15
  end
15
16
 
16
- it 'updates an notification' do
17
- expect(notification).to receive(:save!)
18
- store.update_notification(notification)
19
- end
20
-
21
- it 'updates an app' do
22
- expect(app).to receive(:save!)
23
- store.update_app(app)
24
- end
25
-
26
- it 'finds an app by ID' do
27
- expect(store.app(app.id)).to eq(app)
28
- end
29
-
30
- it 'finds all apps' do
31
- app
32
- expect(store.all_apps).to eq([app])
33
- end
34
-
35
- it 'translates an Integer notification ID' do
36
- expect(store.translate_integer_notification_id(notification.id)).to eq(notification.id)
37
- end
38
-
39
- it 'returns the pending notification count' do
40
- notification
41
- expect(store.pending_delivery_count).to eq(1)
42
- end
43
-
44
17
  it 'can release a connection' do
45
18
  expect(ActiveRecord::Base.connection).to receive(:close)
46
19
  store.release_connection
@@ -94,264 +67,10 @@ describe Rpush::Daemon::Store::ActiveRecord do
94
67
  end
95
68
  end
96
69
 
97
- describe 'mark_retryable' do
98
- it 'increments the retry count' do
99
- expect do
100
- store.mark_retryable(notification, time)
101
- end.to change(notification, :retries).by(1)
102
- end
103
-
104
- it 'sets the deliver after timestamp' do
105
- deliver_after = time + 10.seconds
106
- expect do
107
- store.mark_retryable(notification, deliver_after)
108
- end.to change(notification, :deliver_after).to(deliver_after)
109
- end
110
-
111
- it 'saves the notification without validation' do
112
- expect(notification).to receive(:save!).with(validate: false)
113
- store.mark_retryable(notification, time)
114
- end
115
-
116
- it 'does not save the notification if persist: false' do
117
- expect(notification).not_to receive(:save!)
118
- store.mark_retryable(notification, time, persist: false)
119
- end
120
- end
121
-
122
- describe 'mark_batch_retryable' do
123
- let(:deliver_after) { time + 10.seconds }
124
-
125
- it 'sets the attributes on the object for use in reflections' do
126
- store.mark_batch_retryable([notification], deliver_after)
127
- expect(notification.deliver_after).to eq deliver_after
128
- expect(notification.retries).to eq 1
129
- end
130
-
131
- it 'increments the retired count' do
132
- expect do
133
- store.mark_batch_retryable([notification], deliver_after)
134
- notification.reload
135
- end.to change(notification, :retries).by(1)
136
- end
137
-
138
- it 'sets the deliver after timestamp' do
139
- expect do
140
- store.mark_batch_retryable([notification], deliver_after)
141
- notification.reload
142
- end.to change { notification.deliver_after.try(:utc).to_s }.to(deliver_after.utc.to_s)
143
- end
144
- end
145
-
146
- describe 'mark_delivered' do
147
- it 'marks the notification as delivered' do
148
- expect do
149
- store.mark_delivered(notification, time)
150
- end.to change(notification, :delivered).to(true)
151
- end
152
-
153
- it 'sets the time the notification was delivered' do
154
- expect do
155
- store.mark_delivered(notification, time)
156
- notification.reload
157
- end.to change { notification.delivered_at.try(:utc).to_s }.to(time.to_s)
158
- end
159
-
160
- it 'saves the notification without validation' do
161
- expect(notification).to receive(:save!).with(validate: false)
162
- store.mark_delivered(notification, time)
163
- end
164
-
165
- it 'does not save the notification if persist: false' do
166
- expect(notification).not_to receive(:save!)
167
- store.mark_delivered(notification, time, persist: false)
168
- end
169
- end
170
-
171
- describe 'mark_batch_delivered' do
172
- it 'sets the attributes on the object for use in reflections' do
173
- store.mark_batch_delivered([notification])
174
- expect(notification.delivered_at).to eq time
175
- expect(notification.delivered).to be_truthy
176
- end
177
-
178
- it 'marks the notifications as delivered' do
179
- expect do
180
- store.mark_batch_delivered([notification])
181
- notification.reload
182
- end.to change(notification, :delivered).to(true)
183
- end
184
-
185
- it 'sets the time the notifications were delivered' do
186
- expect do
187
- store.mark_batch_delivered([notification])
188
- notification.reload
189
- end.to change { notification.delivered_at.try(:utc).to_s }.to(time.to_s)
190
- end
191
- end
192
-
193
- describe 'mark_failed' do
194
- it 'marks the notification as not delivered' do
195
- store.mark_failed(notification, nil, '', time)
196
- expect(notification.delivered).to eq(false)
197
- end
198
-
199
- it 'marks the notification as failed' do
200
- expect do
201
- store.mark_failed(notification, nil, '', time)
202
- notification.reload
203
- end.to change(notification, :failed).to(true)
204
- end
205
-
206
- it 'sets the time the notification delivery failed' do
207
- expect do
208
- store.mark_failed(notification, nil, '', time)
209
- notification.reload
210
- end.to change { notification.failed_at.try(:utc).to_s }.to(time.to_s)
211
- end
212
-
213
- it 'sets the error code' do
214
- expect do
215
- store.mark_failed(notification, 42, '', time)
216
- end.to change(notification, :error_code).to(42)
217
- end
218
-
219
- it 'sets the error description' do
220
- expect do
221
- store.mark_failed(notification, 42, 'Weeee', time)
222
- end.to change(notification, :error_description).to('Weeee')
223
- end
224
-
225
- it 'saves the notification without validation' do
226
- expect(notification).to receive(:save!).with(validate: false)
227
- store.mark_failed(notification, nil, '', time)
228
- end
229
-
230
- it 'does not save the notification if persist: false' do
231
- expect(notification).not_to receive(:save!)
232
- store.mark_failed(notification, nil, '', time, persist: false)
233
- end
234
- end
235
-
236
- describe 'mark_batch_failed' do
237
- it 'sets the attributes on the object for use in reflections' do
238
- store.mark_batch_failed([notification], 123, 'an error')
239
- expect(notification.failed_at).to eq time
240
- expect(notification.delivered_at).to be_nil
241
- expect(notification.delivered).to eq(false)
242
- expect(notification.failed).to be_truthy
243
- expect(notification.error_code).to eq 123
244
- expect(notification.error_description).to eq 'an error'
245
- end
246
-
247
- it 'marks the notification as not delivered' do
248
- store.mark_batch_failed([notification], nil, '')
249
- notification.reload
250
- expect(notification.delivered).to be_falsey
251
- end
252
-
253
- it 'marks the notification as failed' do
254
- expect do
255
- store.mark_batch_failed([notification], nil, '')
256
- notification.reload
257
- end.to change(notification, :failed).to(true)
258
- end
259
-
260
- it 'sets the time the notification delivery failed' do
261
- expect do
262
- store.mark_batch_failed([notification], nil, '')
263
- notification.reload
264
- end.to change { notification.failed_at.try(:utc).to_s }.to(time.to_s)
265
- end
266
-
267
- it 'sets the error code' do
268
- expect do
269
- store.mark_batch_failed([notification], 42, '')
270
- notification.reload
271
- end.to change(notification, :error_code).to(42)
272
- end
273
-
274
- it 'sets the error description' do
275
- expect do
276
- store.mark_batch_failed([notification], 42, 'Weeee')
277
- notification.reload
278
- end.to change(notification, :error_description).to('Weeee')
279
- end
280
- end
281
-
282
- describe 'create_apns_feedback' do
283
- it 'creates the Feedback record' do
284
- expect(Rpush::Client::ActiveRecord::Apns::Feedback).to receive(:create!).with(
285
- failed_at: time, device_token: 'ab' * 32, app_id: app.id)
286
- store.create_apns_feedback(time, 'ab' * 32, app)
287
- end
288
- end
289
-
290
- describe 'create_gcm_notification' do
291
- let(:data) { { data: true } }
292
- let(:attributes) { { device_token: 'ab' * 32 } }
293
- let(:registration_ids) { %w(123 456) }
294
- let(:deliver_after) { time + 10.seconds }
295
- let(:args) { [attributes, data, registration_ids, deliver_after, app] }
296
-
297
- it 'sets the given attributes' do
298
- new_notification = store.create_gcm_notification(*args)
299
- expect(new_notification.device_token).to eq 'ab' * 32
300
- end
301
-
302
- it 'sets the given data' do
303
- new_notification = store.create_gcm_notification(*args)
304
- expect(new_notification.data['data']).to be_truthy
305
- end
306
-
307
- it 'sets the given registration IDs' do
308
- new_notification = store.create_gcm_notification(*args)
309
- expect(new_notification.registration_ids).to eq registration_ids
310
- end
311
-
312
- it 'sets the deliver_after timestamp' do
313
- new_notification = store.create_gcm_notification(*args)
314
- expect(new_notification.deliver_after.to_s).to eq deliver_after.to_s
315
- end
316
-
317
- it 'saves the new notification' do
318
- new_notification = store.create_gcm_notification(*args)
319
- expect(new_notification.new_record?).to be_falsey
320
- end
321
- end
322
-
323
- describe 'create_adm_notification' do
324
- let(:data) { { data: true } }
325
- let(:attributes) { { app_id: app.id, collapse_key: 'ckey', delay_while_idle: true } }
326
- let(:registration_ids) { %w(123 456) }
327
- let(:deliver_after) { time + 10.seconds }
328
- let(:args) { [attributes, data, registration_ids, deliver_after, app] }
329
-
330
- it 'sets the given attributes' do
331
- new_notification = store.create_adm_notification(*args)
332
- expect(new_notification.app_id).to eq app.id
333
- expect(new_notification.collapse_key).to eq 'ckey'
334
- expect(new_notification.delay_while_idle).to be_truthy
335
- end
336
-
337
- it 'sets the given data' do
338
- new_notification = store.create_adm_notification(*args)
339
- expect(new_notification.data['data']).to be_truthy
340
- end
341
-
342
- it 'sets the given registration IDs' do
343
- new_notification = store.create_adm_notification(*args)
344
- expect(new_notification.registration_ids).to eq registration_ids
345
- end
346
-
347
- it 'sets the deliver_after timestamp' do
348
- new_notification = store.create_adm_notification(*args)
349
- expect(new_notification.deliver_after.to_s).to eq deliver_after.to_s
350
- end
351
-
352
- it 'saves the new notification' do
353
- new_notification = store.create_adm_notification(*args)
354
- expect(new_notification.new_record?).to be_falsey
70
+ describe "#adapter_name" do
71
+ it "should return the adapter name" do
72
+ adapter = ENV["ADAPTER"] || "postgresql"
73
+ expect(store.adapter_name).to eq(adapter)
355
74
  end
356
75
  end
357
76
  end if active_record?
@@ -1,7 +1,8 @@
1
1
  require 'unit_spec_helper'
2
- require 'rpush/daemon/store/redis'
3
2
 
4
3
  describe Rpush::Daemon::Store::Redis do
4
+ it_behaves_like 'Rpush::Daemon::Store'
5
+
5
6
  let(:app) { Rpush::Client::Redis::Apns::App.create!(name: 'my_app', environment: 'development', certificate: TEST_CERT) }
6
7
  let(:notification) { Rpush::Client::Redis::Apns::Notification.create!(device_token: "a" * 64, app: app) }
7
8
  let(:store) { Rpush::Daemon::Store::Redis.new }
@@ -13,35 +14,6 @@ describe Rpush::Daemon::Store::Redis do
13
14
  allow(Time).to receive_messages(now: time)
14
15
  end
15
16
 
16
- it 'updates an notification' do
17
- expect(notification).to receive(:save!)
18
- store.update_notification(notification)
19
- end
20
-
21
- it 'updates an app' do
22
- expect(app).to receive(:save!)
23
- store.update_app(app)
24
- end
25
-
26
- it 'finds an app by ID' do
27
- app
28
- expect(store.app(app.id)).to eq(app)
29
- end
30
-
31
- it 'finds all apps' do
32
- app
33
- expect(store.all_apps).to eq([app])
34
- end
35
-
36
- it 'translates an Integer notification ID' do
37
- expect(store.translate_integer_notification_id(notification.id)).to eq(notification.id)
38
- end
39
-
40
- it 'returns the pending notification count' do
41
- notification
42
- expect(store.pending_delivery_count).to eq(1)
43
- end
44
-
45
17
  describe 'deliverable_notifications' do
46
18
  it 'loads notifications in batches' do
47
19
  Rpush.config.batch_size = 100
@@ -82,31 +54,6 @@ describe Rpush::Daemon::Store::Redis do
82
54
  end
83
55
  end
84
56
 
85
- describe 'mark_retryable' do
86
- it 'increments the retry count' do
87
- expect do
88
- store.mark_retryable(notification, time)
89
- end.to change(notification, :retries).by(1)
90
- end
91
-
92
- it 'sets the deliver after timestamp' do
93
- deliver_after = time + 10.seconds
94
- expect do
95
- store.mark_retryable(notification, deliver_after)
96
- end.to change(notification, :deliver_after).to(deliver_after)
97
- end
98
-
99
- it 'saves the notification without validation' do
100
- expect(notification).to receive(:save!).with(validate: false)
101
- store.mark_retryable(notification, time)
102
- end
103
-
104
- it 'does not save the notification if persist: false' do
105
- expect(notification).not_to receive(:save!)
106
- store.mark_retryable(notification, time, persist: false)
107
- end
108
- end
109
-
110
57
  describe 'mark_ids_retryable' do
111
58
  let(:deliver_after) { time + 10.seconds }
112
59
 
@@ -126,120 +73,6 @@ describe Rpush::Daemon::Store::Redis do
126
73
  end
127
74
  end
128
75
 
129
- describe 'mark_batch_retryable' do
130
- let(:deliver_after) { time + 10.seconds }
131
-
132
- it 'sets the attributes on the object for use in reflections' do
133
- store.mark_batch_retryable([notification], deliver_after)
134
- expect(notification.deliver_after).to eq deliver_after
135
- expect(notification.retries).to eq 1
136
- end
137
-
138
- it 'increments the retired count' do
139
- expect do
140
- store.mark_batch_retryable([notification], deliver_after)
141
- notification.reload
142
- end.to change(notification, :retries).by(1)
143
- end
144
-
145
- it 'sets the deliver after timestamp' do
146
- expect do
147
- store.mark_batch_retryable([notification], deliver_after)
148
- notification.reload
149
- end.to change { notification.deliver_after.try(:utc).to_s }.to(deliver_after.utc.to_s)
150
- end
151
- end
152
-
153
- describe 'mark_delivered' do
154
- it 'marks the notification as delivered' do
155
- expect do
156
- store.mark_delivered(notification, time)
157
- end.to change(notification, :delivered).to(true)
158
- end
159
-
160
- it 'sets the time the notification was delivered' do
161
- expect do
162
- store.mark_delivered(notification, time)
163
- notification.reload
164
- end.to change { notification.delivered_at.try(:utc).to_s }.to(time.to_s)
165
- end
166
-
167
- it 'saves the notification without validation' do
168
- expect(notification).to receive(:save!).with(validate: false)
169
- store.mark_delivered(notification, time)
170
- end
171
-
172
- it 'does not save the notification if persist: false' do
173
- expect(notification).not_to receive(:save!)
174
- store.mark_delivered(notification, time, persist: false)
175
- end
176
- end
177
-
178
- describe 'mark_batch_delivered' do
179
- it 'sets the attributes on the object for use in reflections' do
180
- store.mark_batch_delivered([notification])
181
- expect(notification.delivered_at).to eq time
182
- expect(notification.delivered).to be_truthy
183
- end
184
-
185
- it 'marks the notifications as delivered' do
186
- expect do
187
- store.mark_batch_delivered([notification])
188
- notification.reload
189
- end.to change(notification, :delivered).to(true)
190
- end
191
-
192
- it 'sets the time the notifications were delivered' do
193
- expect do
194
- store.mark_batch_delivered([notification])
195
- notification.reload
196
- end.to change { notification.delivered_at.try(:utc).to_s }.to(time.to_s)
197
- end
198
- end
199
-
200
- describe 'mark_failed' do
201
- it 'marks the notification as not delivered' do
202
- store.mark_failed(notification, nil, '', time)
203
- expect(notification.delivered).to eq(false)
204
- end
205
-
206
- it 'marks the notification as failed' do
207
- expect do
208
- store.mark_failed(notification, nil, '', time)
209
- notification.reload
210
- end.to change(notification, :failed).to(true)
211
- end
212
-
213
- it 'sets the time the notification delivery failed' do
214
- expect do
215
- store.mark_failed(notification, nil, '', time)
216
- notification.reload
217
- end.to change { notification.failed_at.try(:utc).to_s }.to(time.to_s)
218
- end
219
-
220
- it 'sets the error code' do
221
- expect do
222
- store.mark_failed(notification, 42, '', time)
223
- end.to change(notification, :error_code).to(42)
224
- end
225
-
226
- it 'sets the error description' do
227
- expect do
228
- store.mark_failed(notification, 42, 'Weeee', time)
229
- end.to change(notification, :error_description).to('Weeee')
230
- end
231
-
232
- it 'saves the notification without validation' do
233
- expect(notification).to receive(:save!).with(validate: false)
234
- store.mark_failed(notification, nil, '', time)
235
- end
236
-
237
- it 'does not save the notification if persist: false' do
238
- expect(notification).not_to receive(:save!)
239
- store.mark_failed(notification, nil, '', time, persist: false)
240
- end
241
- end
242
-
243
76
  describe 'mark_ids_failed' do
244
77
  it 'marks the notification as failed' do
245
78
  expect do
@@ -256,126 +89,4 @@ describe Rpush::Daemon::Store::Redis do
256
89
  end.not_to raise_exception
257
90
  end
258
91
  end
259
-
260
- describe 'mark_batch_failed' do
261
- it 'sets the attributes on the object for use in reflections' do
262
- store.mark_batch_failed([notification], 123, 'an error')
263
- expect(notification.failed_at).to eq time
264
- expect(notification.delivered_at).to be_nil
265
- expect(notification.delivered).to eq(false)
266
- expect(notification.failed).to be_truthy
267
- expect(notification.error_code).to eq 123
268
- expect(notification.error_description).to eq 'an error'
269
- end
270
-
271
- it 'marks the notification as not delivered' do
272
- store.mark_batch_failed([notification], nil, '')
273
- notification.reload
274
- expect(notification.delivered).to be_falsey
275
- end
276
-
277
- it 'marks the notification as failed' do
278
- expect do
279
- store.mark_batch_failed([notification], nil, '')
280
- notification.reload
281
- end.to change(notification, :failed).to(true)
282
- end
283
-
284
- it 'sets the time the notification delivery failed' do
285
- expect do
286
- store.mark_batch_failed([notification], nil, '')
287
- notification.reload
288
- end.to change { notification.failed_at.try(:utc).to_s }.to(time.to_s)
289
- end
290
-
291
- it 'sets the error code' do
292
- expect do
293
- store.mark_batch_failed([notification], 42, '')
294
- notification.reload
295
- end.to change(notification, :error_code).to(42)
296
- end
297
-
298
- it 'sets the error description' do
299
- expect do
300
- store.mark_batch_failed([notification], 42, 'Weeee')
301
- notification.reload
302
- end.to change(notification, :error_description).to('Weeee')
303
- end
304
- end
305
-
306
- describe 'create_apns_feedback' do
307
- it 'creates the Feedback record' do
308
- expect(Rpush::Client::Redis::Apns::Feedback).to receive(:create!).with(
309
- failed_at: time, device_token: 'ab' * 32, app_id: app.id)
310
- store.create_apns_feedback(time, 'ab' * 32, app)
311
- end
312
- end
313
-
314
- describe 'create_gcm_notification' do
315
- let(:data) { { data: true } }
316
- let(:attributes) { { device_token: 'ab' * 32 } }
317
- let(:registration_ids) { %w(123 456) }
318
- let(:deliver_after) { time + 10.seconds }
319
- let(:args) { [attributes, data, registration_ids, deliver_after, app] }
320
-
321
- it 'sets the given attributes' do
322
- new_notification = store.create_gcm_notification(*args)
323
- expect(new_notification.device_token).to eq 'ab' * 32
324
- end
325
-
326
- it 'sets the given data' do
327
- new_notification = store.create_gcm_notification(*args)
328
- expect(new_notification.data).to eq(data: true)
329
- end
330
-
331
- it 'sets the given registration IDs' do
332
- new_notification = store.create_gcm_notification(*args)
333
- expect(new_notification.registration_ids).to eq registration_ids
334
- end
335
-
336
- it 'sets the deliver_after timestamp' do
337
- new_notification = store.create_gcm_notification(*args)
338
- expect(new_notification.deliver_after.utc.to_s).to eq deliver_after.to_s
339
- end
340
-
341
- it 'saves the new notification' do
342
- new_notification = store.create_gcm_notification(*args)
343
- expect(new_notification.new_record?).to be_falsey
344
- end
345
- end
346
-
347
- describe 'create_adm_notification' do
348
- let(:data) { { data: true } }
349
- let(:attributes) { { app_id: app.id, collapse_key: 'ckey', delay_while_idle: true } }
350
- let(:registration_ids) { %w(123 456) }
351
- let(:deliver_after) { time + 10.seconds }
352
- let(:args) { [attributes, data, registration_ids, deliver_after, app] }
353
-
354
- it 'sets the given attributes' do
355
- new_notification = store.create_adm_notification(*args)
356
- expect(new_notification.app_id).to eq app.id
357
- expect(new_notification.collapse_key).to eq 'ckey'
358
- expect(new_notification.delay_while_idle).to be_truthy
359
- end
360
-
361
- it 'sets the given data' do
362
- new_notification = store.create_adm_notification(*args)
363
- expect(new_notification.data).to eq(data: true)
364
- end
365
-
366
- it 'sets the given registration IDs' do
367
- new_notification = store.create_adm_notification(*args)
368
- expect(new_notification.registration_ids).to eq registration_ids
369
- end
370
-
371
- it 'sets the deliver_after timestamp' do
372
- new_notification = store.create_adm_notification(*args)
373
- expect(new_notification.deliver_after.utc.to_s).to eq deliver_after.to_s
374
- end
375
-
376
- it 'saves the new notification' do
377
- new_notification = store.create_adm_notification(*args)
378
- expect(new_notification.new_record?).to be_falsey
379
- end
380
- end
381
92
  end if redis?