rpush 4.0.1 → 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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +252 -162
  3. data/README.md +1 -1
  4. data/lib/generators/rpush_migration_generator.rb +3 -0
  5. data/lib/generators/templates/rpush_4_1_0_updates.rb +9 -0
  6. data/lib/generators/templates/rpush_4_1_1_updates.rb +9 -0
  7. data/lib/generators/templates/rpush_4_2_0_updates.rb +10 -0
  8. data/lib/rpush/apns_feedback.rb +1 -0
  9. data/lib/rpush/cli.rb +9 -22
  10. data/lib/rpush/client/active_model.rb +1 -1
  11. data/lib/rpush/client/active_model/apns/notification.rb +9 -1
  12. data/lib/rpush/client/active_model/apns/notification_payload_size_validator.rb +15 -0
  13. data/lib/rpush/client/active_model/apns2/notification.rb +14 -0
  14. data/lib/rpush/client/active_model/gcm/notification.rb +6 -3
  15. data/lib/rpush/client/active_model/wns/notification.rb +8 -0
  16. data/lib/rpush/client/active_record.rb +1 -0
  17. data/lib/rpush/client/active_record/apns/active_record_serializable_notification.rb +65 -0
  18. data/lib/rpush/client/active_record/apns/notification.rb +1 -29
  19. data/lib/rpush/client/active_record/apns2/notification.rb +4 -1
  20. data/lib/rpush/client/active_record/app.rb +1 -1
  21. data/lib/rpush/client/active_record/notification.rb +1 -1
  22. data/lib/rpush/client/redis/apns2/notification.rb +1 -0
  23. data/lib/rpush/client/redis/app.rb +2 -1
  24. data/lib/rpush/client/redis/notification.rb +3 -1
  25. data/lib/rpush/client/redis/pushy/notification.rb +0 -1
  26. data/lib/rpush/daemon.rb +2 -2
  27. data/lib/rpush/daemon/apns/feedback_receiver.rb +2 -1
  28. data/lib/rpush/daemon/apns2/delivery.rb +6 -1
  29. data/lib/rpush/daemon/apnsp8/delivery.rb +7 -2
  30. data/lib/rpush/daemon/app_runner.rb +1 -1
  31. data/lib/rpush/daemon/dispatcher/apns_http2.rb +4 -2
  32. data/lib/rpush/daemon/dispatcher/apnsp8_http2.rb +2 -1
  33. data/lib/rpush/daemon/signal_handler.rb +1 -1
  34. data/lib/rpush/daemon/store/active_record.rb +1 -1
  35. data/lib/rpush/daemon/store/active_record/reconnectable.rb +1 -1
  36. data/lib/rpush/daemon/store/redis.rb +1 -1
  37. data/lib/rpush/daemon/wns/badge_request.rb +8 -3
  38. data/lib/rpush/daemon/wns/raw_request.rb +9 -2
  39. data/lib/rpush/daemon/wns/toast_request.rb +6 -2
  40. data/lib/rpush/version.rb +3 -3
  41. data/spec/.rubocop.yml +1 -1
  42. data/spec/functional/apns2_spec.rb +36 -0
  43. data/spec/functional/gcm_priority_spec.rb +40 -0
  44. data/spec/support/active_record_setup.rb +7 -1
  45. data/spec/support/simplecov_helper.rb +1 -1
  46. data/spec/unit/apns_feedback_spec.rb +17 -6
  47. data/spec/unit/client/active_record/adm/app_spec.rb +2 -54
  48. data/spec/unit/client/active_record/adm/notification_spec.rb +2 -39
  49. data/spec/unit/client/active_record/apns/app_spec.rb +3 -26
  50. data/spec/unit/client/active_record/apns/feedback_spec.rb +1 -5
  51. data/spec/unit/client/active_record/apns/notification_spec.rb +29 -288
  52. data/spec/unit/client/active_record/apns2/app_spec.rb +4 -0
  53. data/spec/unit/client/active_record/apns2/notification_spec.rb +65 -0
  54. data/spec/unit/client/active_record/app_spec.rb +1 -26
  55. data/spec/unit/client/active_record/gcm/app_spec.rb +3 -1
  56. data/spec/unit/client/active_record/gcm/notification_spec.rb +7 -60
  57. data/spec/unit/client/active_record/notification_spec.rb +10 -11
  58. data/spec/unit/client/active_record/pushy/app_spec.rb +2 -13
  59. data/spec/unit/client/active_record/pushy/notification_spec.rb +2 -55
  60. data/spec/unit/client/active_record/shared/app.rb +14 -0
  61. data/spec/unit/{notification_shared.rb → client/active_record/shared/notification.rb} +12 -7
  62. data/spec/unit/client/active_record/wns/badge_notification_spec.rb +1 -11
  63. data/spec/unit/client/active_record/wns/raw_notification_spec.rb +3 -12
  64. data/spec/unit/client/active_record/wpns/app_spec.rb +3 -1
  65. data/spec/unit/client/active_record/wpns/notification_spec.rb +2 -17
  66. data/spec/unit/client/redis/adm/app_spec.rb +5 -0
  67. data/spec/unit/client/redis/adm/notification_spec.rb +5 -0
  68. data/spec/unit/client/redis/apns/app_spec.rb +5 -0
  69. data/spec/unit/client/redis/apns/feedback_spec.rb +5 -0
  70. data/spec/unit/client/redis/apns/notification_spec.rb +50 -0
  71. data/spec/unit/client/redis/apns2/app_spec.rb +4 -0
  72. data/spec/unit/client/redis/apns2/notification_spec.rb +50 -0
  73. data/spec/unit/client/redis/app_spec.rb +5 -0
  74. data/spec/unit/client/redis/gcm/app_spec.rb +5 -0
  75. data/spec/unit/client/redis/gcm/notification_spec.rb +5 -0
  76. data/spec/unit/client/redis/notification_spec.rb +5 -0
  77. data/spec/unit/client/redis/pushy/app_spec.rb +5 -0
  78. data/spec/unit/client/redis/pushy/notification_spec.rb +5 -0
  79. data/spec/unit/client/redis/wns/badge_notification_spec.rb +5 -0
  80. data/spec/unit/client/redis/wns/raw_notification_spec.rb +22 -0
  81. data/spec/unit/client/redis/wpns/app_spec.rb +5 -0
  82. data/spec/unit/client/redis/wpns/notification_spec.rb +5 -0
  83. data/spec/unit/client/shared/adm/app.rb +51 -0
  84. data/spec/unit/client/shared/adm/notification.rb +39 -0
  85. data/spec/unit/client/shared/apns/app.rb +29 -0
  86. data/spec/unit/client/shared/apns/feedback.rb +9 -0
  87. data/spec/unit/client/shared/apns/notification.rb +262 -0
  88. data/spec/unit/client/shared/app.rb +17 -0
  89. data/spec/unit/client/shared/gcm/app.rb +4 -0
  90. data/spec/unit/client/shared/gcm/notification.rb +77 -0
  91. data/spec/unit/client/shared/notification.rb +10 -0
  92. data/spec/unit/client/shared/pushy/app.rb +17 -0
  93. data/spec/unit/client/shared/pushy/notification.rb +55 -0
  94. data/spec/unit/client/shared/wns/badge_notification.rb +15 -0
  95. data/spec/unit/client/shared/wns/raw_notification.rb +21 -0
  96. data/spec/unit/client/shared/wpns/app.rb +4 -0
  97. data/spec/unit/client/shared/wpns/notification.rb +18 -0
  98. data/spec/unit/daemon/apns/feedback_receiver_spec.rb +19 -1
  99. data/spec/unit/daemon/gcm/delivery_spec.rb +1 -1
  100. data/spec/unit/daemon/shared/store.rb +312 -0
  101. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +7 -7
  102. data/spec/unit/daemon/store/active_record_spec.rb +7 -295
  103. data/spec/unit/daemon/store/redis_spec.rb +4 -293
  104. data/spec/unit/daemon/wns/post_request_spec.rb +64 -0
  105. data/spec/unit_spec_helper.rb +3 -0
  106. metadata +120 -15
  107. data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +0 -16
@@ -3,6 +3,7 @@ module Rpush
3
3
  module Redis
4
4
  module Apns2
5
5
  class Notification < Rpush::Client::Redis::Notification
6
+ include Rpush::Client::ActiveModel::Apns::Notification
6
7
  include Rpush::Client::ActiveModel::Apns2::Notification
7
8
  end
8
9
  end
@@ -18,7 +18,8 @@ module Rpush
18
18
  attribute :apn_key_id, :string
19
19
  attribute :team_id, :string
20
20
  attribute :bundle_id, :string
21
-
21
+ attribute :feedback_enabled, :boolean, default: true
22
+
22
23
  index :name
23
24
 
24
25
  validates :name, presence: true
@@ -20,7 +20,7 @@ module Rpush
20
20
 
21
21
  attribute :badge, :integer
22
22
  attribute :device_token, :string
23
- attribute :sound, :string, default: 'default'
23
+ attribute :sound, [:string, :hash], strict: false, default: 'default'
24
24
  attribute :alert, [:string, :hash], strict: false
25
25
  attribute :data, :hash
26
26
  attribute :expiry, :integer, default: 1.day.to_i
@@ -34,6 +34,7 @@ module Rpush
34
34
  attribute :error_description, :string
35
35
  attribute :deliver_after, :timestamp
36
36
  attribute :alert_is_json, :boolean
37
+ attribute :sound_is_json, :boolean
37
38
  attribute :app_id, :integer
38
39
  attribute :collapse_key, :string
39
40
  attribute :delay_while_idle, :boolean
@@ -43,6 +44,7 @@ module Rpush
43
44
  attribute :url_args, :array
44
45
  attribute :category, :string
45
46
  attribute :content_available, :boolean, default: false
47
+ attribute :dry_run, :boolean, default: false
46
48
  attribute :mutable_content, :boolean, default: false
47
49
  attribute :notification, :hash
48
50
  attribute :thread_id, :string
@@ -9,7 +9,6 @@ module Rpush
9
9
 
10
10
  def time_to_live=(value)
11
11
  self.expiry = value
12
- super
13
12
  end
14
13
  end
15
14
  end
@@ -109,7 +109,7 @@ module Rpush
109
109
  Feeder.stop
110
110
  AppRunner.stop
111
111
  delete_pid_file
112
- puts ANSI.green { '✔' } if Rpush.config.foreground
112
+ puts Rainbow('✔').red if Rpush.config.foreground
113
113
  end
114
114
  end
115
115
 
@@ -168,7 +168,7 @@ module Rpush
168
168
  if Rpush::Daemon::AppRunner.app_ids.count == 0
169
169
  puts <<-EOS
170
170
 
171
- * #{ANSI.green { 'Is this your first time using Rpush?' }}
171
+ * #{Rainbow('Is this your first time using Rpush?').green}
172
172
  You need to create an App before you can start using Rpush.
173
173
  Please refer to the documentation at https://github.com/rpush/rpush
174
174
 
@@ -24,6 +24,7 @@ module Rpush
24
24
 
25
25
  def start
26
26
  return if Rpush.config.push
27
+ return unless @app.feedback_enabled
27
28
  Rpush.logger.info("[#{@app.name}] Starting feedback receiver... ", true)
28
29
 
29
30
  @thread = Thread.new do
@@ -36,7 +37,7 @@ module Rpush
36
37
  Rpush::Daemon.store.release_connection
37
38
  end
38
39
 
39
- puts ANSI.green { '✔' } if Rpush.config.foreground
40
+ puts Rainbow('✔').green if Rpush.config.foreground
40
41
  end
41
42
 
42
43
  def stop
@@ -7,6 +7,7 @@ module Rpush
7
7
 
8
8
  class Delivery < Rpush::Daemon::Delivery
9
9
  RETRYABLE_CODES = [ 429, 500, 503 ]
10
+ CLIENT_JOIN_TIMEOUT = 60
10
11
 
11
12
  def initialize(app, http2_client, batch)
12
13
  @app = app
@@ -20,7 +21,11 @@ module Rpush
20
21
  end
21
22
 
22
23
  # Send all preprocessed requests at once
23
- @client.join
24
+ @client.join(timeout: CLIENT_JOIN_TIMEOUT)
25
+ rescue NetHttp2::AsyncRequestTimeout => error
26
+ mark_batch_retryable(Time.now + 10.seconds, error)
27
+ @client.close
28
+ raise
24
29
  rescue Errno::ECONNREFUSED, SocketError => error
25
30
  mark_batch_retryable(Time.now + 10.seconds, error)
26
31
  raise
@@ -7,6 +7,7 @@ module Rpush
7
7
 
8
8
  class Delivery < Rpush::Daemon::Delivery
9
9
  RETRYABLE_CODES = [ 429, 500, 503 ]
10
+ CLIENT_JOIN_TIMEOUT = 60
10
11
 
11
12
  def initialize(app, http2_client, token_provider, batch)
12
13
  @app = app
@@ -22,7 +23,11 @@ module Rpush
22
23
  end
23
24
 
24
25
  # Send all preprocessed requests at once
25
- @client.join
26
+ @client.join(timeout: CLIENT_JOIN_TIMEOUT)
27
+ rescue NetHttp2::AsyncRequestTimeout => error
28
+ mark_batch_retryable(Time.now + 10.seconds, error)
29
+ @client.close
30
+ raise
26
31
  rescue Errno::ECONNREFUSED, SocketError, HTTP2::Error::StreamLimitExceeded => error
27
32
  # TODO restart connection when StreamLimitExceeded
28
33
  mark_batch_retryable(Time.now + 10.seconds, error)
@@ -133,7 +138,7 @@ module Rpush
133
138
  jwt_token = @token_provider.token
134
139
 
135
140
  headers = {}
136
-
141
+
137
142
  headers['content-type'] = 'application/json'
138
143
  headers['apns-expiration'] = '0'
139
144
  headers['apns-priority'] = '10'
@@ -29,7 +29,7 @@ module Rpush
29
29
  Rpush.logger.info("[#{app.name}] Starting #{pluralize(app.connections, 'dispatcher')}... ", true)
30
30
  runner = @runners[app.id] = new(app)
31
31
  runner.start_dispatchers
32
- puts ANSI.green { '✔' } if Rpush.config.foreground
32
+ puts Rainbow('✔').green if Rpush.config.foreground
33
33
  runner.start_loops
34
34
  rescue StandardError => e
35
35
  @runners.delete(app.id)
@@ -2,11 +2,13 @@ module Rpush
2
2
  module Daemon
3
3
  module Dispatcher
4
4
  class ApnsHttp2
5
+ include Loggable
6
+ include Reflectable
5
7
 
6
8
  URLS = {
7
9
  production: 'https://api.push.apple.com:443',
8
- development: 'https://api.development.push.apple.com:443',
9
- sandbox: 'https://api.development.push.apple.com:443'
10
+ development: 'https://api.sandbox.push.apple.com:443',
11
+ sandbox: 'https://api.sandbox.push.apple.com:443'
10
12
  }
11
13
 
12
14
  DEFAULT_TIMEOUT = 60
@@ -7,7 +7,8 @@ module Rpush
7
7
 
8
8
  URLS = {
9
9
  production: 'https://api.push.apple.com',
10
- development: 'https://api.development.push.apple.com'
10
+ development: 'https://api.sandbox.push.apple.com',
11
+ sandbox: 'https://api.sandbox.push.apple.com'
11
12
  }
12
13
 
13
14
  DEFAULT_TIMEOUT = 60
@@ -29,7 +29,7 @@ module Rpush
29
29
 
30
30
  def self.start_handler(read_io)
31
31
  @thread = Thread.new do
32
- while readable_io = IO.select([read_io]) # rubocop:disable AssignmentInCondition
32
+ while readable_io = IO.select([read_io]) # rubocop:disable Lint/AssignmentInCondition
33
33
  signal = readable_io.first[0].gets.strip
34
34
 
35
35
  begin
@@ -183,7 +183,7 @@ module Rpush
183
183
 
184
184
  private
185
185
 
186
- def create_gcm_like_notification(notification, attrs, data, registration_ids, deliver_after, app) # rubocop:disable ParameterLists
186
+ def create_gcm_like_notification(notification, attrs, data, registration_ids, deliver_after, app) # rubocop:disable Metrics/ParameterLists
187
187
  with_database_reconnect_and_retry do
188
188
  notification.assign_attributes(attrs)
189
189
  notification.data = data
@@ -67,7 +67,7 @@ module Rpush
67
67
 
68
68
  def check_database_is_connected
69
69
  # Simply asking the adapter for the connection state is not sufficient.
70
- Rpush::Client::ActiveRecord::Notification.count
70
+ Rpush::Client::ActiveRecord::Notification.exists?
71
71
  end
72
72
 
73
73
  def sleep_to_avoid_thrashing
@@ -138,7 +138,7 @@ module Rpush
138
138
  nil
139
139
  end
140
140
 
141
- def create_gcm_like_notification(notification, attrs, data, registration_ids, deliver_after, app) # rubocop:disable ParameterLists
141
+ def create_gcm_like_notification(notification, attrs, data, registration_ids, deliver_after, app) # rubocop:disable Metrics/ParameterLists
142
142
  notification.assign_attributes(attrs)
143
143
  notification.data = data
144
144
  notification.registration_ids = registration_ids
@@ -4,14 +4,19 @@ module Rpush
4
4
  class BadgeRequest
5
5
  def self.create(notification, access_token)
6
6
  body = BadgeRequestPayload.new(notification).to_xml
7
- uri = URI.parse(notification.uri)
8
- post = Net::HTTP::Post.new(
9
- uri.request_uri,
7
+ uri = URI.parse(notification.uri)
8
+ headers = {
10
9
  "Content-Length" => body.length.to_s,
11
10
  "Content-Type" => "text/xml",
12
11
  "X-WNS-Type" => "wns/badge",
13
12
  "X-WNS-RequestForStatus" => "true",
14
13
  "Authorization" => "Bearer #{access_token}"
14
+ }
15
+ headers['X-WNS-PRIORITY'] = notification.priority.to_s if notification.priority
16
+
17
+ post = Net::HTTP::Post.new(
18
+ uri.request_uri,
19
+ headers
15
20
  )
16
21
  post.body = body
17
22
  post
@@ -5,14 +5,21 @@ module Rpush
5
5
  def self.create(notification, access_token)
6
6
  body = notification.data.to_json
7
7
  uri = URI.parse(notification.uri)
8
- post = Net::HTTP::Post.new(
9
- uri.request_uri,
8
+ headers = {
10
9
  "Content-Length" => body.length.to_s,
11
10
  "Content-Type" => "application/octet-stream",
12
11
  "X-WNS-Type" => "wns/raw",
13
12
  "X-WNS-RequestForStatus" => "true",
14
13
  "Authorization" => "Bearer #{access_token}"
14
+ }
15
+
16
+ headers['X-WNS-PRIORITY'] = notification.priority.to_s if notification.priority
17
+
18
+ post = Net::HTTP::Post.new(
19
+ uri.request_uri,
20
+ headers
15
21
  )
22
+
16
23
  post.body = body
17
24
  post
18
25
  end
@@ -5,13 +5,17 @@ module Rpush
5
5
  def self.create(notification, access_token)
6
6
  body = ToastRequestPayload.new(notification).to_xml
7
7
  uri = URI.parse(notification.uri)
8
- post = Net::HTTP::Post.new(
9
- uri.request_uri,
8
+ headers = {
10
9
  "Content-Length" => body.length.to_s,
11
10
  "Content-Type" => "text/xml",
12
11
  "X-WNS-Type" => "wns/toast",
13
12
  "X-WNS-RequestForStatus" => "true",
14
13
  "Authorization" => "Bearer #{access_token}"
14
+ }
15
+ headers['X-WNS-PRIORITY'] = notification.priority.to_s if notification.priority
16
+ post = Net::HTTP::Post.new(
17
+ uri.request_uri,
18
+ headers
15
19
  )
16
20
  post.body = body
17
21
  post
@@ -1,8 +1,8 @@
1
1
  module Rpush
2
2
  module VERSION
3
- MAJOR = 4
4
- MINOR = 0
5
- TINY = 1
3
+ MAJOR = 5
4
+ MINOR = 1
5
+ TINY = 0
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".").freeze
@@ -1,4 +1,4 @@
1
1
  inherit_from: ../.rubocop.yml
2
2
 
3
- RescueModifier:
3
+ Style/RescueModifier:
4
4
  Enabled: false
@@ -228,5 +228,41 @@ describe 'APNs http2 adapter' do
228
228
  Rpush.push
229
229
  end
230
230
  end
231
+
232
+ context 'when waiting for requests to complete times out' do
233
+ before(:each) do
234
+ expect(fake_client).to receive(:join) { raise(NetHttp2::AsyncRequestTimeout) }
235
+ end
236
+
237
+ it 'closes the client' do
238
+ create_notification
239
+ expect(fake_client).to receive(:close)
240
+ Rpush.push
241
+ end
242
+
243
+ it 'reflects :error' do
244
+ reflected_error = false
245
+ Rpush.reflect do |on|
246
+ on.error do |error|
247
+ reflected_error = true
248
+ expect(error).to be_kind_of(StandardError)
249
+ reflector.accept
250
+ end
251
+ end
252
+
253
+ notification = create_notification
254
+ Rpush.push
255
+
256
+ expect(reflected_error).to be true
257
+ end
258
+
259
+ it 'fails but retries delivery several times' do
260
+ notification = create_notification
261
+ expect do
262
+ Rpush.push
263
+ notification.reload
264
+ end.to change(notification, :retries)
265
+ end
266
+ end
231
267
  end
232
268
  end
@@ -0,0 +1,40 @@
1
+ require 'functional_spec_helper'
2
+
3
+ describe 'GCM priority' do
4
+ let(:app) { Rpush::Gcm::App.new }
5
+ let(:notification) { Rpush::Gcm::Notification.new }
6
+ let(:hydrated_notification) { Rpush::Gcm::Notification.find(notification.id) }
7
+ let(:response) { double(Net::HTTPResponse, code: 200) }
8
+ let(:http) { double(Net::HTTP::Persistent, request: response, shutdown: nil) }
9
+ let(:priority) { 'normal' }
10
+
11
+ before do
12
+ app.name = 'test'
13
+ app.auth_key = 'abc123'
14
+ app.save!
15
+
16
+ notification.app_id = app.id
17
+ notification.registration_ids = ['foo']
18
+ notification.data = { message: 'test' }
19
+ notification.priority = priority
20
+ notification.save!
21
+
22
+ allow(Net::HTTP::Persistent).to receive_messages(new: http)
23
+ end
24
+
25
+ it 'supports normal priority' do
26
+ expect(hydrated_notification.as_json['priority']).to eq('normal')
27
+ end
28
+
29
+ context 'high priority' do
30
+ let(:priority) { 'high' }
31
+
32
+ it 'supports high priority' do
33
+ expect(hydrated_notification.as_json['priority']).to eq('high')
34
+ end
35
+ end
36
+
37
+ it 'does not add an error when receiving expected priority' do
38
+ expect(hydrated_notification.errors.messages[:priority]).to be_empty
39
+ end
40
+ end
@@ -39,6 +39,9 @@ require 'generators/templates/rpush_3_2_0_add_apns_p8'
39
39
  require 'generators/templates/rpush_3_2_4_updates'
40
40
  require 'generators/templates/rpush_3_3_0_updates'
41
41
  require 'generators/templates/rpush_3_3_1_updates'
42
+ require 'generators/templates/rpush_4_1_0_updates'
43
+ require 'generators/templates/rpush_4_1_1_updates'
44
+ require 'generators/templates/rpush_4_2_0_updates'
42
45
 
43
46
  migrations = [
44
47
  AddRpush,
@@ -53,7 +56,10 @@ migrations = [
53
56
  Rpush320AddApnsP8,
54
57
  Rpush324Updates,
55
58
  Rpush330Updates,
56
- Rpush331Updates
59
+ Rpush331Updates,
60
+ Rpush410Updates,
61
+ Rpush411Updates,
62
+ Rpush420Updates
57
63
  ]
58
64
 
59
65
  unless ENV['TRAVIS']
@@ -18,7 +18,7 @@ module SimpleCovHelper
18
18
  end
19
19
  end
20
20
 
21
- formatter SimpleCov::Formatter::MultiFormatter[*formatters]
21
+ formatter SimpleCov::Formatter::MultiFormatter.new(formatters)
22
22
  end
23
23
  end
24
24
  end
@@ -1,13 +1,15 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  describe Rpush, 'apns_feedback' do
4
- let!(:apns_app) do
5
- Rpush::Apns::App.create!(name: 'test', environment: 'production', certificate: TEST_CERT)
6
- end
7
-
8
- let!(:gcm_app) do
9
- Rpush::Gcm::App.create!(name: 'MyApp', auth_key: 'abc123')
4
+ let!(:apns_app) { Rpush::Apns::App.create!(apns_app_params) }
5
+ let(:apns_app_params) do
6
+ {
7
+ name: 'test',
8
+ environment: 'production',
9
+ certificate: TEST_CERT
10
+ }
10
11
  end
12
+ let!(:gcm_app) { Rpush::Gcm::App.create!(name: 'MyApp', auth_key: 'abc123') }
11
13
 
12
14
  let(:receiver) { double(check_for_feedback: nil) }
13
15
 
@@ -25,4 +27,13 @@ describe Rpush, 'apns_feedback' do
25
27
  expect(receiver).to receive(:check_for_feedback)
26
28
  Rpush.apns_feedback
27
29
  end
30
+
31
+ context 'feedback disabled' do
32
+ let(:apns_app_params) { super().merge(feedback_enabled: false) }
33
+
34
+ it 'does not initialize feedback receiver' do
35
+ expect(Rpush::Daemon::Apns::FeedbackReceiver).not_to receive(:new)
36
+ Rpush.apns_feedback
37
+ end
38
+ end
28
39
  end