rhoconnect 5.5.18 → 7.4.1

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.
@@ -1,189 +1,313 @@
1
- require File.join(File.dirname(__FILE__),'..','spec_helper')
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
2
 
3
- describe "PingJob" do
4
- include_examples "SharedRhoconnectHelper", :rhoconnect_data => true
3
+ describe 'PingJob' do
4
+ include_examples 'SharedRhoconnectHelper', :rhoconnect_data => true
5
5
 
6
6
  before(:each) do
7
7
  @u1_fields = {:login => 'testuser1'}
8
8
  @u1 = User.create(@u1_fields)
9
9
  @u1.password = 'testpass1'
10
10
  @c1_fields = {
11
- :device_type => 'Apple',
12
- :device_pin => 'abcde',
13
- :device_port => '3333',
14
- :user_id => @u1.id,
15
- :app_id => @a.id
11
+ :device_type => 'Apple',
12
+ :device_pin => 'abcde',
13
+ :device_port => '3333',
14
+ :user_id => @u1.id,
15
+ :app_id => @a.id
16
16
  }
17
- @c1 = Client.create(@c1_fields,{:source_name => @s_fields[:name]})
17
+ @c1 = Client.create(@c1_fields, {:source_name => @s_fields[:name]})
18
18
  @a.users << @u1.id
19
19
  end
20
20
 
21
- it "should perform apple ping with integer parameters" do
22
- params = {"user_id" => @u.id, "api_token" => @api_token,
23
- "sources" => [@s.name], "message" => 'hello world',
24
- "vibrate" => 5, "badge" => '5', "sound" => 'hello.mp3',"phone_id"=>nil}
21
+ it 'should perform apple ping with integer parameters' do
22
+ params = {'user_id' => @u.id,
23
+ 'api_token' => @api_token,
24
+ 'sources' => [@s.name],
25
+ 'message' => 'hello world',
26
+ 'vibrate' => 5,
27
+ 'badge' => '5',
28
+ 'sound' => 'hello.mp3',
29
+ 'phone_id' => nil,
30
+ 'device_app_id' => nil,
31
+ 'device_app_version' => nil, }
25
32
 
26
33
  scrubbed_params = params.dup
27
34
  scrubbed_params['vibrate'] = '5'
28
35
 
29
- Apple.should_receive(:ping).once.with({'device_pin' => @c.device_pin,
30
- 'device_port' => @c.device_port}.merge!(scrubbed_params))
36
+ expect(Apple).to receive(:ping).once.with({
37
+ 'device_pin' => @c.device_pin,
38
+ 'device_port' => @c.device_port
39
+ }.merge!(scrubbed_params))
31
40
  PingJob.perform(params)
32
41
  end
33
42
 
34
- it "should perform apple ping" do
35
- params = {"user_id" => @u.id, "api_token" => @api_token,
36
- "sources" => [@s.name], "message" => 'hello world',
37
- "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',"phone_id"=>nil}
38
- Apple.should_receive(:ping).once.with({'device_pin' => @c.device_pin,
39
- 'device_port' => @c.device_port}.merge!(params))
43
+ it 'should perform apple ping' do
44
+ params = {'user_id' => @u.id,
45
+ 'api_token' => @api_token,
46
+ 'sources' => [@s.name],
47
+ 'message' => 'hello world',
48
+ 'vibrate' => '5',
49
+ 'badge' => '5',
50
+ 'sound' => 'hello.mp3',
51
+ 'phone_id' => nil,
52
+ 'device_app_id' => nil,
53
+ 'device_app_version' => nil}
54
+ expect(Apple).to receive(:ping).once.with({'device_pin' => @c.device_pin,
55
+ 'device_port' => @c.device_port}.merge!(params))
40
56
  PingJob.perform(params)
41
57
  end
42
58
 
43
- it "should skip ping for the unknown platform" do
44
- params = {"user_id" => @u.id, "api_token" => @api_token,
45
- "sources" => [@s.name], "message" => 'hello world',
46
- "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',"phone_id"=>nil}
59
+ it 'should skip ping for the unknown platform' do
60
+ params = {'user_id' => @u.id,
61
+ 'api_token' => @api_token,
62
+ 'sources' => [@s.name],
63
+ 'message' => 'hello world',
64
+ 'vibrate' => '5',
65
+ 'badge' => '5',
66
+ 'sound' => 'hello.mp3',
67
+ 'phone_id' => nil,
68
+ 'device_app_id' => nil,
69
+ 'device_app_version' => nil}
47
70
  @c.device_type = 'unknown_device_type'
48
- PingJob.should_receive(:log).once.with("Dropping ping request for unsupported platform '#{@c.device_type}'")
71
+ expect(PingJob).to receive(:log).once.with("Dropping ping request for unsupported platform '#{@c.device_type}'")
49
72
  PingJob.perform(params)
50
73
  end
51
74
 
52
- it "should skip ping for empty device_type" do
53
- params = {"user_id" => @u.id, "api_token" => @api_token,
54
- "sources" => [@s.name], "message" => 'hello world',
55
- "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
75
+ it 'should skip ping for empty device_type' do
76
+ params = {'user_id' => @u.id,
77
+ 'api_token' => @api_token,
78
+ 'sources' => [@s.name],
79
+ 'message' => 'hello world',
80
+ 'vibrate' => '5',
81
+ 'badge' => '5',
82
+ 'sound' => 'hello.mp3',
83
+ 'device_app_id' => nil,
84
+ 'device_app_version' => nil}
56
85
  @c.device_type = nil
57
- PingJob.should_receive(:log).once.with("Skipping ping for non-registered client_id '#{@c.id}'...")
58
- lambda { PingJob.perform(params) }.should_not raise_error
86
+ expect(PingJob).to receive(:log).once.with("Skipping ping for non-registered client_id '#{@c.id}'...")
87
+ expect {PingJob.perform(params)}.not_to raise_error
59
88
  end
60
89
 
61
- it "should skip ping for empty device_pin" do
62
- params = {"user_id" => @u.id, "api_token" => @api_token,
63
- "sources" => [@s.name], "message" => 'hello world',
64
- "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
90
+ it 'should skip ping for empty device_pin' do
91
+ params = {'user_id' => @u.id,
92
+ 'api_token' => @api_token,
93
+ 'sources' => [@s.name],
94
+ 'message' => 'hello world',
95
+ 'vibrate' => '5',
96
+ 'badge' => '5',
97
+ 'sound' => 'hello.mp3',
98
+ 'device_app_id' => nil,
99
+ 'device_app_version' => nil, }
65
100
  @c.device_type = 'Android'
66
101
  @c.device_pin = nil
67
- PingJob.should_receive(:log).once.with("Skipping ping for non-registered client_id '#{@c.id}'...")
68
- lambda { PingJob.perform(params) }.should_not raise_error
102
+ expect(PingJob).to receive(:log).once.with("Skipping ping for non-registered client_id '#{@c.id}'...")
103
+ expect {PingJob.perform(params)}.not_to raise_error
69
104
  end
70
105
 
71
- it "should drop ping if it's already in user's device pin list" do
72
- params = {"user_id" => @u.id, "api_token" => @api_token,
73
- "sources" => [@s.name], "message" => 'hello world',
74
- "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',"phone_id"=>nil}
106
+ it 'should drop ping if it\'s already in user\'s device pin list' do
107
+ params = {'user_id' => @u.id,
108
+ 'api_token' => @api_token,
109
+ 'sources' => [@s.name],
110
+ 'message' => 'hello world',
111
+ 'vibrate' => '5',
112
+ 'badge' => '5',
113
+ 'sound' => 'hello.mp3',
114
+ 'phone_id' => nil,
115
+ 'device_app_id' => nil,
116
+ 'device_app_version' => nil}
75
117
  # another client with the same device pin ...
76
118
  @c_fields.delete(:id)
77
- @c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
119
+ @c1 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
78
120
  # and yet another one ...
79
121
  @c_fields.delete(:id)
80
- @c2 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
122
+ @c2 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
81
123
 
82
- Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
83
- PingJob.should_receive(:log).twice.with(/Dropping ping request for client/)
84
- lambda { PingJob.perform(params) }.should_not raise_error
124
+ expect(Apple).to receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
125
+ expect(PingJob).to receive(:log).twice.with(/Dropping ping request for client/)
126
+ expect {PingJob.perform(params)}.not_to raise_error
85
127
  end
86
128
 
87
- it "should drop ping if it's already in user's phone id list and device pin is different" do
88
- params = {"user_id" => @u.id, "api_token" => @api_token,
89
- "sources" => [@s.name], "message" => 'hello world',
90
- "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
129
+ it 'should drop ping if it\'s already in user\'s phone id list and device pin is different' do
130
+ params = {'user_id' => @u.id,
131
+ 'api_token' => @api_token,
132
+ 'sources' => [@s.name],
133
+ 'message' => 'hello world',
134
+ 'vibrate' => '5',
135
+ 'badge' => '5',
136
+ 'sound' => 'hello.mp3',
137
+ 'device_app_id' => nil,
138
+ 'device_app_version' => nil, }
91
139
  @c.phone_id = '3'
92
140
  @c_fields.merge!(:phone_id => '3')
93
141
  # another client with the same phone id..
94
142
  @c_fields.delete(:id)
95
- @c1 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
143
+ @c1 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
96
144
  # yet another...
97
145
  @c_fields.delete(:id)
98
- @c2 = Client.create(@c_fields,{:source_name => @s_fields[:name]})
146
+ @c2 = Client.create(@c_fields, {:source_name => @s_fields[:name]})
99
147
 
100
- Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
101
- PingJob.should_receive(:log).twice.with(/Dropping ping request for client/)
102
- lambda { PingJob.perform(params) }.should_not raise_error
148
+ expect(Apple).to receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
149
+ expect(PingJob).to receive(:log).twice.with(/Dropping ping request for client/)
150
+ expect {PingJob.perform(params)}.not_to raise_error
103
151
  end
104
152
 
105
- it "should ping two different users from two different devices - Apple and GCM" do
106
- params = {"user_id" => [ @u.id, @u1.id], "api_token" => @api_token,
107
- "sources" => [@s.name], "message" => 'hello world',
108
- "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', 'phone_id' => nil }
153
+ xit 'should ping two different users from two different devices - Apple and GCM' do
154
+ params = {'user_id' => [@u.id, @u1.id],
155
+ 'api_token' => @api_token,
156
+ 'sources' => [@s.name],
157
+ 'message' => 'hello world',
158
+ 'vibrate' => '5',
159
+ 'badge' => '5',
160
+ 'sound' => 'hello.mp3',
161
+ 'phone_id' => nil,
162
+ 'device_app_id' => nil,
163
+ 'device_app_version' => nil, }
109
164
  @c.phone_id = '3'
110
165
 
111
166
  scrubbed_params = params.dup
112
167
  scrubbed_params['vibrate'] = '5'
113
168
  @c1.device_push_type = 'Gcm'
114
169
 
115
- Apple.should_receive(:ping).with(params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}))
116
- Gcm.should_receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
170
+ expect(Apple).to receive(:ping).with(params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}))
171
+ expect(Gcm).to receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
117
172
  PingJob.perform(params)
118
173
  end
119
174
 
120
- it "should drop ping with two different users from the same device" do
121
- params = {"user_id" => [ @u.id, @u1.id], "api_token" => @api_token,
122
- "sources" => [@s.name], "message" => 'hello world',
123
- "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
175
+ it 'should ping two different users from two different devices - Apple and FCM' do
176
+ params = {'user_id' => [@u.id, @u1.id],
177
+ 'api_token' => @api_token,
178
+ 'sources' => [@s.name],
179
+ 'message' => 'hello world',
180
+ 'vibrate' => '5',
181
+ 'badge' => '5',
182
+ 'sound' => 'hello.mp3',
183
+ 'phone_id' => nil,
184
+ 'device_app_id' => nil,
185
+ 'device_app_version' => nil, }
186
+ @c.phone_id = '3'
187
+
188
+ scrubbed_params = params.dup
189
+ scrubbed_params['vibrate'] = '5'
190
+ @c1.device_push_type = 'Fcm'
191
+
192
+ expect(Apple).to receive(:ping).with(params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}))
193
+ expect(Fcm).to receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
194
+ PingJob.perform(params)
195
+ end
196
+
197
+ it 'should drop ping with two different users from the same device' do
198
+ params = {'user_id' => [@u.id, @u1.id],
199
+ 'api_token' => @api_token,
200
+ 'sources' => [@s.name],
201
+ 'message' => 'hello world',
202
+ 'vibrate' => '5',
203
+ 'badge' => '5',
204
+ 'sound' => 'hello.mp3',
205
+ 'device_app_id' => nil,
206
+ 'device_app_version' => nil, }
124
207
  @c.phone_id = '3'
125
208
  @c1.phone_id = '3'
126
209
 
127
- Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
128
- PingJob.should_receive(:log).once.with(/Dropping ping request for client/)
129
- lambda { PingJob.perform(params) }.should_not raise_error
210
+ expect(Apple).to receive(:ping).with({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port}.merge!(params))
211
+ expect(PingJob).to receive(:log).once.with(/Dropping ping request for client/)
212
+ expect {PingJob.perform(params)}.not_to raise_error
130
213
  end
131
214
 
132
- it "should drop ping with two different users with the same pin" do
133
- params = {"user_id" => [ @u.id, @u1.id], "api_token" => @api_token,
134
- "sources" => [@s.name], "message" => 'hello world', "phone_id" => nil,
135
- "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3'}
215
+ it 'should drop ping with two different users with the same pin' do
216
+ params = {'user_id' => [@u.id, @u1.id],
217
+ 'api_token' => @api_token,
218
+ 'sources' => [@s.name],
219
+ 'message' => 'hello world',
220
+ 'phone_id' => nil,
221
+ 'vibrate' => '5',
222
+ 'badge' => '5',
223
+ 'sound' => 'hello.mp3',
224
+ 'device_app_id' => nil,
225
+ 'device_app_version' => nil, }
136
226
  @c1.device_pin = @c.device_pin
137
227
 
138
- Apple.should_receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
139
- PingJob.should_receive(:log).once.with(/Dropping ping request for client/)
140
- lambda { PingJob.perform(params) }.should_not raise_error
228
+ expect(Apple).to receive(:ping).with({'device_pin' => @c.device_pin, 'device_port' => @c.device_port}.merge!(params))
229
+ expect(PingJob).to receive(:log).once.with(/Dropping ping request for client/)
230
+ expect {PingJob.perform(params)}.not_to raise_error
141
231
  end
142
232
 
143
- it "should process all pings even if some of them are failing" do
144
- params = {"user_id" => [ @u.id, @u1.id], "api_token" => @api_token,
145
- "sources" => [@s.name], "message" => 'hello world',
146
- "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', 'phone_id' => nil }
233
+ xit 'should process all pings even if some of them are failing' do
234
+ params = {'user_id' => [@u.id, @u1.id],
235
+ 'api_token' => @api_token,
236
+ 'sources' => [@s.name],
237
+ 'message' => 'hello world',
238
+ 'vibrate' => '5',
239
+ 'badge' => '5',
240
+ 'sound' => 'hello.mp3',
241
+ 'phone_id' => nil,
242
+ 'device_app_id' => nil,
243
+ 'device_app_version' => nil, }
147
244
  @c.phone_id = '3'
148
245
 
149
246
  scrubbed_params = params.dup
150
247
  scrubbed_params['vibrate'] = '5'
151
248
  @c1.device_push_type = 'Gcm'
152
249
 
153
- Apple.should_receive(:ping).with(params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port})).and_return { raise SocketError.new("Socket failure") }
154
- Gcm.should_receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
155
- exception_raised = false
156
- begin
157
- PingJob.perform(params)
158
- rescue Exception => e
159
- exception_raised = true
160
- end
161
- exception_raised.should == true
162
- end
163
-
164
- it "should skip ping for unknown user or user with no clients" do
165
- params = {"user_id" => [ 'fake_user' ], "api_token" => @api_token,
166
- "sources" => [@s.name], "message" => 'hello world',
167
- "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3', 'phone_id' => nil }
168
- PingJob.should_receive(:log).once.with(/Skipping ping for unknown user 'fake_user' or 'fake_user' has no registered clients.../)
250
+ params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port})
251
+ allow(Apple).to receive(:ping).with(params).and_raise(SocketError.new("Socket failure"))
252
+ allow(Gcm).to receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
253
+ expect{ PingJob.perform(params)}.to raise_error
254
+ end
255
+
256
+ it 'should process all pings even if some of them are failing' do
257
+ params = {'user_id' => [@u.id, @u1.id],
258
+ 'api_token' => @api_token,
259
+ 'sources' => [@s.name],
260
+ 'message' => 'hello world',
261
+ 'vibrate' => '5',
262
+ 'badge' => '5',
263
+ 'sound' => 'hello.mp3',
264
+ 'phone_id' => nil,
265
+ 'device_app_id' => nil,
266
+ 'device_app_version' => nil, }
267
+ @c.phone_id = '3'
268
+
269
+ scrubbed_params = params.dup
270
+ scrubbed_params['vibrate'] = '5'
271
+ @c1.device_push_type = 'Fcm'
272
+
273
+ params.merge!({'device_pin' => @c.device_pin, 'phone_id' => @c.phone_id, 'device_port' => @c.device_port})
274
+ allow(Apple).to receive(:ping).with(params).and_raise(SocketError.new("Socket failure"))
275
+ allow(Fcm).to receive(:ping).with({'device_pin' => @c1.device_pin, 'device_port' => @c1.device_port}.merge!(scrubbed_params))
276
+ expect{ PingJob.perform(params)}.to raise_error
277
+ end
278
+
279
+ it 'should skip ping for unknown user or user with no clients' do
280
+ params = {'user_id' => ['fake_user'],
281
+ 'api_token' => @api_token,
282
+ 'sources' => [@s.name],
283
+ 'message' => 'hello world',
284
+ 'vibrate' => '5',
285
+ 'badge' => '5',
286
+ 'sound' => 'hello.mp3',
287
+ 'phone_id' => nil,
288
+ 'device_app_id' => nil,
289
+ 'device_app_version' => nil, }
290
+ expect(PingJob).to receive(:log).once.with(/Skipping ping for unknown user 'fake_user' or 'fake_user' has no registered clients.../)
169
291
  PingJob.perform(params)
170
292
  end
171
293
 
172
- it "should process ping for device_push_type if available" do
294
+ it 'should process ping for device_push_type if available' do
173
295
  @c.device_push_type = 'rhoconnect_push'
174
296
  @c.device_port = nil
175
297
  params = {
176
- 'user_id' => @u.id,
177
- 'message' => 'hello world',
178
- 'device_port' => '',
179
- 'vibrate' => '',
180
- 'phone_id' => nil
298
+ 'user_id' => @u.id,
299
+ 'message' => 'hello world',
300
+ 'device_port' => '',
301
+ 'vibrate' => '',
302
+ 'phone_id' => nil,
303
+ 'device_app_id' => nil,
304
+ 'device_app_version' => nil,
181
305
  }
182
306
  scrubbed_params = params.dup
183
307
 
184
- RhoconnectPush.should_receive(:ping).once.with(
185
- {'device_pin' => @c.device_pin}.merge!(scrubbed_params)
308
+ expect(RhoconnectPush).to receive(:ping).once.with(
309
+ {'device_pin' => @c.device_pin}.merge!(scrubbed_params)
186
310
  )
187
311
  PingJob.perform(params)
188
312
  end
189
- end
313
+ end
@@ -41,12 +41,12 @@ def generate_fake_data(num=1000,unique=false)
41
41
  unique_prefix = "#{n}-#{Time.now.to_s}"
42
42
  end
43
43
  res[n.to_s] = {
44
- "FirstName" => Faker::Name.first_name + unique_prefix,
45
- "LastName" => Faker::Name.last_name + unique_prefix,
46
- "Email" => Faker::Internet.free_email + unique_prefix,
47
- "Company" => Faker::Company.name + unique_prefix,
44
+ "FirstName" => FFaker::Name.first_name + unique_prefix,
45
+ "LastName" => FFaker::Name.last_name + unique_prefix,
46
+ "Email" => FFaker::Internet.free_email + unique_prefix,
47
+ "Company" => FFaker::Company.name + unique_prefix,
48
48
  "JobTitle" => title + unique_prefix,
49
- "Phone1" => Faker::PhoneNumber.phone_number + unique_prefix
49
+ "Phone1" => FFaker::PhoneNumber.phone_number + unique_prefix
50
50
  }
51
51
  end
52
52
  res
@@ -9,22 +9,22 @@ describe "Ping Apple" do
9
9
  "vibrate" => '5', "badge" => '5', "sound" => 'hello.mp3',
10
10
  "device_pin" => @c.device_pin, "device_port" => @c.device_port}
11
11
  ssl_ctx = double("ssl_ctx")
12
- ssl_ctx.stub(:key=).and_return('key')
13
- ssl_ctx.stub(:cert=).and_return('cert')
14
- OpenSSL::SSL::SSLContext.stub(:new).and_return(ssl_ctx)
15
- OpenSSL::PKey::RSA.stub(:new)
16
- OpenSSL::X509::Certificate.stub(:new)
12
+ allow(ssl_ctx).to receive(:key=).and_return('key')
13
+ allow(ssl_ctx).to receive(:cert=).and_return('cert')
14
+ allow(OpenSSL::SSL::SSLContext).to receive(:new).and_return(ssl_ctx)
15
+ allow(OpenSSL::PKey::RSA).to receive(:new)
16
+ allow(OpenSSL::X509::Certificate).to receive(:new)
17
17
 
18
18
  tcp_socket = double("tcp_socket")
19
- tcp_socket.stub(:close)
20
- TCPSocket.stub(:new).and_return(tcp_socket)
19
+ allow(tcp_socket).to receive(:close)
20
+ allow(TCPSocket).to receive(:new).and_return(tcp_socket)
21
21
 
22
22
  @ssl_socket = double("ssl_socket")
23
- @ssl_socket.stub(:sync=)
24
- @ssl_socket.stub(:connect)
25
- @ssl_socket.stub(:write)
26
- @ssl_socket.stub(:close)
27
- OpenSSL::SSL::SSLSocket.stub(:new).and_return(@ssl_socket)
23
+ allow(@ssl_socket).to receive(:sync=)
24
+ allow(@ssl_socket).to receive(:connect)
25
+ allow(@ssl_socket).to receive(:write)
26
+ allow(@ssl_socket).to receive(:close)
27
+ allow(OpenSSL::SSL::SSLSocket).to receive(:new).and_return(@ssl_socket)
28
28
  end
29
29
 
30
30
  # TODO: This should really test SSLSocket.write
@@ -33,9 +33,7 @@ describe "Ping Apple" do
33
33
  end
34
34
 
35
35
  it "should log deprecation on iphone ping" do
36
- Iphone.should_receive(
37
- :log
38
- ).once.with("DEPRECATION WARNING: 'iphone' is a deprecated device_type, use 'apple' instead")
36
+ expect(Iphone).to receive(:log).once.with("DEPRECATION WARNING: 'iphone' is a deprecated device_type, use 'apple' instead")
39
37
  Iphone.ping(@params)
40
38
  end
41
39
 
@@ -45,8 +43,8 @@ describe "Ping Apple" do
45
43
  "do_sync"=>["SampleAdapter"]
46
44
  }
47
45
  apn_message = Apple.apn_message(@params)
48
- apn_message[0, 7].inspect.gsub("\"", "").should == "\\x00\\x00 \\xAB\\xCD\\x00g"
49
- JSON.parse(apn_message[7, apn_message.length]).should == expected_hash
46
+ expect(apn_message[0, 7].inspect.gsub("\"", "")).to eq("\\x00\\x00 \\xAB\\xCD\\x00g")
47
+ expect(JSON.parse(apn_message[7, apn_message.length])).to eq(expected_hash)
50
48
  end
51
49
 
52
50
  it "should compute apn_message with source array" do
@@ -56,21 +54,21 @@ describe "Ping Apple" do
56
54
  "do_sync"=>["SampleAdapter", "SimpleAdapter"]
57
55
  }
58
56
  apn_message = Apple.apn_message(@params)
59
- apn_message[0, 7].inspect.gsub("\"", "").should == "\\x00\\x00 \\xAB\\xCD\\x00w"
60
- JSON.parse(apn_message[7, apn_message.length]).should == expected_hash
57
+ expect(apn_message[0, 7].inspect.gsub("\"", "")).to eq("\\x00\\x00 \\xAB\\xCD\\x00w")
58
+ expect(JSON.parse(apn_message[7, apn_message.length])).to eq(expected_hash)
61
59
  end
62
60
 
63
61
  it "should raise SocketError if socket fails" do
64
62
  error = 'socket error'
65
- @ssl_socket.stub(:write).and_return { raise SocketError.new(error) }
66
- Apple.should_receive(:log).once.with("Error while sending ping: #{error}")
67
- lambda { Apple.ping(@params) }.should raise_error(SocketError,error)
63
+ allow(@ssl_socket).to receive(:write).and_raise(SocketError.new(error))
64
+ expect(Apple).to receive(:log).once.with("Error while sending ping: #{error}")
65
+ expect(lambda { Apple.ping(@params) }).to raise_error(SocketError, error)
68
66
  end
69
67
 
70
68
  it "should do nothing if no cert or host or port" do
71
- Rhoconnect::Apple.stub(:get_config).and_return({:test => {:iphonecertfile=>"none"}})
72
- Rhoconnect::Apple.should_receive(:get_config).once
73
- OpenSSL::SSL::SSLContext.should_receive(:new).exactly(0).times
69
+ allow(Rhoconnect::Apple).to receive(:get_config).and_return({:test => {:iphonecertfile=>"none"}})
70
+ expect(Rhoconnect::Apple).to receive(:get_config).once
71
+ expect(OpenSSL::SSL::SSLContext).to receive(:new).exactly(0).times
74
72
  Apple.ping(@params)
75
73
  end
76
- end
74
+ end