rpush 1.0.0-java → 2.0.0-java

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 (201) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +37 -22
  4. data/bin/rpush +13 -4
  5. data/lib/generators/rpush_generator.rb +2 -0
  6. data/lib/generators/templates/add_adm.rb +5 -5
  7. data/lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb +1 -1
  8. data/lib/generators/templates/add_app_to_rapns.rb +2 -2
  9. data/lib/generators/templates/add_fail_after_to_rpush_notifications.rb +1 -1
  10. data/lib/generators/templates/add_gcm.rb +32 -32
  11. data/lib/generators/templates/add_rpush.rb +67 -67
  12. data/lib/generators/templates/add_wpns.rb +2 -2
  13. data/lib/generators/templates/create_rapns_apps.rb +5 -5
  14. data/lib/generators/templates/create_rapns_feedback.rb +2 -2
  15. data/lib/generators/templates/create_rapns_notifications.rb +15 -15
  16. data/lib/generators/templates/rpush.rb +28 -7
  17. data/lib/generators/templates/rpush_2_0_0_updates.rb +42 -0
  18. data/lib/rpush/client/active_model/adm/app.rb +23 -0
  19. data/lib/rpush/client/active_model/adm/data_validator.rb +14 -0
  20. data/lib/rpush/client/active_model/adm/notification.rb +28 -0
  21. data/lib/rpush/client/active_model/apns/app.rb +37 -0
  22. data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +16 -0
  23. data/lib/rpush/client/active_model/apns/device_token_format_validator.rb +14 -0
  24. data/lib/rpush/client/active_model/apns/notification.rb +90 -0
  25. data/lib/rpush/client/active_model/gcm/app.rb +19 -0
  26. data/lib/rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +14 -0
  27. data/lib/rpush/client/active_model/gcm/notification.rb +31 -0
  28. data/lib/rpush/client/active_model/notification.rb +26 -0
  29. data/lib/rpush/client/active_model/payload_data_size_validator.rb +13 -0
  30. data/lib/rpush/client/active_model/registration_ids_count_validator.rb +13 -0
  31. data/lib/rpush/client/active_model/wpns/app.rb +13 -0
  32. data/lib/rpush/client/active_model/wpns/notification.rb +17 -0
  33. data/lib/rpush/client/active_model.rb +21 -0
  34. data/lib/rpush/client/active_record/adm/app.rb +11 -0
  35. data/lib/rpush/client/active_record/adm/notification.rb +11 -0
  36. data/lib/rpush/client/active_record/apns/app.rb +11 -0
  37. data/lib/rpush/client/active_record/apns/feedback.rb +22 -0
  38. data/lib/rpush/client/active_record/apns/notification.rb +46 -0
  39. data/lib/rpush/client/active_record/app.rb +17 -0
  40. data/lib/rpush/client/active_record/gcm/app.rb +11 -0
  41. data/lib/rpush/client/active_record/gcm/notification.rb +11 -0
  42. data/lib/rpush/client/active_record/notification.rb +38 -0
  43. data/lib/rpush/client/active_record/wpns/app.rb +11 -0
  44. data/lib/rpush/client/active_record/wpns/notification.rb +11 -0
  45. data/lib/rpush/client/active_record.rb +19 -0
  46. data/lib/rpush/client/redis/adm/app.rb +14 -0
  47. data/lib/rpush/client/redis/adm/notification.rb +11 -0
  48. data/lib/rpush/client/redis/apns/app.rb +11 -0
  49. data/lib/rpush/client/redis/apns/feedback.rb +20 -0
  50. data/lib/rpush/client/redis/apns/notification.rb +11 -0
  51. data/lib/rpush/client/redis/app.rb +24 -0
  52. data/lib/rpush/client/redis/gcm/app.rb +11 -0
  53. data/lib/rpush/client/redis/gcm/notification.rb +11 -0
  54. data/lib/rpush/client/redis/notification.rb +68 -0
  55. data/lib/rpush/client/redis/wpns/app.rb +11 -0
  56. data/lib/rpush/client/redis/wpns/notification.rb +11 -0
  57. data/lib/rpush/client/redis.rb +35 -0
  58. data/lib/rpush/configuration.rb +27 -6
  59. data/lib/rpush/daemon/adm/delivery.rb +56 -55
  60. data/lib/rpush/daemon/apns/delivery.rb +20 -44
  61. data/lib/rpush/daemon/apns/feedback_receiver.rb +11 -8
  62. data/lib/rpush/daemon/apns.rb +6 -5
  63. data/lib/rpush/daemon/app_runner.rb +103 -99
  64. data/lib/rpush/daemon/batch.rb +54 -40
  65. data/lib/rpush/daemon/delivery.rb +13 -3
  66. data/lib/rpush/daemon/delivery_error.rb +10 -2
  67. data/lib/rpush/daemon/dispatcher/apns_tcp.rb +114 -0
  68. data/lib/rpush/daemon/dispatcher/http.rb +3 -3
  69. data/lib/rpush/daemon/dispatcher/tcp.rb +3 -3
  70. data/lib/rpush/daemon/dispatcher_loop.rb +37 -23
  71. data/lib/rpush/daemon/errors.rb +18 -0
  72. data/lib/rpush/daemon/feeder.rb +28 -39
  73. data/lib/rpush/daemon/gcm/delivery.rb +19 -20
  74. data/lib/rpush/daemon/interruptible_sleep.rb +26 -45
  75. data/lib/rpush/daemon/loggable.rb +2 -4
  76. data/lib/rpush/daemon/proc_title.rb +16 -0
  77. data/lib/rpush/daemon/queue_payload.rb +12 -0
  78. data/lib/rpush/daemon/reflectable.rb +3 -5
  79. data/lib/rpush/daemon/retry_header_parser.rb +6 -6
  80. data/lib/rpush/daemon/retryable_error.rb +2 -0
  81. data/lib/rpush/daemon/ring_buffer.rb +16 -0
  82. data/lib/rpush/daemon/service_config_methods.rb +23 -7
  83. data/lib/rpush/daemon/signal_handler.rb +56 -0
  84. data/lib/rpush/daemon/store/active_record/reconnectable.rb +21 -17
  85. data/lib/rpush/daemon/store/active_record.rb +71 -38
  86. data/lib/rpush/daemon/store/interface.rb +19 -0
  87. data/lib/rpush/daemon/store/redis.rb +149 -0
  88. data/lib/rpush/daemon/string_helpers.rb +15 -0
  89. data/lib/rpush/daemon/synchronizer.rb +60 -0
  90. data/lib/rpush/daemon/tcp_connection.rb +6 -11
  91. data/lib/rpush/daemon/wpns/delivery.rb +21 -30
  92. data/lib/rpush/daemon.rb +40 -60
  93. data/lib/rpush/deprecatable.rb +4 -3
  94. data/lib/rpush/deprecation.rb +7 -10
  95. data/lib/rpush/embed.rb +8 -3
  96. data/lib/rpush/logger.rb +11 -15
  97. data/lib/rpush/push.rb +1 -2
  98. data/lib/rpush/reflection.rb +8 -12
  99. data/lib/rpush/version.rb +1 -1
  100. data/lib/rpush.rb +5 -29
  101. data/lib/tasks/quality.rake +35 -0
  102. data/lib/tasks/test.rake +1 -5
  103. data/spec/.rubocop.yml +4 -0
  104. data/spec/functional/adm_spec.rb +3 -6
  105. data/spec/functional/apns_spec.rb +117 -24
  106. data/spec/functional/embed_spec.rb +20 -20
  107. data/spec/functional/gcm_spec.rb +4 -7
  108. data/spec/functional/new_app_spec.rb +59 -0
  109. data/spec/functional/retry_spec.rb +46 -0
  110. data/spec/functional/synchronization_spec.rb +68 -0
  111. data/spec/functional/wpns_spec.rb +3 -6
  112. data/spec/functional_spec_helper.rb +26 -0
  113. data/spec/integration/rpush_spec.rb +13 -0
  114. data/spec/integration/support/gcm_success_response.json +1 -0
  115. data/spec/spec_helper.rb +60 -0
  116. data/spec/support/active_record_setup.rb +48 -0
  117. data/{config → spec/support/config}/database.yml +0 -0
  118. data/spec/support/install.sh +43 -7
  119. data/spec/support/simplecov_helper.rb +9 -5
  120. data/spec/support/simplecov_quality_formatter.rb +10 -6
  121. data/spec/unit/apns_feedback_spec.rb +3 -3
  122. data/spec/unit/{adm → client/active_record/adm}/app_spec.rb +3 -3
  123. data/spec/unit/{adm → client/active_record/adm}/notification_spec.rb +5 -7
  124. data/spec/unit/client/active_record/apns/app_spec.rb +29 -0
  125. data/spec/unit/client/active_record/apns/feedback_spec.rb +9 -0
  126. data/spec/unit/client/active_record/apns/notification_spec.rb +231 -0
  127. data/spec/unit/client/active_record/app_spec.rb +30 -0
  128. data/spec/unit/client/active_record/gcm/app_spec.rb +4 -0
  129. data/spec/unit/{gcm → client/active_record/gcm}/notification_spec.rb +5 -7
  130. data/spec/unit/client/active_record/notification_spec.rb +21 -0
  131. data/spec/unit/client/active_record/wpns/app_spec.rb +4 -0
  132. data/spec/unit/client/active_record/wpns/notification_spec.rb +21 -0
  133. data/spec/unit/configuration_spec.rb +12 -5
  134. data/spec/unit/daemon/adm/delivery_spec.rb +66 -55
  135. data/spec/unit/daemon/apns/certificate_expired_error_spec.rb +3 -3
  136. data/spec/unit/daemon/apns/delivery_spec.rb +90 -83
  137. data/spec/unit/daemon/apns/feedback_receiver_spec.rb +22 -17
  138. data/spec/unit/daemon/app_runner_spec.rb +78 -186
  139. data/spec/unit/daemon/batch_spec.rb +52 -115
  140. data/spec/unit/daemon/delivery_spec.rb +15 -1
  141. data/spec/unit/daemon/dispatcher/http_spec.rb +3 -2
  142. data/spec/unit/daemon/dispatcher/tcp_spec.rb +10 -9
  143. data/spec/unit/daemon/dispatcher_loop_spec.rb +6 -24
  144. data/spec/unit/daemon/feeder_spec.rb +38 -39
  145. data/spec/unit/daemon/gcm/delivery_spec.rb +122 -101
  146. data/spec/unit/daemon/reflectable_spec.rb +2 -2
  147. data/spec/unit/daemon/retryable_error_spec.rb +1 -1
  148. data/spec/unit/daemon/service_config_methods_spec.rb +6 -3
  149. data/spec/unit/daemon/signal_handler_spec.rb +95 -0
  150. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +48 -27
  151. data/spec/unit/daemon/store/active_record_spec.rb +38 -47
  152. data/spec/unit/daemon/tcp_connection_spec.rb +22 -34
  153. data/spec/unit/daemon/wpns/delivery_spec.rb +58 -50
  154. data/spec/unit/daemon_spec.rb +48 -82
  155. data/spec/unit/embed_spec.rb +6 -4
  156. data/spec/unit/logger_spec.rb +35 -43
  157. data/spec/unit/notification_shared.rb +9 -79
  158. data/spec/unit/push_spec.rb +6 -10
  159. data/spec/unit/reflection_spec.rb +25 -25
  160. data/spec/unit/rpush_spec.rb +1 -2
  161. data/spec/unit_spec_helper.rb +33 -88
  162. metadata +126 -76
  163. data/lib/rpush/TODO +0 -3
  164. data/lib/rpush/adm/app.rb +0 -15
  165. data/lib/rpush/adm/data_validator.rb +0 -11
  166. data/lib/rpush/adm/notification.rb +0 -29
  167. data/lib/rpush/apns/app.rb +0 -29
  168. data/lib/rpush/apns/binary_notification_validator.rb +0 -12
  169. data/lib/rpush/apns/device_token_format_validator.rb +0 -12
  170. data/lib/rpush/apns/feedback.rb +0 -16
  171. data/lib/rpush/apns/notification.rb +0 -84
  172. data/lib/rpush/app.rb +0 -18
  173. data/lib/rpush/daemon/apns/certificate_expired_error.rb +0 -20
  174. data/lib/rpush/daemon/apns/disconnection_error.rb +0 -20
  175. data/lib/rpush/daemon/dispatcher_loop_collection.rb +0 -33
  176. data/lib/rpush/daemon/too_many_requests_error.rb +0 -20
  177. data/lib/rpush/gcm/app.rb +0 -11
  178. data/lib/rpush/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +0 -11
  179. data/lib/rpush/gcm/notification.rb +0 -30
  180. data/lib/rpush/notification.rb +0 -69
  181. data/lib/rpush/notifier.rb +0 -52
  182. data/lib/rpush/payload_data_size_validator.rb +0 -10
  183. data/lib/rpush/railtie.rb +0 -11
  184. data/lib/rpush/registration_ids_count_validator.rb +0 -10
  185. data/lib/rpush/wpns/app.rb +0 -9
  186. data/lib/rpush/wpns/notification.rb +0 -26
  187. data/lib/tasks/cane.rake +0 -18
  188. data/lib/tasks/rpush.rake +0 -16
  189. data/spec/unit/apns/app_spec.rb +0 -29
  190. data/spec/unit/apns/feedback_spec.rb +0 -9
  191. data/spec/unit/apns/notification_spec.rb +0 -208
  192. data/spec/unit/app_spec.rb +0 -30
  193. data/spec/unit/daemon/apns/disconnection_error_spec.rb +0 -18
  194. data/spec/unit/daemon/dispatcher_loop_collection_spec.rb +0 -37
  195. data/spec/unit/daemon/interruptible_sleep_spec.rb +0 -68
  196. data/spec/unit/daemon/too_many_requests_error_spec.rb +0 -14
  197. data/spec/unit/gcm/app_spec.rb +0 -4
  198. data/spec/unit/notification_spec.rb +0 -15
  199. data/spec/unit/notifier_spec.rb +0 -49
  200. data/spec/unit/wpns/app_spec.rb +0 -4
  201. data/spec/unit/wpns/notification_spec.rb +0 -30
@@ -1,208 +0,0 @@
1
- # encoding: US-ASCII
2
-
3
- require "unit_spec_helper"
4
- require 'unit/notification_shared.rb'
5
-
6
- describe Rpush::Apns::Notification do
7
- it_should_behave_like 'an Notification subclass'
8
-
9
- let(:app) { Rpush::Apns::App.create!(:name => 'my_app', :environment => 'development', :certificate => TEST_CERT) }
10
- let(:notification_class) { Rpush::Apns::Notification }
11
- let(:notification) { notification_class.new }
12
- let(:data_setter) { 'attributes_for_device=' }
13
- let(:data_getter) { 'attributes_for_device' }
14
-
15
- it "should validate the format of the device_token" do
16
- notification = Rpush::Apns::Notification.new(:device_token => "{$%^&*()}")
17
- notification.valid?.should be_false
18
- notification.errors[:device_token].include?("is invalid").should be_true
19
- end
20
-
21
- it "should validate the length of the binary conversion of the notification" do
22
- notification.device_token = "a" * 64
23
- notification.alert = "way too long!" * 100
24
- notification.valid?.should be_false
25
- notification.errors[:base].include?("APN notification cannot be larger than 256 bytes. Try condensing your alert and device attributes.").should be_true
26
- end
27
-
28
- it "should default the sound to 'default'" do
29
- notification.sound.should eq('default')
30
- end
31
-
32
- it "should default the expiry to 1 day" do
33
- notification.expiry.should eq 1.day.to_i
34
- end
35
- end
36
-
37
- describe Rpush::Apns::Notification, "when assigning the device token" do
38
- it "should strip spaces from the given string" do
39
- notification = Rpush::Apns::Notification.new(:device_token => "o m g")
40
- notification.device_token.should eq "omg"
41
- end
42
-
43
- it "should strip chevrons from the given string" do
44
- notification = Rpush::Apns::Notification.new(:device_token => "<omg>")
45
- notification.device_token.should eq "omg"
46
- end
47
- end
48
-
49
- describe Rpush::Apns::Notification, "as_json" do
50
- it "should include the alert if present" do
51
- notification = Rpush::Apns::Notification.new(:alert => "hi mom")
52
- notification.as_json["aps"]["alert"].should eq "hi mom"
53
- end
54
-
55
- it "should not include the alert key if the alert is not present" do
56
- notification = Rpush::Apns::Notification.new(:alert => nil)
57
- notification.as_json["aps"].key?("alert").should be_false
58
- end
59
-
60
- it "should encode the alert as JSON if it is a Hash" do
61
- notification = Rpush::Apns::Notification.new(:alert => { 'body' => "hi mom", 'alert-loc-key' => "View" })
62
- notification.as_json["aps"]["alert"].should eq ({ 'body' => "hi mom", 'alert-loc-key' => "View" })
63
- end
64
-
65
- it "should include the badge if present" do
66
- notification = Rpush::Apns::Notification.new(:badge => 6)
67
- notification.as_json["aps"]["badge"].should eq 6
68
- end
69
-
70
- it "should not include the badge key if the badge is not present" do
71
- notification = Rpush::Apns::Notification.new(:badge => nil)
72
- notification.as_json["aps"].key?("badge").should be_false
73
- end
74
-
75
- it "should include the sound if present" do
76
- notification = Rpush::Apns::Notification.new(:alert => "my_sound.aiff")
77
- notification.as_json["aps"]["alert"].should eq "my_sound.aiff"
78
- end
79
-
80
- it "should not include the sound key if the sound is not present" do
81
- notification = Rpush::Apns::Notification.new(:sound => false)
82
- notification.as_json["aps"].key?("sound").should be_false
83
- end
84
-
85
- it "should include attributes for the device" do
86
- notification = Rpush::Apns::Notification.new
87
- notification.attributes_for_device = {:omg => :lol, :wtf => :dunno}
88
- notification.as_json["omg"].should eq "lol"
89
- notification.as_json["wtf"].should eq "dunno"
90
- end
91
-
92
- it "should allow attributes to include a hash" do
93
- notification = Rpush::Apns::Notification.new
94
- notification.attributes_for_device = {:omg => {:ilike => :hashes}}
95
- notification.as_json["omg"]["ilike"].should eq "hashes"
96
- end
97
-
98
- end
99
-
100
- describe Rpush::Apns::Notification, 'MDM' do
101
- let(:magic) { 'abc123' }
102
- let(:notification) { Rpush::Apns::Notification.new }
103
-
104
- it 'includes the mdm magic in the payload' do
105
- notification.mdm = magic
106
- notification.as_json.should eq ({'mdm' => magic})
107
- end
108
-
109
- it 'does not include aps attribute' do
110
- notification.alert = "i'm doomed"
111
- notification.mdm = magic
112
- notification.as_json.key?('aps').should be_false
113
- end
114
- end
115
-
116
- describe Rpush::Apns::Notification, 'content-available' do
117
- let(:notification) { Rpush::Apns::Notification.new }
118
-
119
- it 'includes content-available in the payload' do
120
- notification.content_available = true
121
- notification.as_json['aps']['content-available'].should eq 1
122
- end
123
-
124
- it 'does not include content-available in the payload if not set' do
125
- notification.as_json['aps'].key?('content-available').should be_false
126
- end
127
-
128
- it 'does not include content-available as a non-aps attribute' do
129
- notification.content_available = true
130
- notification.as_json.key?('content-available').should be_false
131
- end
132
-
133
- it 'does not overwrite existing attributes for the device' do
134
- notification.data = {:hi => :mom}
135
- notification.content_available = true
136
- notification.as_json['aps']['content-available'].should eq 1
137
- notification.as_json['hi'].should eq 'mom'
138
- end
139
-
140
- it 'does not overwrite the content-available flag when setting attributes for the device' do
141
- notification.content_available = true
142
- notification.data = {:hi => :mom}
143
- notification.as_json['aps']['content-available'].should eq 1
144
- notification.as_json['hi'].should eq 'mom'
145
- end
146
- end
147
-
148
- describe Rpush::Apns::Notification, "to_binary" do
149
- it "should correctly convert the notification to binary" do
150
- notification = Rpush::Apns::Notification.new
151
- notification.device_token = "a" * 64
152
- notification.sound = "1.aiff"
153
- notification.badge = 3
154
- notification.alert = "Don't panic Mr Mainwaring, don't panic!"
155
- notification.attributes_for_device = {:hi => :mom}
156
- notification.expiry = 86400 # 1 day, \x00\x01Q\x80
157
- notification.app = Rpush::Apns::App.new(:name => 'my_app', :environment => 'development', :certificate => TEST_CERT)
158
- notification.stub(:id).and_return(1234)
159
- notification.to_binary.should eq "\x01\x00\x00\x04\xD2\x00\x01Q\x80\x00 \xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\x00a{\"aps\":{\"alert\":\"Don't panic Mr Mainwaring, don't panic!\",\"badge\":3,\"sound\":\"1.aiff\"},\"hi\":\"mom\"}"
160
- end
161
- end
162
-
163
- describe Rpush::Apns::Notification, "bug #31" do
164
- it 'does not confuse a JSON looking string as JSON' do
165
- notification = Rpush::Apns::Notification.new
166
- notification.alert = "{\"one\":2}"
167
- notification.alert.should eq "{\"one\":2}"
168
- end
169
-
170
- it 'does confuse a JSON looking string as JSON if the alert_is_json attribute is not present' do
171
- notification = Rpush::Apns::Notification.new
172
- notification.stub(:has_attribute? => false)
173
- notification.alert = "{\"one\":2}"
174
- notification.alert.should eq ({"one" => 2})
175
- end
176
- end
177
-
178
- describe Rpush::Apns::Notification, "bug #35" do
179
- it "should limit payload size to 256 bytes but not the entire packet" do
180
- notification = Rpush::Apns::Notification.new do |n|
181
- n.device_token = "a" * 64
182
- n.alert = "a" * 210
183
- n.app = Rpush::Apns::App.create!(:name => 'my_app', :environment => 'development', :certificate => TEST_CERT)
184
- end
185
-
186
- notification.to_binary(:for_validation => true).bytesize.should > 256
187
- notification.payload_size.should < 256
188
- notification.should be_valid
189
- end
190
- end
191
-
192
- describe Rpush::Apns::Notification, "multi_json usage" do
193
- describe Rpush::Apns::Notification, "alert" do
194
- it "should call MultiJson.load when multi_json version is 1.3.0" do
195
- notification = Rpush::Apns::Notification.new(:alert => { :a => 1 }, :alert_is_json => true)
196
- Gem.stub(:loaded_specs).and_return( { 'multi_json' => Gem::Specification.new('multi_json', '1.3.0') } )
197
- MultiJson.should_receive(:load).with(any_args())
198
- notification.alert
199
- end
200
-
201
- it "should call MultiJson.decode when multi_json version is 1.2.9" do
202
- notification = Rpush::Apns::Notification.new(:alert => { :a => 1 }, :alert_is_json => true)
203
- Gem.stub(:loaded_specs).and_return( { 'multi_json' => Gem::Specification.new('multi_json', '1.2.9') } )
204
- MultiJson.should_receive(:decode).with(any_args())
205
- notification.alert
206
- end
207
- end
208
- end
@@ -1,30 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Rpush::App do
4
- it 'validates the uniqueness of name within type and environment' do
5
- Rpush::Apns::App.create!(:name => 'test', :environment => 'production', :certificate => TEST_CERT)
6
- app = Rpush::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']
9
-
10
- app = Rpush::Apns::App.new(:name => 'test', :environment => 'development', :certificate => TEST_CERT)
11
- app.valid?.should be_true
12
-
13
- app = Rpush::Gcm::App.new(:name => 'test', :environment => 'production', :auth_key => TEST_CERT)
14
- app.valid?.should be_true
15
- end
16
-
17
- context 'validating certificates' do
18
- it 'rescues from certificate error' do
19
- app = Rpush::Apns::App.new(:name => 'test', :environment => 'development', :certificate => 'bad')
20
- expect{app.valid?}.not_to raise_error
21
- expect(app.valid?).to be_false
22
- end
23
-
24
- it 'raises other errors' do
25
- app = Rpush::Apns::App.new(:name => 'test', :environment => 'development', :certificate => 'bad')
26
- OpenSSL::X509::Certificate.stub(:new).and_raise(NameError, 'simulating no openssl')
27
- expect{app.valid?}.to raise_error(NameError)
28
- end
29
- end
30
- end
@@ -1,18 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Rpush::Apns::DisconnectionError do
4
- let(:error) { Rpush::Apns::DisconnectionError.new }
5
-
6
- it 'returns a nil error code' do
7
- error.code.should be_nil
8
- end
9
-
10
- it 'contains an error description' do
11
- error.description
12
- end
13
-
14
- it 'returns a message' do
15
- error.message
16
- error.to_s
17
- end
18
- end
@@ -1,37 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Rpush::Daemon::DispatcherLoopCollection do
4
- let(:dispatcher_loop) { double.as_null_object }
5
- let(:collection) { Rpush::Daemon::DispatcherLoopCollection.new }
6
-
7
- it 'returns the size of the collection' do
8
- collection.push(dispatcher_loop)
9
- collection.size.should eq 1
10
- end
11
-
12
- it 'pops a dispatcher loop from the collection' do
13
- collection.push(dispatcher_loop)
14
- dispatcher_loop.should_receive(:stop)
15
- dispatcher_loop.should_receive(:wakeup)
16
- dispatcher_loop.should_receive(:wait)
17
- collection.pop
18
- collection.size.should eq 0
19
- end
20
-
21
- it 'wakes up all dispatcher loops when popping a single dispatcher_loop' do
22
- collection.push(dispatcher_loop)
23
- dispatcher_loop2 = double.as_null_object
24
- collection.push(dispatcher_loop2)
25
- dispatcher_loop.should_receive(:wakeup)
26
- dispatcher_loop2.should_receive(:wakeup)
27
- collection.pop
28
- end
29
-
30
- it 'stops all dispatcher detetcloops' do
31
- collection.push(dispatcher_loop)
32
- dispatcher_loop.should_receive(:stop)
33
- dispatcher_loop.should_receive(:wakeup)
34
- dispatcher_loop.should_receive(:wait)
35
- collection.stop
36
- end
37
- end
@@ -1,68 +0,0 @@
1
- require "unit_spec_helper"
2
-
3
- describe Rpush::Daemon::InterruptibleSleep do
4
-
5
- let(:rd) { double(:close => nil) }
6
- let(:wr) { double(:close => nil) }
7
-
8
- subject { Rpush::Daemon::InterruptibleSleep.new }
9
-
10
- it 'creates a new pipe' do
11
- IO.should_receive(:pipe)
12
- subject
13
- end
14
-
15
- it 'selects on the reader' do
16
- IO.stub(:pipe => [rd, wr])
17
- IO.should_receive(:select).with([rd], nil, nil, 1)
18
- subject.sleep(1)
19
- end
20
-
21
- it 'closes the writer' do
22
- IO.stub(:pipe => [rd, wr])
23
- rd.should_receive(:close)
24
- wr.should_receive(:close)
25
- subject.close
26
- end
27
-
28
- it 'returns false when timeout occurs' do
29
- expect(subject.sleep(0.01)).to be_false
30
- end
31
-
32
- it 'returns true when sleep does not timeout' do
33
- subject.interrupt_sleep
34
- expect(subject.sleep(0.01)).to be_true
35
- end
36
-
37
- context 'with UDP socket connected' do
38
- before :each do
39
- @host, @port = subject.enable_wake_on_udp('127.0.0.1', 0)
40
- end
41
-
42
- it 'times out with no udp activity' do
43
- expect(subject.sleep(0.01)).to be_false
44
- end
45
-
46
- unless defined? JRUBY_VERSION
47
- it 'wakes on UDPSocket' do
48
- waker = UDPSocket.new
49
- waker.connect(@host, @port)
50
- waker.write('x')
51
- expect(subject.sleep(0.01)).to be_true
52
- end
53
-
54
- it 'consumes all data on udp socket' do
55
- waker = UDPSocket.new
56
- waker.connect(@host, @port)
57
- waker.send('x', 0)
58
- waker.send('x', 0)
59
- waker.send('x', 0)
60
- # true since there is data to be read => no timeout
61
- expect(subject.sleep(0.01)).to be_true
62
- # false since data is consumed => wait for full timeout
63
- expect(subject.sleep(0.01)).to be_false
64
- end
65
- end
66
- end
67
-
68
- end
@@ -1,14 +0,0 @@
1
- require "unit_spec_helper"
2
-
3
- describe Rpush::TooManyRequestsError do
4
- let(:response) { double(:code => 429, :header => { 'retry-after' => 3600 }) }
5
- let(:error) { Rpush::TooManyRequestsError.new(429, 12, "Too Many Requests", response) }
6
-
7
- it "returns an informative message" do
8
- error.to_s.should eq "Too many requests for 12, received error 429 (Too Many Requests) - retry after 3600"
9
- end
10
-
11
- it "returns the error code" do
12
- error.code.should eq 429
13
- end
14
- end
@@ -1,4 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Rpush::Gcm::App do
4
- end
@@ -1,15 +0,0 @@
1
- require "unit_spec_helper"
2
-
3
- describe Rpush::Notification do
4
- let(:notification) { Rpush::Notification.new }
5
-
6
- it 'allows assignment of many registration IDs' do
7
- notification.registration_ids = ['a', 'b']
8
- notification.registration_ids.should eq ['a', 'b']
9
- end
10
-
11
- it 'allows assignment of a single registration ID' do
12
- notification.registration_ids = 'a'
13
- notification.registration_ids.should eq ['a']
14
- end
15
- end
@@ -1,49 +0,0 @@
1
- require 'unit_spec_helper'
2
- require 'rpush/notifier'
3
-
4
- describe Rpush::Notifier do
5
-
6
- before(:each) { @port = 5000 }
7
- subject { Rpush::Notifier.new('127.0.0.1', @port) }
8
- its(:socket) { should_not be_nil }
9
-
10
- context "when connected" do
11
- before :each do
12
- @reader = UDPSocket.new
13
- @reader.bind('127.0.0.1', 0)
14
- @port = @reader.addr[1]
15
- end
16
-
17
- describe "notify" do
18
- it "calls write on the socket" do
19
- UDPSocket.any_instance.should_receive(:write)
20
- subject.notify
21
- end
22
-
23
- it "writes data that can be read from socket" do
24
- subject.notify
25
- expect(@reader.recv(1)).to eq 'x'
26
- end
27
- end
28
- end
29
-
30
- describe "default notifier" do
31
- it "creates using :connect first" do
32
- Rpush.config.stub :wakeup => { :connect => '127.0.0.1', :port => 1234 }
33
- Rpush::Notifier.should_receive(:new).with('127.0.0.1', 1234)
34
- Rpush.notifier
35
- end
36
-
37
- it "creates using :host next" do
38
- Rpush.config.stub :wakeup => { :host => '127.0.0.1', :port => 1234 }
39
- Rpush::Notifier.should_receive(:new).with('127.0.0.1', 1234)
40
- Rpush.notifier
41
- end
42
-
43
- it "returns nil when wakeup is not specified" do
44
- Rpush.config.stub :wakeup => nil
45
- Rpush::Notifier.should_not_receive(:new)
46
- expect(Rpush.notifier).to be_nil
47
- end
48
- end
49
- end
@@ -1,4 +0,0 @@
1
- require 'unit_spec_helper'
2
-
3
- describe Rpush::Wpns::App do
4
- end
@@ -1,30 +0,0 @@
1
- require 'unit_spec_helper'
2
- require 'unit/notification_shared.rb'
3
-
4
- describe Rpush::Wpns::Notification do
5
- it_should_behave_like 'an Notification subclass'
6
- let(:app) { Rpush::Wpns::App.create!(:name => 'test', :auth_key => 'abc') }
7
- let(:notification_class) { Rpush::Wpns::Notification }
8
- let(:notification) { notification_class.new }
9
- let(:data_setter) { 'data=' }
10
- let(:data_getter) { 'data' }
11
-
12
- it "should have an url in the uri parameter" do
13
- notification = Rpush::Wpns::Notification.new(:uri => "somthing")
14
- notification.valid?
15
- notification.errors[:uri].include?("is invalid").should be_true
16
- end
17
-
18
- it "should be invalid if there's no message" do
19
- notification = Rpush::Wpns::Notification.new(:alert => "")
20
- notification.valid?
21
- notification.errors[:alert].include?("can't be blank").should be_true
22
- end
23
- end
24
-
25
- describe Rpush::Wpns::Notification, "when assigning the url" do
26
- it "should be a valid url" do
27
- notification = Rpush::Wpns::Notification.new(:alert => "abc", :uri => "some")
28
- notification.uri_is_valid?.should be_false
29
- end
30
- end