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
@@ -4,26 +4,26 @@ describe Rpush::Client::ActiveRecord::App do
4
4
  it 'validates the uniqueness of name within type and environment' do
5
5
  Rpush::Client::ActiveRecord::Apns::App.create!(name: 'test', environment: 'production', certificate: TEST_CERT)
6
6
  app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'production', certificate: TEST_CERT)
7
- app.valid?.should be_false
8
- app.errors[:name].should eq ['has already been taken']
7
+ expect(app.valid?).to eq(false)
8
+ expect(app.errors[:name]).to eq ['has already been taken']
9
9
 
10
10
  app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'development', certificate: TEST_CERT)
11
- app.valid?.should be_true
11
+ expect(app.valid?).to eq(true)
12
12
 
13
13
  app = Rpush::Client::ActiveRecord::Gcm::App.new(name: 'test', environment: 'production', auth_key: TEST_CERT)
14
- app.valid?.should be_true
14
+ expect(app.valid?).to eq(true)
15
15
  end
16
16
 
17
17
  context 'validating certificates' do
18
18
  it 'rescues from certificate error' do
19
19
  app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'development', certificate: 'bad')
20
20
  expect { app.valid? }.not_to raise_error
21
- expect(app.valid?).to be_false
21
+ expect(app.valid?).to eq(false)
22
22
  end
23
23
 
24
24
  it 'raises other errors' do
25
25
  app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'development', certificate: 'bad')
26
- OpenSSL::X509::Certificate.stub(:new).and_raise(NameError, 'simulating no openssl')
26
+ allow(OpenSSL::X509::Certificate).to receive(:new).and_raise(NameError, 'simulating no openssl')
27
27
  expect { app.valid? }.to raise_error(NameError)
28
28
  end
29
29
  end
@@ -10,25 +10,25 @@ describe Rpush::Client::ActiveRecord::Gcm::Notification do
10
10
 
11
11
  it "has a 'data' payload limit of 4096 bytes" do
12
12
  notification.data = { key: "a" * 4096 }
13
- notification.valid?.should be_false
14
- notification.errors[:base].should eq ["Notification payload data cannot be larger than 4096 bytes."]
13
+ expect(notification.valid?).to be_falsey
14
+ expect(notification.errors[:base]).to eq ["Notification payload data cannot be larger than 4096 bytes."]
15
15
  end
16
16
 
17
17
  it 'limits the number of registration ids to 1000' do
18
18
  notification.registration_ids = ['a'] * (1000 + 1)
19
- notification.valid?.should be_false
20
- notification.errors[:base].should eq ["Number of registration_ids cannot be larger than 1000."]
19
+ expect(notification.valid?).to be_falsey
20
+ expect(notification.errors[:base]).to eq ["Number of registration_ids cannot be larger than 1000."]
21
21
  end
22
22
 
23
23
  it 'validates expiry is present if collapse_key is set' do
24
24
  notification.collapse_key = 'test'
25
25
  notification.expiry = nil
26
- notification.valid?.should be_false
27
- notification.errors[:expiry].should eq ['must be set when using a collapse_key']
26
+ expect(notification.valid?).to be_falsey
27
+ expect(notification.errors[:expiry]).to eq ['must be set when using a collapse_key']
28
28
  end
29
29
 
30
30
  it 'includes time_to_live in the payload' do
31
31
  notification.expiry = 100
32
- notification.as_json['time_to_live'].should eq 100
32
+ expect(notification.as_json['time_to_live']).to eq 100
33
33
  end
34
34
  end
@@ -5,12 +5,12 @@ describe Rpush::Client::ActiveRecord::Notification do
5
5
 
6
6
  it 'allows assignment of many registration IDs' do
7
7
  notification.registration_ids = %w(a b)
8
- notification.registration_ids.should eq %w(a b)
8
+ expect(notification.registration_ids).to eq %w(a b)
9
9
  end
10
10
 
11
11
  it 'allows assignment of a single registration ID' do
12
12
  notification.registration_ids = 'a'
13
- notification.registration_ids.should eq ['a']
13
+ expect(notification.registration_ids).to eq ['a']
14
14
  end
15
15
 
16
16
  it 'saves its parent App if required' do
@@ -10,18 +10,12 @@ describe Rpush::Client::ActiveRecord::Wpns::Notification do
10
10
  it "should have an url in the uri parameter" do
11
11
  notification = Rpush::Client::ActiveRecord::Wpns::Notification.new(uri: "somthing")
12
12
  notification.valid?
13
- notification.errors[:uri].include?("is invalid").should be_true
13
+ expect(notification.errors[:uri]).to include('is invalid')
14
14
  end
15
15
 
16
16
  it "should be invalid if there's no data" do
17
17
  notification = Rpush::Client::ActiveRecord::Wpns::Notification.new(data: {})
18
18
  notification.valid?
19
- notification.errors[:data].include?("can't be blank").should be_true
20
- end
21
-
22
- it "should be invalid if there's no alert" do
23
- notification = Rpush::Client::ActiveRecord::Wpns::Notification.new(alert: nil)
24
- notification.valid?
25
- notification.errors[:data].include?("can't be blank").should be_true
19
+ expect(notification.errors[:data]).to include("can't be blank")
26
20
  end
27
21
  end
@@ -4,8 +4,8 @@ describe Rpush do
4
4
  let(:config) { Rpush.config }
5
5
 
6
6
  before do
7
- Rpush.stub(require: nil)
8
- Rpush.stub(config: config)
7
+ allow(Rpush).to receive_messages(require: nil)
8
+ allow(Rpush).to receive_messages(config: config)
9
9
  end
10
10
 
11
11
  it 'yields a configure block' do
@@ -30,17 +30,17 @@ describe Rpush::Configuration do
30
30
 
31
31
  it 'sets the pid_file relative if not absolute' do
32
32
  config.pid_file = 'tmp/rpush.pid'
33
- config.pid_file.should eq '/tmp/rails_root/tmp/rpush.pid'
33
+ expect(config.pid_file).to eq '/tmp/rails_root/tmp/rpush.pid'
34
34
  end
35
35
 
36
36
  it 'does not alter an absolute pid_file path' do
37
37
  config.pid_file = '/tmp/rpush.pid'
38
- config.pid_file.should eq '/tmp/rpush.pid'
38
+ expect(config.pid_file).to eq '/tmp/rpush.pid'
39
39
  end
40
40
 
41
41
  it 'delegate redis_options to Modis' do
42
42
  Rpush.config.client = :redis
43
43
  Rpush.config.redis_options = { hi: :mom }
44
- Modis.redis_options.should eq(hi: :mom)
44
+ expect(Modis.redis_options).to eq(hi: :mom)
45
45
  end
46
46
  end
@@ -19,72 +19,72 @@ describe Rpush::Daemon::Adm::Delivery do
19
19
  app.access_token = 'ACCESS_TOKEN'
20
20
  app.access_token_expiration = Time.now + 1.month
21
21
 
22
- delivery.stub(reflect: nil)
23
- Rpush::Daemon.stub(store: store)
24
- Time.stub(now: now)
25
- Rpush.stub(logger: logger)
22
+ allow(delivery).to receive_messages(reflect: nil)
23
+ allow(Rpush::Daemon).to receive_messages(store: store)
24
+ allow(Time).to receive_messages(now: now)
25
+ allow(Rpush).to receive_messages(logger: logger)
26
26
  end
27
27
 
28
28
  describe 'unknown error response' do
29
29
  before do
30
- response.stub(code: 408)
30
+ allow(response).to receive_messages(code: 408)
31
31
  end
32
32
 
33
33
  it 'marks the notification as failed because no successful delivery was made' do
34
- response.stub(body: JSON.dump('reason' => 'InvalidData'))
34
+ allow(response).to receive_messages(body: JSON.dump('reason' => 'InvalidData'))
35
35
  error = Rpush::DeliveryError.new(408, notification.id, 'Request Timeout')
36
- delivery.should_receive(:mark_failed).with(error)
36
+ expect(delivery).to receive(:mark_failed).with(error)
37
37
  expect { perform }.to raise_error(Rpush::DeliveryError)
38
38
  end
39
39
  end
40
40
 
41
41
  describe 'a 200 (Ok) response' do
42
42
  before do
43
- response.stub(code: 200)
43
+ allow(response).to receive_messages(code: 200)
44
44
  end
45
45
 
46
46
  it 'marks the notification as delivered if delivered successfully to all devices' do
47
- response.stub(body: JSON.dump('registrationID' => 'xyz'))
48
- delivery.should_receive(:mark_delivered)
47
+ allow(response).to receive_messages(body: JSON.dump('registrationID' => 'xyz'))
48
+ expect(delivery).to receive(:mark_delivered)
49
49
  perform
50
50
  end
51
51
 
52
52
  it 'logs that the notification was delivered' do
53
- response.stub(body: JSON.dump('registrationID' => 'xyz'))
54
- logger.should_receive(:info).with("[MyApp] #{notification.id} sent to xyz")
53
+ allow(response).to receive_messages(body: JSON.dump('registrationID' => 'xyz'))
54
+ expect(logger).to receive(:info).with("[MyApp] #{notification.id} sent to xyz")
55
55
  perform
56
56
  end
57
57
 
58
58
  it 'reflects on canonical IDs' do
59
- response.stub(body: JSON.dump('registrationID' => 'canonical123'))
60
- notification.stub(registration_ids: ['1'])
61
- delivery.should_receive(:reflect).with(:adm_canonical_id, '1', 'canonical123')
59
+ allow(response).to receive_messages(body: JSON.dump('registrationID' => 'canonical123'))
60
+ allow(notification).to receive_messages(registration_ids: ['1'])
61
+ expect(delivery).to receive(:reflect).with(:adm_canonical_id, '1', 'canonical123')
62
62
  perform
63
63
  end
64
64
  end
65
65
 
66
66
  describe 'a 400 (Bad Request) response' do
67
67
  before do
68
- response.stub(code: 400)
68
+ allow(response).to receive_messages(code: 400)
69
69
  end
70
70
 
71
71
  it 'marks the notification as failed because no successful delivery was made' do
72
- response.stub(body: JSON.dump('reason' => 'InvalidData'))
72
+ allow(response).to receive_messages(body: JSON.dump('reason' => 'InvalidData'))
73
73
  error = Rpush::DeliveryError.new(nil, notification.id, 'Failed to deliver to all recipients.')
74
- delivery.should_receive(:mark_failed).with(error)
74
+ expect(delivery).to receive(:mark_failed).with(error)
75
75
  expect { perform }.to raise_error(error)
76
76
  end
77
77
 
78
78
  it 'logs that the notification was not delivered' do
79
- response.stub(body: JSON.dump('reason' => 'InvalidRegistrationId'))
80
- logger.should_receive(:warn).with("[MyApp] bad_request: xyz (InvalidRegistrationId)")
79
+ allow(response).to receive_messages(body: JSON.dump('reason' => 'InvalidRegistrationId'))
80
+ expect(logger).to receive(:warn).with("[MyApp] bad_request: xyz (InvalidRegistrationId)")
81
81
  expect { perform }.to raise_error
82
82
  end
83
83
 
84
84
  it 'reflects' do
85
- response.stub(body: JSON.dump('registrationID' => 'canonical123', 'reason' => 'Unregistered'))
86
- notification.stub(registration_ids: ['1'])
87
- delivery.should_receive(:reflect).with(:adm_failed_to_recipient, notification, '1', 'Unregistered')
85
+ allow(response).to receive_messages(body: JSON.dump('registrationID' => 'canonical123', 'reason' => 'Unregistered'))
86
+ allow(notification).to receive_messages(registration_ids: ['1'])
87
+ expect(delivery).to receive(:reflect).with(:adm_failed_to_recipient, notification, '1', 'Unregistered')
88
88
  expect { perform }.to raise_error
89
89
  end
90
90
  end
@@ -94,45 +94,45 @@ describe Rpush::Daemon::Adm::Delivery do
94
94
  let(:token_response) { double(code: 200, header: {}, body: JSON.dump('access_token' => 'ACCESS_TOKEN', 'expires_in' => 60)) }
95
95
 
96
96
  before do
97
- response.stub(code: 401, header: { 'retry-after' => 10 })
97
+ allow(response).to receive_messages(code: 401, header: { 'retry-after' => 10 })
98
98
 
99
99
  # first request to deliver message that returns unauthorized response
100
100
  adm_uri = URI.parse(format(Rpush::Daemon::Adm::Delivery::AMAZON_ADM_URL, notification.registration_ids.first))
101
- http.should_receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(response)
101
+ expect(http).to receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(response)
102
102
  end
103
103
 
104
104
  it 'should retrieve a new access token and mark the notification for retry' do
105
105
  # request for access token
106
- http.should_receive(:request).with(Rpush::Daemon::Adm::Delivery::AMAZON_TOKEN_URI, instance_of(Net::HTTP::Post)).and_return(token_response)
106
+ expect(http).to receive(:request).with(Rpush::Daemon::Adm::Delivery::AMAZON_TOKEN_URI, instance_of(Net::HTTP::Post)).and_return(token_response)
107
107
 
108
- store.should_receive(:update_app).with(notification.app)
109
- delivery.should_receive(:mark_retryable).with(notification, now)
108
+ expect(store).to receive(:update_app).with(notification.app)
109
+ expect(delivery).to receive(:mark_retryable).with(notification, now)
110
110
 
111
111
  perform
112
112
  end
113
113
 
114
114
  it 'should update the app with the new access token' do
115
115
  # request for access token
116
- http.should_receive(:request).with(Rpush::Daemon::Adm::Delivery::AMAZON_TOKEN_URI, instance_of(Net::HTTP::Post)).and_return(token_response)
116
+ expect(http).to receive(:request).with(Rpush::Daemon::Adm::Delivery::AMAZON_TOKEN_URI, instance_of(Net::HTTP::Post)).and_return(token_response)
117
117
 
118
- store.should_receive(:update_app).with do |app|
119
- app.access_token.should eq 'ACCESS_TOKEN'
120
- app.access_token_expiration.should eq now + 60.seconds
118
+ expect(store).to receive(:update_app) do |app|
119
+ expect(app.access_token).to eq 'ACCESS_TOKEN'
120
+ expect(app.access_token_expiration).to eq now + 60.seconds
121
121
  end
122
- delivery.should_receive(:mark_retryable).with(notification, now)
122
+ expect(delivery).to receive(:mark_retryable).with(notification, now)
123
123
 
124
124
  perform
125
125
  end
126
126
 
127
127
  it 'should log the error and stop retrying if new access token can\'t be retrieved' do
128
- token_response.stub(code: 404, body: "test")
128
+ allow(token_response).to receive_messages(code: 404, body: "test")
129
129
  # request for access token
130
- http.should_receive(:request).with(Rpush::Daemon::Adm::Delivery::AMAZON_TOKEN_URI, instance_of(Net::HTTP::Post)).and_return(token_response)
130
+ expect(http).to receive(:request).with(Rpush::Daemon::Adm::Delivery::AMAZON_TOKEN_URI, instance_of(Net::HTTP::Post)).and_return(token_response)
131
131
 
132
- store.should_not_receive(:update_app).with(notification.app)
133
- delivery.should_not_receive(:mark_retryable)
132
+ expect(store).not_to receive(:update_app).with(notification.app)
133
+ expect(delivery).not_to receive(:mark_retryable)
134
134
 
135
- logger.should_receive(:warn).with("[MyApp] Could not retrieve access token from ADM: test")
135
+ expect(logger).to receive(:warn).with("[MyApp] Could not retrieve access token from ADM: test")
136
136
 
137
137
  perform
138
138
  end
@@ -144,54 +144,54 @@ describe Rpush::Daemon::Adm::Delivery do
144
144
  let(:rate_limited_response) { double(code: 429, header: { 'retry-after' => 3600 }) }
145
145
 
146
146
  it 'should retry the entire notification respecting the Retry-After header if none sent out yet' do
147
- response.stub(code: 429, header: { 'retry-after' => 3600 })
147
+ allow(response).to receive_messages(code: 429, header: { 'retry-after' => 3600 })
148
148
 
149
149
  # first request to deliver message that returns too many request response
150
150
  adm_uri = URI.parse(format(Rpush::Daemon::Adm::Delivery::AMAZON_ADM_URL, notification.registration_ids.first))
151
- http.should_receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(response)
151
+ expect(http).to receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(response)
152
152
 
153
- delivery.should_receive(:mark_retryable).with(notification, now + 1.hour)
153
+ expect(delivery).to receive(:mark_retryable).with(notification, now + 1.hour)
154
154
  perform
155
155
  end
156
156
 
157
157
  it 'should retry the entire notification using exponential backoff' do
158
- response.stub(code: 429, header: {})
158
+ allow(response).to receive_messages(code: 429, header: {})
159
159
 
160
160
  # first request to deliver message that returns too many request response
161
161
  adm_uri = URI.parse(format(Rpush::Daemon::Adm::Delivery::AMAZON_ADM_URL, notification.registration_ids.first))
162
- http.should_receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(response)
162
+ expect(http).to receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(response)
163
163
 
164
- delivery.should_receive(:mark_retryable).with(notification, Time.now + 2**(notification.retries + 1))
164
+ expect(delivery).to receive(:mark_retryable).with(notification, Time.now + 2**(notification.retries + 1))
165
165
  perform
166
166
  end
167
167
 
168
168
  it 'should keep sent reg ids in original notification and create new notification with remaining reg ids for retry' do
169
- response.stub(code: 200, body: JSON.dump('registrationID' => 'abc'))
169
+ allow(response).to receive_messages(code: 200, body: JSON.dump('registrationID' => 'abc'))
170
170
 
171
171
  # first request to deliver message succeeds
172
172
  adm_uri = URI.parse(format(Rpush::Daemon::Adm::Delivery::AMAZON_ADM_URL, 'abc'))
173
- http.should_receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(response)
173
+ expect(http).to receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(response)
174
174
 
175
175
  # first request to deliver message that returns too many request response
176
176
  adm_uri = URI.parse(format(Rpush::Daemon::Adm::Delivery::AMAZON_ADM_URL, 'xyz'))
177
- http.should_receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(rate_limited_response)
177
+ expect(http).to receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(rate_limited_response)
178
178
 
179
- store.should_receive(:update_notification).with do |notif|
180
- notif.registration_ids.include?('abc').should be_true
181
- notif.registration_ids.include?('xyz').should be_false
179
+ expect(store).to receive(:update_notification) do |notif|
180
+ expect(notif.registration_ids).to include('abc')
181
+ expect(notif.registration_ids).to_not include('xyz')
182
182
  end
183
183
 
184
- store.should_receive(:create_adm_notification).with do |attrs, _notification_data, reg_ids, deliver_after, notification_app|
185
- attrs.key?('collapse_key').should be_true
186
- attrs.key?('delay_while_idle').should be_true
187
- attrs.key?('app_id').should be_true
184
+ expect(store).to receive(:create_adm_notification) do |attrs, _notification_data, reg_ids, deliver_after, notification_app|
185
+ expect(attrs.keys).to include('collapse_key')
186
+ expect(attrs.keys).to include('delay_while_idle')
187
+ expect(attrs.keys).to include('app_id')
188
188
 
189
- reg_ids.should eq ['xyz']
190
- deliver_after.should eq now + 1.hour
191
- notification_app.should eq notification.app
189
+ expect(reg_ids).to eq ['xyz']
190
+ expect(deliver_after).to eq now + 1.hour
191
+ expect(notification_app).to eq notification.app
192
192
  end
193
193
 
194
- delivery.should_receive(:mark_delivered)
194
+ expect(delivery).to receive(:mark_delivered)
195
195
 
196
196
  perform
197
197
  end
@@ -199,28 +199,28 @@ describe Rpush::Daemon::Adm::Delivery do
199
199
 
200
200
  describe 'a 500 (Internal Server Error) response' do
201
201
  before do
202
- response.stub(code: 500)
202
+ allow(response).to receive_messages(code: 500)
203
203
  end
204
204
 
205
205
  it 'marks the notification as failed because no successful delivery was made' do
206
206
  error = Rpush::DeliveryError.new(nil, notification.id, 'Failed to deliver to all recipients.')
207
- delivery.should_receive(:mark_failed).with(error)
207
+ expect(delivery).to receive(:mark_failed).with(error)
208
208
  expect { perform }.to raise_error(Rpush::DeliveryError)
209
209
  end
210
210
 
211
211
  it 'logs that the notification was not delivered' do
212
- logger.should_receive(:warn).with("[MyApp] internal_server_error: xyz (Internal Server Error)")
212
+ expect(logger).to receive(:warn).with("[MyApp] internal_server_error: xyz (Internal Server Error)")
213
213
  expect { perform }.to raise_error(Rpush::DeliveryError)
214
214
  end
215
215
  end
216
216
 
217
217
  describe 'a 503 (Service Unavailable) response' do
218
218
  before do
219
- response.stub(code: 503, header: { 'retry-after' => 10 })
219
+ allow(response).to receive_messages(code: 503, header: { 'retry-after' => 10 })
220
220
  end
221
221
 
222
222
  it 'should retry the notification respecting the Retry-After header' do
223
- delivery.should_receive(:mark_retryable).with(notification, now + 10.seconds)
223
+ expect(delivery).to receive(:mark_retryable).with(notification, now + 10.seconds)
224
224
  perform
225
225
  end
226
226
  end
@@ -231,21 +231,21 @@ describe Rpush::Daemon::Adm::Delivery do
231
231
  let(:bad_request_response) { double(code: 400, body: JSON.dump('reason' => 'InvalidData')) }
232
232
 
233
233
  it 'should keep sent reg ids in original notification and create new notification with remaining reg ids for retry' do
234
- response.stub(code: 200, body: JSON.dump('registrationID' => 'abc'))
234
+ allow(response).to receive_messages(code: 200, body: JSON.dump('registrationID' => 'abc'))
235
235
 
236
236
  # first request to deliver message succeeds
237
237
  adm_uri = URI.parse(format(Rpush::Daemon::Adm::Delivery::AMAZON_ADM_URL, 'abc'))
238
- http.should_receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(response)
238
+ expect(http).to receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(response)
239
239
 
240
240
  # first request to deliver message that returns too many request response
241
241
  adm_uri = URI.parse(format(Rpush::Daemon::Adm::Delivery::AMAZON_ADM_URL, 'xyz'))
242
- http.should_receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(bad_request_response)
242
+ expect(http).to receive(:request).with(adm_uri, instance_of(Net::HTTP::Post)).and_return(bad_request_response)
243
243
 
244
- store.should_receive(:update_notification).with do |notif|
245
- notif.error_description.should eq "Failed to deliver to recipients: \nxyz: InvalidData"
244
+ expect(store).to receive(:update_notification) do |notif|
245
+ expect(notif.error_description).to eq "Failed to deliver to recipients: \nxyz: InvalidData"
246
246
  end
247
247
 
248
- delivery.should_receive(:mark_delivered)
248
+ expect(delivery).to receive(:mark_delivered)
249
249
 
250
250
  perform
251
251
  end
@@ -10,42 +10,42 @@ describe Rpush::Daemon::Apns::Delivery do
10
10
  let(:delivery) { Rpush::Daemon::Apns::Delivery.new(app, connection, batch) }
11
11
 
12
12
  before do
13
- batch.stub(:each_notification) do |&blk|
13
+ allow(batch).to receive(:each_notification) do |&blk|
14
14
  [notification1, notification2].each(&blk)
15
15
  end
16
- Rpush.stub(logger: logger)
16
+ allow(Rpush).to receive_messages(logger: logger)
17
17
  end
18
18
 
19
19
  it 'writes the binary batch' do
20
- notification1.stub(to_binary: 'binary1')
21
- notification2.stub(to_binary: 'binary2')
22
- connection.should_receive(:write).with('binary1binary2')
20
+ allow(notification1).to receive_messages(to_binary: 'binary1')
21
+ allow(notification2).to receive_messages(to_binary: 'binary2')
22
+ expect(connection).to receive(:write).with('binary1binary2')
23
23
  delivery.perform
24
24
  end
25
25
 
26
26
  it 'logs the notification deliveries' do
27
- notification1.stub(id: 666, device_token: 'abc123')
28
- notification2.stub(id: 42, device_token: 'abc456')
29
- logger.should_receive(:info).with('[MyApp] 666 sent to abc123')
30
- logger.should_receive(:info).with('[MyApp] 42 sent to abc456')
27
+ allow(notification1).to receive_messages(id: 666, device_token: 'abc123')
28
+ allow(notification2).to receive_messages(id: 42, device_token: 'abc456')
29
+ expect(logger).to receive(:info).with('[MyApp] 666 sent to abc123')
30
+ expect(logger).to receive(:info).with('[MyApp] 42 sent to abc456')
31
31
  delivery.perform
32
32
  end
33
33
 
34
34
  it 'marks all notifications as delivered' do
35
- delivery.should_receive(:mark_batch_delivered)
35
+ expect(delivery).to receive(:mark_batch_delivered)
36
36
  delivery.perform
37
37
  end
38
38
 
39
39
  it 'notifies the batch all notifications have been processed' do
40
- batch.should_receive(:all_processed)
40
+ expect(batch).to receive(:all_processed)
41
41
  delivery.perform
42
42
  end
43
43
 
44
44
  describe 'when an error is raised' do
45
45
  it 'marks all notifications as failed' do
46
46
  error = StandardError.new
47
- connection.stub(:write).and_raise(error)
48
- delivery.should_receive(:mark_batch_failed).with(error)
47
+ allow(connection).to receive(:write).and_raise(error)
48
+ expect(delivery).to receive(:mark_batch_failed).with(error)
49
49
  expect { delivery.perform }.to raise_error(error)
50
50
  end
51
51
  end