rpush 2.3.1 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +36 -28
  4. data/lib/rpush/configuration.rb +1 -0
  5. data/lib/rpush/daemon/feeder.rb +16 -12
  6. data/lib/rpush/daemon/interruptible_sleep.rb +26 -5
  7. data/lib/rpush/daemon/store/active_record.rb +4 -0
  8. data/lib/rpush/daemon/store/interface.rb +1 -1
  9. data/lib/rpush/daemon/store/redis.rb +10 -0
  10. data/lib/rpush/embed.rb +1 -0
  11. data/lib/rpush/logger.rb +1 -0
  12. data/lib/rpush/push.rb +1 -2
  13. data/lib/rpush/version.rb +1 -1
  14. data/spec/functional/adm_spec.rb +6 -8
  15. data/spec/functional/apns_spec.rb +9 -9
  16. data/spec/functional/embed_spec.rb +3 -3
  17. data/spec/functional/gcm_spec.rb +6 -8
  18. data/spec/functional/new_app_spec.rb +5 -20
  19. data/spec/functional/retry_spec.rb +8 -12
  20. data/spec/functional/synchronization_spec.rb +1 -1
  21. data/spec/functional/wpns_spec.rb +7 -7
  22. data/spec/functional_spec_helper.rb +4 -5
  23. data/spec/spec_helper.rb +1 -1
  24. data/spec/unit/apns_feedback_spec.rb +4 -4
  25. data/spec/unit/client/active_record/adm/app_spec.rb +12 -12
  26. data/spec/unit/client/active_record/adm/notification_spec.rb +9 -9
  27. data/spec/unit/client/active_record/apns/app_spec.rb +4 -4
  28. data/spec/unit/client/active_record/apns/feedback_spec.rb +2 -2
  29. data/spec/unit/client/active_record/apns/notification_spec.rb +46 -46
  30. data/spec/unit/client/active_record/app_spec.rb +6 -6
  31. data/spec/unit/client/active_record/gcm/notification_spec.rb +7 -7
  32. data/spec/unit/client/active_record/notification_spec.rb +2 -2
  33. data/spec/unit/client/active_record/wpns/notification_spec.rb +2 -8
  34. data/spec/unit/configuration_spec.rb +5 -5
  35. data/spec/unit/daemon/adm/delivery_spec.rb +69 -69
  36. data/spec/unit/daemon/apns/delivery_spec.rb +13 -13
  37. data/spec/unit/daemon/apns/feedback_receiver_spec.rb +24 -26
  38. data/spec/unit/daemon/app_runner_spec.rb +29 -29
  39. data/spec/unit/daemon/batch_spec.rb +30 -30
  40. data/spec/unit/daemon/delivery_error_spec.rb +2 -2
  41. data/spec/unit/daemon/delivery_spec.rb +6 -6
  42. data/spec/unit/daemon/dispatcher/http_spec.rb +5 -5
  43. data/spec/unit/daemon/dispatcher/tcp_spec.rb +4 -4
  44. data/spec/unit/daemon/dispatcher_loop_spec.rb +9 -9
  45. data/spec/unit/daemon/feeder_spec.rb +22 -23
  46. data/spec/unit/daemon/gcm/delivery_spec.rb +56 -56
  47. data/spec/unit/daemon/retryable_error_spec.rb +2 -2
  48. data/spec/unit/daemon/service_config_methods_spec.rb +5 -5
  49. data/spec/unit/daemon/signal_handler_spec.rb +13 -13
  50. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +13 -13
  51. data/spec/unit/daemon/store/active_record_spec.rb +49 -49
  52. data/spec/unit/daemon/tcp_connection_spec.rb +50 -50
  53. data/spec/unit/daemon/wpns/delivery_spec.rb +36 -36
  54. data/spec/unit/daemon_spec.rb +33 -30
  55. data/spec/unit/deprecatable_spec.rb +3 -3
  56. data/spec/unit/deprecation_spec.rb +2 -2
  57. data/spec/unit/embed_spec.rb +7 -7
  58. data/spec/unit/logger_spec.rb +25 -25
  59. data/spec/unit/notification_shared.rb +7 -7
  60. data/spec/unit/plugin_spec.rb +1 -1
  61. data/spec/unit/push_spec.rb +8 -8
  62. data/spec/unit/reflectable_spec.rb +5 -5
  63. data/spec/unit/reflection_collection_spec.rb +2 -2
  64. data/spec/unit/rpush_spec.rb +1 -1
  65. data/spec/unit_spec_helper.rb +4 -5
  66. metadata +10 -4
@@ -12,23 +12,23 @@ describe Rpush::Daemon::Delivery do
12
12
  let(:delivery) { DeliverySpecDelivery.new(batch) }
13
13
  let(:notification) { Rpush::Apns::Notification.new }
14
14
 
15
- before { Time.stub(now: now) }
15
+ before { allow(Time).to receive_messages(now: now) }
16
16
 
17
17
  describe 'mark_retryable' do
18
18
  it 'does not retry a notification with an expired fail_after' do
19
- batch.should_receive(:mark_failed).with(notification, nil, "Notification failed to be delivered before 2014-10-13 23:00:00.")
19
+ expect(batch).to receive(:mark_failed).with(notification, nil, "Notification failed to be delivered before 2014-10-13 23:00:00.")
20
20
  notification.fail_after = Time.now - 1.hour
21
21
  delivery.mark_retryable(notification, Time.now + 1.hour)
22
22
  end
23
23
 
24
24
  it 'retries the notification if does not have a fail_after time' do
25
- batch.should_receive(:mark_retryable)
25
+ expect(batch).to receive(:mark_retryable)
26
26
  notification.fail_after = nil
27
27
  delivery.mark_retryable(notification, Time.now + 1.hour)
28
28
  end
29
29
 
30
30
  it 'retries the notification if the fail_after time has not been reached' do
31
- batch.should_receive(:mark_retryable)
31
+ expect(batch).to receive(:mark_retryable)
32
32
  notification.fail_after = Time.now + 1.hour
33
33
  delivery.mark_retryable(notification, Time.now + 1.hour)
34
34
  end
@@ -36,7 +36,7 @@ describe Rpush::Daemon::Delivery do
36
36
 
37
37
  describe 'mark_batch_delivered' do
38
38
  it 'marks all notifications as delivered' do
39
- batch.should_receive(:mark_all_delivered)
39
+ expect(batch).to receive(:mark_all_delivered)
40
40
  delivery.mark_batch_delivered
41
41
  end
42
42
  end
@@ -44,7 +44,7 @@ describe Rpush::Daemon::Delivery do
44
44
  describe 'mark_batch_failed' do
45
45
  it 'marks all notifications as delivered' do
46
46
  error = Rpush::DeliveryError.new(1, 42, 'an error')
47
- batch.should_receive(:mark_all_failed).with(1, 'Unable to deliver notification 42, received error 1 (an error)')
47
+ expect(batch).to receive(:mark_all_failed).with(1, 'Unable to deliver notification 42, received error 1 (an error)')
48
48
  delivery.mark_batch_failed(error)
49
49
  end
50
50
  end
@@ -9,25 +9,25 @@ describe Rpush::Daemon::Dispatcher::Http do
9
9
  let(:queue_payload) { Rpush::Daemon::QueuePayload.new(batch, notification) }
10
10
  let(:dispatcher) { Rpush::Daemon::Dispatcher::Http.new(app, delivery_class) }
11
11
 
12
- before { Net::HTTP::Persistent.stub(new: http) }
12
+ before { allow(Net::HTTP::Persistent).to receive_messages(new: http) }
13
13
 
14
14
  it 'constructs a new persistent connection' do
15
- Net::HTTP::Persistent.should_receive(:new)
15
+ expect(Net::HTTP::Persistent).to receive(:new)
16
16
  Rpush::Daemon::Dispatcher::Http.new(app, delivery_class)
17
17
  end
18
18
 
19
19
  describe 'dispatch' do
20
20
  it 'delivers the notification' do
21
21
  delivery = double
22
- delivery_class.should_receive(:new).with(app, http, notification, batch).and_return(delivery)
23
- delivery.should_receive(:perform)
22
+ expect(delivery_class).to receive(:new).with(app, http, notification, batch).and_return(delivery)
23
+ expect(delivery).to receive(:perform)
24
24
  dispatcher.dispatch(queue_payload)
25
25
  end
26
26
  end
27
27
 
28
28
  describe 'cleanup' do
29
29
  it 'closes the connection' do
30
- http.should_receive(:shutdown)
30
+ expect(http).to receive(:shutdown)
31
31
  dispatcher.cleanup
32
32
  end
33
33
  end
@@ -13,19 +13,19 @@ describe Rpush::Daemon::Dispatcher::Tcp do
13
13
  let(:queue_payload) { Rpush::Daemon::QueuePayload.new(batch, notification) }
14
14
  let(:dispatcher) { Rpush::Daemon::Dispatcher::Tcp.new(app, delivery_class, host: host_proc) }
15
15
 
16
- before { Rpush::Daemon::TcpConnection.stub(new: connection) }
16
+ before { allow(Rpush::Daemon::TcpConnection).to receive_messages(new: connection) }
17
17
 
18
18
  describe 'dispatch' do
19
19
  it 'delivers the notification' do
20
- delivery_class.should_receive(:new).with(app, connection, notification, batch).and_return(delivery)
21
- delivery.should_receive(:perform)
20
+ expect(delivery_class).to receive(:new).with(app, connection, notification, batch).and_return(delivery)
21
+ expect(delivery).to receive(:perform)
22
22
  dispatcher.dispatch(queue_payload)
23
23
  end
24
24
  end
25
25
 
26
26
  describe 'cleanup' do
27
27
  it 'closes the connection' do
28
- connection.should_receive(:close)
28
+ expect(connection).to receive(:close)
29
29
  dispatcher.cleanup
30
30
  end
31
31
  end
@@ -14,24 +14,24 @@ describe Rpush::Daemon::DispatcherLoop do
14
14
  let(:store) { double(Rpush::Daemon::Store::ActiveRecord, release_connection: nil) }
15
15
 
16
16
  before do
17
- Rpush::Daemon.stub(store: store)
17
+ allow(Rpush::Daemon).to receive_messages(store: store)
18
18
  queue.push([notification, batch])
19
19
  end
20
20
 
21
21
  it 'logs errors' do
22
22
  logger = double
23
- Rpush.stub(logger: logger)
23
+ allow(Rpush).to receive_messages(logger: logger)
24
24
  error = StandardError.new
25
- dispatcher.stub(:dispatch).and_raise(error)
26
- Rpush.logger.should_receive(:error).with(error)
25
+ allow(dispatcher).to receive(:dispatch).and_raise(error)
26
+ expect(Rpush.logger).to receive(:error).with(error)
27
27
  run_dispatcher_loop
28
28
  end
29
29
 
30
30
  it 'reflects an exception' do
31
- Rpush.stub(logger: double(error: nil))
31
+ allow(Rpush).to receive_messages(logger: double(error: nil))
32
32
  error = StandardError.new
33
- dispatcher.stub(:dispatch).and_raise(error)
34
- dispatcher_loop.should_receive(:reflect).with(:error, error)
33
+ allow(dispatcher).to receive(:dispatch).and_raise(error)
34
+ expect(dispatcher_loop).to receive(:reflect).with(:error, error)
35
35
  run_dispatcher_loop
36
36
  end
37
37
 
@@ -41,12 +41,12 @@ describe Rpush::Daemon::DispatcherLoop do
41
41
  end
42
42
 
43
43
  it 'instructs the dispatcher to cleanup' do
44
- dispatcher.should_receive(:cleanup)
44
+ expect(dispatcher).to receive(:cleanup)
45
45
  run_dispatcher_loop
46
46
  end
47
47
 
48
48
  it 'releases the store connection' do
49
- Rpush::Daemon.store.should_receive(:release_connection)
49
+ expect(Rpush::Daemon.store).to receive(:release_connection)
50
50
  run_dispatcher_loop
51
51
  end
52
52
  end
@@ -14,10 +14,10 @@ describe Rpush::Daemon::Feeder do
14
14
  config.push = false
15
15
  end
16
16
 
17
- Rpush.stub(logger: logger)
18
- Rpush::Daemon.stub(store: store)
19
- Rpush::Daemon::Feeder.stub(should_stop: true, interruptible_sleeper: interruptible_sleeper)
20
- Rpush::Daemon::AppRunner.stub(enqueue: nil, num_queued: 0)
17
+ allow(Rpush).to receive_messages(logger: logger)
18
+ allow(Rpush::Daemon).to receive_messages(store: store)
19
+ allow(Rpush::Daemon::Feeder).to receive_messages(should_stop: true, interruptible_sleeper: interruptible_sleeper)
20
+ allow(Rpush::Daemon::AppRunner).to receive_messages(enqueue: nil, num_queued: 0)
21
21
  end
22
22
 
23
23
  def start_and_stop
@@ -26,68 +26,67 @@ describe Rpush::Daemon::Feeder do
26
26
  end
27
27
 
28
28
  it 'loads deliverable notifications' do
29
- Rpush::Daemon.store.should_receive(:deliverable_notifications).with(Rpush.config.batch_size)
29
+ expect(Rpush::Daemon.store).to receive(:deliverable_notifications).with(Rpush.config.batch_size)
30
30
  start_and_stop
31
31
  end
32
32
 
33
33
  it 'does not load more notifications if the total queue size is equal to the batch size' do
34
- Rpush::Daemon::AppRunner.stub(total_queued: Rpush.config.batch_size)
35
- Rpush::Daemon.store.should_not_receive(:deliverable_notifications)
34
+ allow(Rpush::Daemon::AppRunner).to receive_messages(total_queued: Rpush.config.batch_size)
35
+ expect(Rpush::Daemon.store).not_to receive(:deliverable_notifications)
36
36
  start_and_stop
37
37
  end
38
38
 
39
39
  it 'limits the batch size if some runners are still processing notifications' do
40
- Rpush.config.stub(batch_size: 10)
41
- Rpush::Daemon::AppRunner.stub(total_queued: 6)
42
- Rpush::Daemon.store.should_receive(:deliverable_notifications).with(4)
40
+ allow(Rpush.config).to receive_messages(batch_size: 10)
41
+ allow(Rpush::Daemon::AppRunner).to receive_messages(total_queued: 6)
42
+ expect(Rpush::Daemon.store).to receive(:deliverable_notifications).with(4)
43
43
  start_and_stop
44
44
  end
45
45
 
46
46
  it 'enqueues notifications without looping if in push mode' do
47
- Rpush.config.push = true
48
- Rpush::Daemon::Feeder.should_not_receive(:feed_forever)
49
- Rpush::Daemon::Feeder.should_receive(:enqueue_notifications)
50
- start_and_stop
47
+ expect(Rpush::Daemon::Feeder).not_to receive(:feed_forever)
48
+ expect(Rpush::Daemon::Feeder).to receive(:feed_all)
49
+ Rpush::Daemon::Feeder.start(true)
51
50
  end
52
51
 
53
52
  it "enqueues the notifications" do
54
- Rpush::Daemon::AppRunner.should_receive(:enqueue).with([notification])
53
+ expect(Rpush::Daemon::AppRunner).to receive(:enqueue).with([notification])
55
54
  start_and_stop
56
55
  end
57
56
 
58
57
  it "logs errors" do
59
58
  e = StandardError.new("bork")
60
- Rpush::Daemon.store.stub(:deliverable_notifications).and_raise(e)
61
- Rpush.logger.should_receive(:error).with(e)
59
+ allow(Rpush::Daemon.store).to receive(:deliverable_notifications).and_raise(e)
60
+ expect(Rpush.logger).to receive(:error).with(e)
62
61
  start_and_stop
63
62
  end
64
63
 
65
64
  describe 'stop' do
66
65
  it 'interrupts sleep' do
67
- interruptible_sleeper.should_receive(:stop)
66
+ expect(interruptible_sleeper).to receive(:stop)
68
67
  start_and_stop
69
68
  end
70
69
 
71
70
  it 'releases the store connection' do
72
- Rpush::Daemon.store.should_receive(:release_connection)
71
+ expect(Rpush::Daemon.store).to receive(:release_connection)
73
72
  start_and_stop
74
73
  end
75
74
  end
76
75
 
77
76
  it 'enqueues notifications when started' do
78
- Rpush::Daemon::Feeder.should_receive(:enqueue_notifications).at_least(:once)
79
- Rpush::Daemon::Feeder.stub(:loop).and_yield
77
+ expect(Rpush::Daemon::Feeder).to receive(:enqueue_notifications).at_least(:once)
78
+ allow(Rpush::Daemon::Feeder).to receive(:loop).and_yield
80
79
  start_and_stop
81
80
  end
82
81
 
83
82
  it 'sleeps' do
84
- interruptible_sleeper.should_receive(:sleep)
83
+ expect(interruptible_sleeper).to receive(:sleep)
85
84
  start_and_stop
86
85
  end
87
86
 
88
87
  describe 'wakeup' do
89
88
  it 'interrupts sleep' do
90
- interruptible_sleeper.should_receive(:wakeup)
89
+ expect(interruptible_sleeper).to receive(:wakeup)
91
90
  Rpush::Daemon::Feeder.start
92
91
  Rpush::Daemon::Feeder.wakeup
93
92
  end
@@ -20,31 +20,31 @@ describe Rpush::Daemon::Gcm::Delivery do
20
20
  end
21
21
 
22
22
  before do
23
- delivery.stub(reflect: nil)
24
- Rpush::Daemon.stub(store: store)
25
- Time.stub(now: now)
26
- Rpush.stub(logger: logger)
23
+ allow(delivery).to receive_messages(reflect: nil)
24
+ allow(Rpush::Daemon).to receive_messages(store: store)
25
+ allow(Time).to receive_messages(now: now)
26
+ allow(Rpush).to receive_messages(logger: logger)
27
27
  end
28
28
 
29
29
  shared_examples_for 'a notification with some delivery failures' do
30
30
  let(:new_notification) { Rpush::Gcm::Notification.where('id != ?', notification.id).first }
31
31
 
32
- before { response.stub(body: JSON.dump(body)) }
32
+ before { allow(response).to receive_messages(body: JSON.dump(body)) }
33
33
 
34
34
  it 'marks the original notification as failed' do
35
35
  # error = Rpush::DeliveryError.new(nil, notification.id, error_description)
36
- delivery.should_receive(:mark_failed) do |error|
37
- error.to_s.should =~ error_description
36
+ expect(delivery).to receive(:mark_failed) do |error|
37
+ expect(error.to_s).to match(error_description)
38
38
  end
39
39
  perform_with_rescue
40
40
  end
41
41
 
42
42
  it 'creates a new notification for the unavailable devices' do
43
43
  notification.update_attributes(registration_ids: %w(id_0 id_1 id_2), data: { 'one' => 1 }, collapse_key: 'thing', delay_while_idle: true)
44
- response.stub(header: { 'retry-after' => 10 })
44
+ allow(response).to receive_messages(header: { 'retry-after' => 10 })
45
45
  attrs = { 'collapse_key' => 'thing', 'delay_while_idle' => true, 'app_id' => app.id }
46
- store.should_receive(:create_gcm_notification).with(attrs, notification.data,
47
- %w(id_0 id_2), now + 10.seconds, notification.app)
46
+ expect(store).to receive(:create_gcm_notification).with(attrs, notification.data,
47
+ %w(id_0 id_2), now + 10.seconds, notification.app)
48
48
  perform_with_rescue
49
49
  end
50
50
 
@@ -55,7 +55,7 @@ describe Rpush::Daemon::Gcm::Delivery do
55
55
 
56
56
  describe 'a 200 response' do
57
57
  before do
58
- response.stub(code: 200)
58
+ allow(response).to receive_messages(code: 200)
59
59
  end
60
60
 
61
61
  it 'reflects on any IDs which successfully received the notification' do
@@ -68,10 +68,10 @@ describe Rpush::Daemon::Gcm::Delivery do
68
68
  ]
69
69
  }
70
70
 
71
- response.stub(body: JSON.dump(body))
72
- notification.stub(registration_ids: %w(1 2))
73
- delivery.should_receive(:reflect).with(:gcm_delivered_to_recipient, notification, '1')
74
- delivery.should_not_receive(:reflect).with(:gcm_delivered_to_recipient, notification, '2')
71
+ allow(response).to receive_messages(body: JSON.dump(body))
72
+ allow(notification).to receive_messages(registration_ids: %w(1 2))
73
+ expect(delivery).to receive(:reflect).with(:gcm_delivered_to_recipient, notification, '1')
74
+ expect(delivery).not_to receive(:reflect).with(:gcm_delivered_to_recipient, notification, '2')
75
75
  perform_with_rescue
76
76
  end
77
77
 
@@ -85,10 +85,10 @@ describe Rpush::Daemon::Gcm::Delivery do
85
85
  ]
86
86
  }
87
87
 
88
- response.stub(body: JSON.dump(body))
89
- notification.stub(registration_ids: %w(1 2))
90
- delivery.should_receive(:reflect).with(:gcm_failed_to_recipient, notification, 'Err', '1')
91
- delivery.should_not_receive(:reflect).with(:gcm_failed_to_recipient, notification, anything, '2')
88
+ allow(response).to receive_messages(body: JSON.dump(body))
89
+ allow(notification).to receive_messages(registration_ids: %w(1 2))
90
+ expect(delivery).to receive(:reflect).with(:gcm_failed_to_recipient, notification, 'Err', '1')
91
+ expect(delivery).not_to receive(:reflect).with(:gcm_failed_to_recipient, notification, anything, '2')
92
92
  perform_with_rescue
93
93
  end
94
94
 
@@ -103,9 +103,9 @@ describe Rpush::Daemon::Gcm::Delivery do
103
103
  { 'message_id' => '1:000' }
104
104
  ] }
105
105
 
106
- response.stub(body: JSON.dump(body))
107
- notification.stub(registration_ids: %w(1 2 3))
108
- delivery.should_receive(:reflect).with(:gcm_canonical_id, '2', 'canonical123')
106
+ allow(response).to receive_messages(body: JSON.dump(body))
107
+ allow(notification).to receive_messages(registration_ids: %w(1 2 3))
108
+ expect(delivery).to receive(:reflect).with(:gcm_canonical_id, '2', 'canonical123')
109
109
  perform
110
110
  end
111
111
 
@@ -121,9 +121,9 @@ describe Rpush::Daemon::Gcm::Delivery do
121
121
  ]
122
122
  }
123
123
 
124
- response.stub(body: JSON.dump(body))
125
- notification.stub(registration_ids: %w(1 2 3))
126
- delivery.should_receive(:reflect).with(:gcm_invalid_registration_id, app, 'NotRegistered', '2')
124
+ allow(response).to receive_messages(body: JSON.dump(body))
125
+ allow(notification).to receive_messages(registration_ids: %w(1 2 3))
126
+ expect(delivery).to receive(:reflect).with(:gcm_invalid_registration_id, app, 'NotRegistered', '2')
127
127
  perform_with_rescue
128
128
  end
129
129
 
@@ -136,15 +136,15 @@ describe Rpush::Daemon::Gcm::Delivery do
136
136
  }
137
137
  end
138
138
 
139
- before { response.stub(body: JSON.dump(body)) }
139
+ before { allow(response).to receive_messages(body: JSON.dump(body)) }
140
140
 
141
141
  it 'marks the notification as delivered' do
142
- delivery.should_receive(:mark_delivered)
142
+ expect(delivery).to receive(:mark_delivered)
143
143
  perform
144
144
  end
145
145
 
146
146
  it 'logs that the notification was delivered' do
147
- logger.should_receive(:info).with("[MyApp] #{notification.id} sent to xyz")
147
+ expect(logger).to receive(:info).with("[MyApp] #{notification.id} sent to xyz")
148
148
  perform
149
149
  end
150
150
  end
@@ -161,10 +161,10 @@ describe Rpush::Daemon::Gcm::Delivery do
161
161
  ]
162
162
  }
163
163
 
164
- response.stub(body: JSON.dump(body))
165
- delivery.should_receive(:mark_failed)
166
- delivery.should_not_receive(:mark_retryable)
167
- store.should_not_receive(:create_gcm_notification)
164
+ allow(response).to receive_messages(body: JSON.dump(body))
165
+ expect(delivery).to receive(:mark_failed)
166
+ expect(delivery).not_to receive(:mark_retryable)
167
+ expect(store).not_to receive(:create_gcm_notification)
168
168
  perform_with_rescue
169
169
  end
170
170
 
@@ -176,9 +176,9 @@ describe Rpush::Daemon::Gcm::Delivery do
176
176
  { 'message_id' => '1:000' },
177
177
  { 'error' => 'InvalidDataKey' }
178
178
  ] }
179
- response.stub(body: JSON.dump(body))
179
+ allow(response).to receive_messages(body: JSON.dump(body))
180
180
  error = Rpush::DeliveryError.new(nil, notification.id, 'Failed to deliver to all recipients. Errors: InvalidDataKey.')
181
- delivery.should_receive(:mark_failed).with(error)
181
+ expect(delivery).to receive(:mark_failed).with(error)
182
182
  perform_with_rescue
183
183
  end
184
184
 
@@ -195,30 +195,30 @@ describe Rpush::Daemon::Gcm::Delivery do
195
195
  end
196
196
 
197
197
  before do
198
- response.stub(body: JSON.dump(body))
199
- notification.stub(registration_ids: %w(1 2))
198
+ allow(response).to receive_messages(body: JSON.dump(body))
199
+ allow(notification).to receive_messages(registration_ids: %w(1 2))
200
200
  end
201
201
 
202
202
  it 'retries the notification respecting the Retry-After header' do
203
- response.stub(header: { 'retry-after' => 10 })
204
- delivery.should_receive(:mark_retryable).with(notification, now + 10.seconds)
203
+ allow(response).to receive_messages(header: { 'retry-after' => 10 })
204
+ expect(delivery).to receive(:mark_retryable).with(notification, now + 10.seconds)
205
205
  perform
206
206
  end
207
207
 
208
208
  it 'retries the notification using exponential back-off if the Retry-After header is not present' do
209
- delivery.should_receive(:mark_retryable).with(notification, now + 2)
209
+ expect(delivery).to receive(:mark_retryable).with(notification, now + 2)
210
210
  perform
211
211
  end
212
212
 
213
213
  it 'does not mark the notification as failed' do
214
- delivery.should_not_receive(:mark_failed)
214
+ expect(delivery).not_to receive(:mark_failed)
215
215
  perform
216
216
  end
217
217
 
218
218
  it 'logs that the notification will be retried' do
219
219
  notification.retries = 1
220
220
  notification.deliver_after = now + 2
221
- Rpush.logger.should_receive(:warn).with("[MyApp] All recipients unavailable. Notification #{notification.id} will be retried after 2012-10-14 00:00:02 (retry 1).")
221
+ expect(Rpush.logger).to receive(:warn).with("[MyApp] All recipients unavailable. Notification #{notification.id} will be retried after 2012-10-14 00:00:02 (retry 1).")
222
222
  perform
223
223
  end
224
224
  end
@@ -255,29 +255,29 @@ describe Rpush::Daemon::Gcm::Delivery do
255
255
  end
256
256
 
257
257
  describe 'a 503 response' do
258
- before { response.stub(code: 503) }
258
+ before { allow(response).to receive_messages(code: 503) }
259
259
 
260
260
  it 'logs a warning that the notification will be retried.' do
261
261
  notification.retries = 1
262
262
  notification.deliver_after = now + 2
263
- logger.should_receive(:warn).with("[MyApp] GCM responded with an Service Unavailable Error. Notification #{notification.id} will be retried after 2012-10-14 00:00:02 (retry 1).")
263
+ expect(logger).to receive(:warn).with("[MyApp] GCM responded with an Service Unavailable Error. Notification #{notification.id} will be retried after 2012-10-14 00:00:02 (retry 1).")
264
264
  perform
265
265
  end
266
266
 
267
267
  it 'respects an integer Retry-After header' do
268
- response.stub(header: { 'retry-after' => 10 })
269
- delivery.should_receive(:mark_retryable).with(notification, now + 10.seconds)
268
+ allow(response).to receive_messages(header: { 'retry-after' => 10 })
269
+ expect(delivery).to receive(:mark_retryable).with(notification, now + 10.seconds)
270
270
  perform
271
271
  end
272
272
 
273
273
  it 'respects a HTTP-date Retry-After header' do
274
- response.stub(header: { 'retry-after' => 'Wed, 03 Oct 2012 20:55:11 GMT' })
275
- delivery.should_receive(:mark_retryable).with(notification, Time.parse('Wed, 03 Oct 2012 20:55:11 GMT'))
274
+ allow(response).to receive_messages(header: { 'retry-after' => 'Wed, 03 Oct 2012 20:55:11 GMT' })
275
+ expect(delivery).to receive(:mark_retryable).with(notification, Time.parse('Wed, 03 Oct 2012 20:55:11 GMT'))
276
276
  perform
277
277
  end
278
278
 
279
279
  it 'defaults to exponential back-off if the Retry-After header is not present' do
280
- delivery.should_receive(:mark_retryable).with(notification, now + 2**1)
280
+ expect(delivery).to receive(:mark_retryable).with(notification, now + 2**1)
281
281
  perform
282
282
  end
283
283
  end
@@ -285,24 +285,24 @@ describe Rpush::Daemon::Gcm::Delivery do
285
285
  describe 'a 500 response' do
286
286
  before do
287
287
  notification.update_attribute(:retries, 2)
288
- response.stub(code: 500)
288
+ allow(response).to receive_messages(code: 500)
289
289
  end
290
290
 
291
291
  it 'logs a warning that the notification has been re-queued.' do
292
292
  notification.retries = 3
293
293
  notification.deliver_after = now + 2**3
294
- Rpush.logger.should_receive(:warn).with("[MyApp] GCM responded with an Internal Error. Notification #{notification.id} will be retried after #{(now + 2**3).strftime('%Y-%m-%d %H:%M:%S')} (retry 3).")
294
+ expect(Rpush.logger).to receive(:warn).with("[MyApp] GCM responded with an Internal Error. Notification #{notification.id} will be retried after #{(now + 2**3).strftime('%Y-%m-%d %H:%M:%S')} (retry 3).")
295
295
  perform
296
296
  end
297
297
 
298
298
  it 'retries the notification in accordance with the exponential back-off strategy.' do
299
- delivery.should_receive(:mark_retryable).with(notification, now + 2**3)
299
+ expect(delivery).to receive(:mark_retryable).with(notification, now + 2**3)
300
300
  perform
301
301
  end
302
302
  end
303
303
 
304
304
  describe 'a 401 response' do
305
- before { response.stub(code: 401) }
305
+ before { allow(response).to receive_messages(code: 401) }
306
306
 
307
307
  it 'raises an error' do
308
308
  expect { perform }.to raise_error(Rpush::DeliveryError)
@@ -310,21 +310,21 @@ describe Rpush::Daemon::Gcm::Delivery do
310
310
  end
311
311
 
312
312
  describe 'a 400 response' do
313
- before { response.stub(code: 400) }
313
+ before { allow(response).to receive_messages(code: 400) }
314
314
 
315
315
  it 'marks the notification as failed' do
316
316
  error = Rpush::DeliveryError.new(400, notification.id, 'GCM failed to parse the JSON request. Possibly an Rpush bug, please open an issue.')
317
- delivery.should_receive(:mark_failed).with(error)
317
+ expect(delivery).to receive(:mark_failed).with(error)
318
318
  perform_with_rescue
319
319
  end
320
320
  end
321
321
 
322
322
  describe 'an un-handled response' do
323
- before { response.stub(code: 418) }
323
+ before { allow(response).to receive_messages(code: 418) }
324
324
 
325
325
  it 'marks the notification as failed' do
326
326
  error = Rpush::DeliveryError.new(418, notification.id, "I'm a Teapot")
327
- delivery.should_receive(:mark_failed).with(error)
327
+ expect(delivery).to receive(:mark_failed).with(error)
328
328
  perform_with_rescue
329
329
  end
330
330
  end