rpush 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -2
  3. data/lib/rpush/cli.rb +1 -1
  4. data/lib/rpush/client/active_model.rb +1 -1
  5. data/lib/rpush/client/active_model/apns/notification.rb +9 -1
  6. data/lib/rpush/client/active_model/apns/notification_payload_size_validator.rb +15 -0
  7. data/lib/rpush/client/active_model/apns2/notification.rb +14 -0
  8. data/lib/rpush/client/active_record.rb +1 -0
  9. data/lib/rpush/client/active_record/apns/active_record_serializable_notification.rb +65 -0
  10. data/lib/rpush/client/active_record/apns/notification.rb +1 -57
  11. data/lib/rpush/client/active_record/apns2/notification.rb +4 -1
  12. data/lib/rpush/client/redis/apns2/notification.rb +1 -0
  13. data/lib/rpush/client/redis/pushy/notification.rb +0 -1
  14. data/lib/rpush/daemon/apns2/delivery.rb +6 -1
  15. data/lib/rpush/daemon/apnsp8/delivery.rb +7 -2
  16. data/lib/rpush/daemon/store/active_record/reconnectable.rb +1 -1
  17. data/lib/rpush/version.rb +1 -1
  18. data/spec/functional/apns2_spec.rb +36 -0
  19. data/spec/support/simplecov_helper.rb +1 -1
  20. data/spec/unit/client/active_record/adm/app_spec.rb +2 -54
  21. data/spec/unit/client/active_record/adm/notification_spec.rb +2 -39
  22. data/spec/unit/client/active_record/apns/app_spec.rb +3 -26
  23. data/spec/unit/client/active_record/apns/feedback_spec.rb +1 -5
  24. data/spec/unit/client/active_record/apns/notification_spec.rb +29 -293
  25. data/spec/unit/client/active_record/apns2/app_spec.rb +4 -0
  26. data/spec/unit/client/active_record/apns2/notification_spec.rb +65 -0
  27. data/spec/unit/client/active_record/app_spec.rb +1 -26
  28. data/spec/unit/client/active_record/gcm/app_spec.rb +3 -1
  29. data/spec/unit/client/active_record/gcm/notification_spec.rb +6 -88
  30. data/spec/unit/client/active_record/notification_spec.rb +3 -11
  31. data/spec/unit/client/active_record/pushy/app_spec.rb +2 -13
  32. data/spec/unit/client/active_record/pushy/notification_spec.rb +2 -55
  33. data/spec/unit/client/active_record/shared/app.rb +14 -0
  34. data/spec/unit/{notification_shared.rb → client/active_record/shared/notification.rb} +12 -7
  35. data/spec/unit/client/active_record/wns/badge_notification_spec.rb +1 -11
  36. data/spec/unit/client/active_record/wns/raw_notification_spec.rb +3 -12
  37. data/spec/unit/client/active_record/wpns/app_spec.rb +3 -1
  38. data/spec/unit/client/active_record/wpns/notification_spec.rb +2 -17
  39. data/spec/unit/client/redis/adm/app_spec.rb +5 -0
  40. data/spec/unit/client/redis/adm/notification_spec.rb +5 -0
  41. data/spec/unit/client/redis/apns/app_spec.rb +5 -0
  42. data/spec/unit/client/redis/apns/feedback_spec.rb +5 -0
  43. data/spec/unit/client/redis/apns/notification_spec.rb +50 -0
  44. data/spec/unit/client/redis/apns2/app_spec.rb +4 -0
  45. data/spec/unit/client/redis/apns2/notification_spec.rb +50 -0
  46. data/spec/unit/client/redis/app_spec.rb +5 -0
  47. data/spec/unit/client/redis/gcm/app_spec.rb +5 -0
  48. data/spec/unit/client/redis/gcm/notification_spec.rb +5 -0
  49. data/spec/unit/client/redis/notification_spec.rb +5 -0
  50. data/spec/unit/client/redis/pushy/app_spec.rb +5 -0
  51. data/spec/unit/client/redis/pushy/notification_spec.rb +5 -0
  52. data/spec/unit/client/redis/wns/badge_notification_spec.rb +5 -0
  53. data/spec/unit/client/redis/wns/raw_notification_spec.rb +22 -0
  54. data/spec/unit/client/redis/wpns/app_spec.rb +5 -0
  55. data/spec/unit/client/redis/wpns/notification_spec.rb +5 -0
  56. data/spec/unit/client/shared/adm/app.rb +51 -0
  57. data/spec/unit/client/shared/adm/notification.rb +39 -0
  58. data/spec/unit/client/shared/apns/app.rb +29 -0
  59. data/spec/unit/client/shared/apns/feedback.rb +9 -0
  60. data/spec/unit/client/shared/apns/notification.rb +262 -0
  61. data/spec/unit/client/shared/app.rb +17 -0
  62. data/spec/unit/client/shared/gcm/app.rb +4 -0
  63. data/spec/unit/client/shared/gcm/notification.rb +77 -0
  64. data/spec/unit/client/shared/notification.rb +10 -0
  65. data/spec/unit/client/shared/pushy/app.rb +17 -0
  66. data/spec/unit/client/shared/pushy/notification.rb +55 -0
  67. data/spec/unit/client/shared/wns/badge_notification.rb +15 -0
  68. data/spec/unit/client/shared/wns/raw_notification.rb +21 -0
  69. data/spec/unit/client/shared/wpns/app.rb +4 -0
  70. data/spec/unit/client/shared/wpns/notification.rb +18 -0
  71. data/spec/unit/daemon/shared/store.rb +312 -0
  72. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +7 -7
  73. data/spec/unit/daemon/store/active_record_spec.rb +2 -290
  74. data/spec/unit/daemon/store/redis_spec.rb +2 -291
  75. data/spec/unit_spec_helper.rb +3 -0
  76. metadata +89 -10
  77. data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +0 -16
@@ -80,8 +80,8 @@ describe Rpush::Daemon::Store::ActiveRecord::Reconnectable do
80
80
  test_doubles.each(&:perform)
81
81
  end
82
82
 
83
- it "should test out the new connection by performing a count" do
84
- expect(Rpush::Client::ActiveRecord::Notification).to receive(:count).twice
83
+ it "should test out the new connection by performing an exists" do
84
+ expect(Rpush::Client::ActiveRecord::Notification).to receive(:exists?).twice
85
85
  test_doubles.each(&:perform)
86
86
  end
87
87
 
@@ -118,13 +118,13 @@ describe Rpush::Daemon::Store::ActiveRecord::Reconnectable do
118
118
  context "when the reconnection attempt is not successful" do
119
119
  before do
120
120
  class << Rpush::Client::ActiveRecord::Notification
121
- def count
122
- @count_calls += 1
123
- return if @count_calls == 2
121
+ def exists?
122
+ @exists_calls += 1
123
+ return if @exists_calls == 2
124
124
  fail @error
125
125
  end
126
126
  end
127
- Rpush::Client::ActiveRecord::Notification.instance_variable_set("@count_calls", 0)
127
+ Rpush::Client::ActiveRecord::Notification.instance_variable_set("@exists_calls", 0)
128
128
  Rpush::Client::ActiveRecord::Notification.instance_variable_set("@error", error)
129
129
  end
130
130
 
@@ -152,7 +152,7 @@ describe Rpush::Daemon::Store::ActiveRecord::Reconnectable do
152
152
  end
153
153
 
154
154
  it "should log errors raised when the reconnection is not successful" do
155
- expect(Rpush.logger).to receive(:error).with(error)
155
+ expect(Rpush.logger).to receive(:error).with(timeout)
156
156
  test_doubles[1].perform
157
157
  end
158
158
 
@@ -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
@@ -93,265 +66,4 @@ describe Rpush::Daemon::Store::ActiveRecord do
93
66
  expect(store.deliverable_notifications(Rpush.config.batch_size)).to be_empty
94
67
  end
95
68
  end
96
-
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
355
- end
356
- end
357
69
  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?