cloud_door 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,648 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'GoogleDrive' do
4
+ let(:storage) do
5
+ storage = create_storage(CloudDoor::GoogleDrive)
6
+ storage.token.credentials = Marshal.dump('credentials')
7
+ token_file = storage.token.token_file
8
+ Google::APIClient.any_instance.stub(:authorization=)
9
+ .and_return(true)
10
+ Google::APIClient.any_instance.stub(:discovered_api)
11
+ .and_return(true)
12
+ CloudDoor::GoogleDriveBridge.any_instance.stub(:request_root_id)
13
+ .and_return('top')
14
+ open(token_file, 'wb') { |file| file << Marshal.dump(storage.token) }
15
+ storage.load_token
16
+ storage
17
+ end
18
+
19
+ describe 'reset_token' do
20
+ subject { storage.reset_token(token_value) }
21
+ let(:storage) { create_storage(CloudDoor::GoogleDrive) }
22
+ let(:token_value) { {'credentials' => 'credentials'} }
23
+ context 'success' do
24
+ it do
25
+ subject
26
+ expect(storage.token.credentials).to eq 'credentials'
27
+ end
28
+ end
29
+ context 'fail' do
30
+ context 'not Token class' do
31
+ before(:each) do
32
+ storage.token = 'token'
33
+ end
34
+ it { expect { subject }.to raise_error(CloudDoor::TokenClassException) }
35
+ end
36
+ end
37
+ end
38
+
39
+ describe 'show_user' do
40
+ subject { storage.show_user }
41
+ let(:token_file) { storage.token.token_file }
42
+ context 'success' do
43
+ let(:posit) { {'name' => 'google'} }
44
+ it do
45
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_user)
46
+ .and_return(posit)
47
+ is_expected.to eq posit
48
+ end
49
+ end
50
+ after(:each) do
51
+ File.delete(token_file) if File.exist?(token_file)
52
+ end
53
+ end
54
+
55
+ describe 'show_files' do
56
+ subject { storage.show_files(file_name) }
57
+ let(:list_file) { storage.file_list.list_file }
58
+ let(:token_file) { storage.token.token_file }
59
+ context 'success' do
60
+ let(:file_name) { nil }
61
+ context 'data exists' do
62
+ let(:posit) do
63
+ [
64
+ {'id' => 'file1234', 'title' => 'file1', 'mimeType' => 'text/plain'},
65
+ {'id' => 'folder1234', 'title' => 'folder1', 'mimeType' => 'application/vnd.google-apps.folder'},
66
+ ]
67
+ end
68
+ let(:result) do
69
+ {
70
+ 'file1' => {'id' => 'file1234', 'type' => 'file'},
71
+ 'folder1' => {'id' => 'folder1234', 'type' => 'folder'}
72
+ }
73
+ end
74
+ it do
75
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_dir)
76
+ .with('top')
77
+ .and_return(posit)
78
+ is_expected.to eq result
79
+ end
80
+ end
81
+ context 'data not exists' do
82
+ let(:posit) { [] }
83
+ it do
84
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_dir)
85
+ .and_return(posit)
86
+ is_expected.to eq({})
87
+ end
88
+ end
89
+ end
90
+ context 'fail' do
91
+ let(:file_name) { 'file9' }
92
+ context 'file id not exits' do
93
+ it { expect { subject }.to raise_error(CloudDoor::SetIDException) }
94
+ end
95
+ context 'not directory' do
96
+ before(:each) do
97
+ list = [{'items' => {'file9' => {'id' => 'file9876', 'type' => 'file'}}}]
98
+ open(list_file, 'wb') { |file| file << Marshal.dump(list) }
99
+ end
100
+ it { expect { subject }.to raise_error(CloudDoor::NotDirectoryException) }
101
+ end
102
+ end
103
+ after(:each) do
104
+ File.delete(list_file) if File.exist?(list_file)
105
+ File.delete(token_file) if File.exist?(token_file)
106
+ end
107
+ end
108
+
109
+ describe 'change_directory' do
110
+ subject { storage.change_directory(file_name) }
111
+ let(:list_file) { storage.file_list.list_file }
112
+ let(:token_file) { storage.token.token_file }
113
+ context 'success' do
114
+ let(:file_name) { 'folder1' }
115
+ before(:each) do
116
+ list = [{'items' => {'folder1' => {'id' => 'folder1234', 'type' => 'folder'}}}]
117
+ open(list_file, 'wb') { |file| file << Marshal.dump(list) }
118
+ end
119
+ context 'data exists' do
120
+ let(:posit) do
121
+ [
122
+ {'id' => 'file1234', 'title' => 'file1', 'mimeType' => 'text/plain'},
123
+ {'id' => 'folder1234', 'title' => 'folder1', 'mimeType' => 'application/vnd.google-apps.folder'},
124
+ ]
125
+ end
126
+ let(:result) do
127
+ {
128
+ 'file1' => {'id' => 'file1234', 'type' => 'file'},
129
+ 'folder1' => {'id' => 'folder1234', 'type' => 'folder'}
130
+ }
131
+ end
132
+ it do
133
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_dir)
134
+ .with('folder1234')
135
+ .and_return(posit)
136
+ is_expected.to eq result
137
+ end
138
+ end
139
+ context 'data not exists' do
140
+ let(:posit) { [] }
141
+ it do
142
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_dir)
143
+ .with('folder1234')
144
+ .and_return(posit)
145
+ is_expected.to eq({})
146
+ end
147
+ end
148
+ end
149
+ context 'fail' do
150
+ context 'file name not input' do
151
+ let(:file_name) { '' }
152
+ it { expect { subject }.to raise_error(CloudDoor::FileNameEmptyException) }
153
+ end
154
+ context 'file id not exits' do
155
+ let(:file_name) { 'file9' }
156
+ it { expect { subject }.to raise_error(CloudDoor::SetIDException) }
157
+ end
158
+ context 'not directory' do
159
+ let(:file_name) { 'file9' }
160
+ before(:each) do
161
+ list = [{'items' => {'file9' => {'id' => '/file9', 'type' => 'file'}}}]
162
+ open(list_file, 'wb') { |file| file << Marshal.dump(list) }
163
+ end
164
+ it { expect { subject }.to raise_error(CloudDoor::NotDirectoryException) }
165
+ end
166
+ end
167
+ after(:each) do
168
+ File.delete(list_file) if File.exist?(list_file)
169
+ File.delete(token_file) if File.exist?(token_file)
170
+ end
171
+ end
172
+
173
+ describe 'show_current_directory' do
174
+ subject { storage.show_current_directory }
175
+ let(:storage) { create_storage(CloudDoor::GoogleDrive) }
176
+ it { is_expected.to eq('/top') }
177
+ end
178
+
179
+ describe 'show_property' do
180
+ subject { storage.show_property(file_name) }
181
+ let(:list_file) { storage.file_list.list_file }
182
+ let(:token_file) { storage.token.token_file }
183
+ before(:each) do
184
+ list = [{'items' => {'file1' => {'id' => 'file1234', 'type' => 'file'}}}]
185
+ open(list_file, 'wb') { |file| file << Marshal.dump(list) }
186
+ end
187
+ context 'success' do
188
+ context 'file exists' do
189
+ let(:file_name) { 'file1' }
190
+ let(:posit) do
191
+ {
192
+ 'name' => 'file1',
193
+ 'bytes' => 38,
194
+ 'modified' => '2014-06-01 12:20:30',
195
+ 'client_mtime' => '2014-06-05 13:30:40',
196
+ 'path' => 'file1234',
197
+ 'is_dir' => false
198
+ }
199
+ end
200
+ before(:each) do
201
+ storage.stub(:file_exist?)
202
+ .with(file_name)
203
+ .and_return(true)
204
+ end
205
+ it do
206
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_file)
207
+ .with('file1234')
208
+ .and_return(posit)
209
+ is_expected.to eq posit
210
+ end
211
+ end
212
+ end
213
+ context 'fail' do
214
+ context 'file name not input' do
215
+ let(:file_name) { '' }
216
+ it { expect { subject }.to raise_error(CloudDoor::FileNameEmptyException) }
217
+ end
218
+ context 'file id not exits' do
219
+ let(:file_name) { 'test' }
220
+ it { expect { subject }.to raise_error(CloudDoor::SetIDException) }
221
+ end
222
+ context 'file not exits on cloud' do
223
+ let(:file_name) { 'file1' }
224
+ before(:each) do
225
+ storage.stub(:file_exist?)
226
+ .with(file_name)
227
+ .and_return(false)
228
+ end
229
+ it { expect { subject }.to raise_error(CloudDoor::FileNotExistsException) }
230
+ end
231
+ context 'no data' do
232
+ let(:file_name) { 'file1' }
233
+ let(:posit) { nil }
234
+ before(:each) do
235
+ storage.stub(:file_exist?)
236
+ .with(file_name)
237
+ .and_return(true)
238
+ CloudDoor::GoogleDriveBridge.any_instance.stub(:request_file)
239
+ .and_return(posit)
240
+ end
241
+ it { expect { subject }.to raise_error(CloudDoor::NoDataException) }
242
+ end
243
+ end
244
+ after(:each) do
245
+ File.delete(list_file) if File.exist?(list_file)
246
+ File.delete(token_file) if File.exist?(token_file)
247
+ end
248
+ end
249
+
250
+ =begin
251
+ describe 'pick_cloud_info' do
252
+ subject { storage.pick_cloud_info(method, key) }
253
+ let(:storage) { create_storage(CloudDoor::GoogleDrive) }
254
+ context 'user' do
255
+ let(:method) { 'request_user' }
256
+ let(:key) { 'name' }
257
+ let(:posit) { {'name' => 'dropbox'} }
258
+ it do
259
+ expect_any_instance_of(GoogleDriveClient).to receive(:account_info)
260
+ .and_return(posit)
261
+ is_expected.to eq 'dropbox'
262
+ end
263
+ end
264
+ context 'dir' do
265
+ let(:method) { 'request_dir' }
266
+ let(:key) { 'contents' }
267
+ let(:posit) { {'contents' => ['file1']} }
268
+ it do
269
+ expect_any_instance_of(GoogleDriveClient).to receive(:metadata)
270
+ .with(CloudDoor::GoogleDrive::ROOT_ID)
271
+ .and_return(posit)
272
+ is_expected.to eq ['file1']
273
+ end
274
+ end
275
+ context 'file' do
276
+ let(:storage) { create_storage(CloudDoor::GoogleDrive, '/file1') }
277
+ let(:method) { 'request_file' }
278
+ let(:key) { 'name' }
279
+ let(:posit) { {'path' => '/file1', 'name' => 'file1', 'is_dir' => false} }
280
+ it do
281
+ expect_any_instance_of(GoogleDriveClient).to receive(:metadata)
282
+ .with(storage.file_id)
283
+ .and_return(posit)
284
+ is_expected.to eq 'file1'
285
+ end
286
+ end
287
+ context 'fail' do
288
+ let(:method) { 'request_user' }
289
+ let(:key) { 'name' }
290
+ let(:posit) { {'name' => 'onedrive'} }
291
+ before(:each) do
292
+ GoogleDriveClient.any_instance.stub(:account_info)
293
+ .and_return(posit)
294
+ end
295
+ context 'method not exists' do
296
+ let(:method) { 'request_member' }
297
+ it { expect { subject }.to raise_error(CloudDoor::RequestMethodNotFoundException) }
298
+ end
299
+ context 'data not exists' do
300
+ let(:posit) { nil }
301
+ it { expect { subject }.to raise_error(CloudDoor::NoDataException) }
302
+ end
303
+ context 'key not exists' do
304
+ let(:key) { 'firstname' }
305
+ it { expect { subject }.to raise_error(CloudDoor::RequestPropertyNotFoundException) }
306
+ end
307
+ end
308
+ end
309
+ =end
310
+
311
+ describe 'download_file' do
312
+ subject { storage.download_file(file_name) }
313
+ let(:list_file) { storage.file_list.list_file }
314
+ let(:token_file) { storage.token.token_file }
315
+ context 'success' do
316
+ let(:file_name) { 'file1' }
317
+ let(:posit) { ['test', {'path' => 'test', 'name' => 'test'}] }
318
+ before(:each) do
319
+ list = [{'items' => {'file1' => {'id' => 'file1234', 'type' => 'file'}}}]
320
+ open(list_file, 'wb') { |file| file << Marshal.dump(list) }
321
+ end
322
+ it do
323
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_download)
324
+ .with('file1234')
325
+ .and_return(posit)
326
+ is_expected.to be_truthy
327
+ end
328
+ after(:each) do
329
+ File.delete('file1') if File.exist?('file1')
330
+ end
331
+ end
332
+ context 'fail' do
333
+ context 'file name not input' do
334
+ let(:file_name) { '' }
335
+ it { expect { subject }.to raise_error(CloudDoor::FileNameEmptyException) }
336
+ end
337
+ context 'file id not exits' do
338
+ let(:file_name) { 'test' }
339
+ it { expect { subject }.to raise_error(CloudDoor::SetIDException) }
340
+ end
341
+ context 'not file' do
342
+ let(:file_name) { 'folder1' }
343
+ before(:each) do
344
+ list = [{'items' => {'folder1' => {'id' => '/folder1', 'type' => 'folder'}}}]
345
+ open(list_file, 'wb') { |file| file << Marshal.dump(list) }
346
+ end
347
+ it { expect { subject }.to raise_error(CloudDoor::NotFileException) }
348
+ end
349
+ end
350
+ after(:each) do
351
+ File.delete(list_file) if File.exist?(list_file)
352
+ File.delete(token_file) if File.exist?(token_file)
353
+ end
354
+ end
355
+
356
+ describe 'upload_file' do
357
+ subject { storage.upload_file(file_name) }
358
+ let(:list_file) { storage.file_list.list_file }
359
+ let(:up_file) { 'upload' }
360
+ let(:token_file) { storage.token.token_file }
361
+ context 'success' do
362
+ let(:file_name) { up_file }
363
+ let(:posit_dir) do
364
+ [{'id' => 'file1234', 'title' => 'file1', 'mimeType' => 'text/plain'}]
365
+ end
366
+ before(:each) do
367
+ open(up_file, 'wb') { |file| file << 'upload' }
368
+ end
369
+ it do
370
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_upload)
371
+ .and_return(true)
372
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_dir)
373
+ .with('top')
374
+ .and_return(posit_dir)
375
+ is_expected.to be_truthy
376
+ end
377
+ end
378
+ context 'fail' do
379
+ context 'upload file name not input' do
380
+ let(:file_name) { '' }
381
+ it { expect { subject }.to raise_error(CloudDoor::FileNameEmptyException) }
382
+ end
383
+ context 'file not exits' do
384
+ let(:file_name) { up_file }
385
+ it { expect { subject }.to raise_error(CloudDoor::FileNotExistsException) }
386
+ end
387
+ end
388
+ after(:each) do
389
+ File.delete(up_file) if File.exist?(up_file)
390
+ File.delete(list_file) if File.exist?(list_file)
391
+ File.delete(token_file) if File.exist?(token_file)
392
+ end
393
+ end
394
+
395
+ describe 'delete_file' do
396
+ subject { storage.delete_file(file_name) }
397
+ let(:list_file) { storage.file_list.list_file }
398
+ let(:token_file) { storage.token.token_file }
399
+ context 'success' do
400
+ let(:file_name) { 'file1' }
401
+ let(:posit_dir) do
402
+ [{'id' => 'file1234', 'title' => 'file1', 'mimeType' => 'text/plain'}]
403
+ end
404
+ before(:each) do
405
+ list = [{'items' => {'file1' => {'id' => 'file1234', 'type' => 'file'}}}]
406
+ open(list_file, 'wb') { |file| file << Marshal.dump(list) }
407
+ end
408
+ it do
409
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_delete)
410
+ .with('file1234')
411
+ .and_return(true)
412
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_dir)
413
+ .with('top')
414
+ .and_return(posit_dir)
415
+ is_expected.to be_truthy
416
+ end
417
+ end
418
+ context 'fail' do
419
+ context 'file name not input' do
420
+ let(:file_name) { '' }
421
+ it { expect { subject }.to raise_error(CloudDoor::FileNameEmptyException) }
422
+ end
423
+ context 'file id not exits' do
424
+ let(:file_name) { 'test' }
425
+ it { expect { subject }.to raise_error(CloudDoor::SetIDException) }
426
+ end
427
+ end
428
+ after(:each) do
429
+ File.delete(list_file) if File.exist?(list_file)
430
+ File.delete(token_file) if File.exist?(token_file)
431
+ end
432
+ end
433
+
434
+ describe 'make_directory' do
435
+ subject { storage.make_directory(mkdir_name) }
436
+ let(:list_file) { storage.file_list.list_file }
437
+ let(:token_file) { storage.token.token_file }
438
+ context 'success' do
439
+ let(:mkdir_name) { 'folder1' }
440
+ let(:posit_dir) do
441
+ [{'id' => 'file1234', 'title' => 'file1', 'mimeType' => 'text/plain'}]
442
+ end
443
+ it do
444
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_mkdir)
445
+ .with('folder1', 'top')
446
+ .and_return(true)
447
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_dir)
448
+ .with('top')
449
+ .and_return(posit_dir)
450
+ is_expected.to be_truthy
451
+ end
452
+ end
453
+ context 'fail' do
454
+ context 'file name not input' do
455
+ let(:mkdir_name) { '' }
456
+ it { expect { subject }.to raise_error(CloudDoor::DirectoryNameEmptyException) }
457
+ end
458
+ end
459
+ after(:each) do
460
+ File.delete(list_file) if File.exist?(list_file)
461
+ File.delete(token_file) if File.exist?(token_file)
462
+ end
463
+ end
464
+
465
+ describe 'assign_upload_file_name' do
466
+ subject { storage.assign_upload_file_name(file_name) }
467
+ let(:storage) { create_storage(CloudDoor::GoogleDrive) }
468
+ context 'file' do
469
+ let(:file_name) { 'testfile' }
470
+ it { is_expected.to eq file_name }
471
+ end
472
+ context 'directory' do
473
+ let(:file_name) { 'testdir' }
474
+ before(:each) do
475
+ Dir.mkdir(file_name)
476
+ end
477
+ it { is_expected.to eq "#{file_name}.zip" }
478
+ after(:each) do
479
+ Dir.rmdir(file_name) if File.exist?(file_name)
480
+ end
481
+ end
482
+ end
483
+
484
+ describe 'file_exist?' do
485
+ subject { storage.file_exist?(file_name) }
486
+ let(:list_file) { storage.file_list.list_file }
487
+ let(:token_file) { storage.token.token_file }
488
+ before(:each) do
489
+ list = [{'items' => {'file1' => {'id' => 'file1234', 'type' => 'file'}}}]
490
+ open(list_file, 'wb') { |file| file << Marshal.dump(list) }
491
+ end
492
+ context 'return true' do
493
+ let(:posit) do
494
+ [{'id' => 'file1234', 'title' => 'file1', 'mimeType' => 'text/plain'}]
495
+ end
496
+ context 'file exists' do
497
+ let(:file_name) { 'file1' }
498
+ it do
499
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_dir)
500
+ .with('top')
501
+ .and_return(posit)
502
+ is_expected.to be_truthy
503
+ end
504
+ end
505
+ end
506
+ context 'return false' do
507
+ let(:posit) do
508
+ [{'id' => 'file5678', 'title' => 'file2', 'mimeType' => 'text/plain'}]
509
+ end
510
+ context 'file not found' do
511
+ let(:file_name) { 'file1' }
512
+ before(:each) do
513
+ CloudDoor::GoogleDriveBridge.any_instance.stub(:request_dir)
514
+ .and_return(posit)
515
+ end
516
+ it { is_expected.to be_falsey }
517
+ end
518
+ end
519
+ after(:each) do
520
+ File.delete(list_file) if File.exist?(list_file)
521
+ end
522
+ end
523
+
524
+ describe 'has_file?' do
525
+ subject { storage.has_file?(file_name) }
526
+ let(:list_file) { storage.file_list.list_file }
527
+ let(:token_file) { storage.token.token_file }
528
+ before(:each) do
529
+ file1 = {'id' => 'file1234', 'type' => 'file'}
530
+ folder1 = {'id' => 'folder1234', 'type' => 'folder'}
531
+ list = [
532
+ {'items' => {'file1' => file1, 'folder1' => folder1}}
533
+ ]
534
+ open(list_file, 'wb') { |file| file << Marshal.dump(list) }
535
+ end
536
+ context 'return true' do
537
+ context 'count > 0' do
538
+ let(:file_name) { 'folder1' }
539
+ let(:posit) do
540
+ [
541
+ {'id' => 'file1234', 'title' => 'file1', 'mimeType' => 'text/plain'},
542
+ {'id' => 'file5678', 'title' => 'file2', 'mimeType' => 'text/plain'}
543
+ ]
544
+ end
545
+ before(:each) do
546
+ storage.stub(:file_exist?)
547
+ .with(file_name)
548
+ .and_return(true)
549
+ end
550
+ it do
551
+ expect_any_instance_of(CloudDoor::GoogleDriveBridge).to receive(:request_dir)
552
+ .with('folder1234')
553
+ .and_return(posit)
554
+ is_expected.to be_truthy
555
+ end
556
+ end
557
+ end
558
+ context 'return false' do
559
+ context 'target is file' do
560
+ let(:file_name) { 'file1' }
561
+ it { is_expected.to be_falsey }
562
+ end
563
+ context 'count == 0' do
564
+ let(:file_name) { 'folder1' }
565
+ let(:posit) { [] }
566
+ before(:each) do
567
+ storage.stub(:file_exist?)
568
+ .with(file_name)
569
+ .and_return(true)
570
+ CloudDoor::GoogleDriveBridge.any_instance.stub(:request_dir).and_return(posit)
571
+ end
572
+ it { is_expected.to be_falsey }
573
+ end
574
+ end
575
+ context 'fail' do
576
+ context 'file name not input' do
577
+ let(:file_name) { '' }
578
+ it { expect { subject }.to raise_error(CloudDoor::FileNameEmptyException) }
579
+ end
580
+ context 'file id not exits' do
581
+ let(:file_name) { 'test' }
582
+ it { expect { subject }.to raise_error(CloudDoor::SetIDException) }
583
+ end
584
+ end
585
+ after(:each) do
586
+ File.delete(list_file) if File.exist?(list_file)
587
+ File.delete(token_file) if File.exist?(token_file)
588
+ end
589
+ end
590
+
591
+ describe 'file?' do
592
+ subject { storage.file?(file_name) }
593
+ let(:storage) { create_storage(CloudDoor::GoogleDrive) }
594
+ let(:list_file) { storage.file_list.list_file }
595
+ before(:each) do
596
+ file1 = {'id' => 'file1234', 'name' => 'file1', 'type' => 'file'}
597
+ folder1 = {'id' => 'folder1234', 'name' => 'folder1', 'type' => 'folder'}
598
+ list = [
599
+ {'items' => {'file1' => file1, 'folder1' => folder1}}
600
+ ]
601
+ open(list_file, 'wb') { |file| file << Marshal.dump(list) }
602
+ end
603
+ context 'return true' do
604
+ context 'file' do
605
+ let(:file_name) { 'file1' }
606
+ it { is_expected.to be_truthy }
607
+ end
608
+ end
609
+ context 'return false' do
610
+ context 'file name not input' do
611
+ let(:file_name) { '' }
612
+ it { is_expected.to be_falsey }
613
+ end
614
+ context 'parent' do
615
+ let(:file_name) { '../' }
616
+ it { is_expected.to be_falsey }
617
+ end
618
+ context 'folder' do
619
+ let(:file_name) { 'folder1' }
620
+ it { is_expected.to be_falsey }
621
+ end
622
+ end
623
+ end
624
+
625
+ describe 'load_token' do
626
+ let(:storage) do
627
+ storage = create_storage(CloudDoor::GoogleDrive)
628
+ storage.token.credentials = Marshal.dump('credentials')
629
+ token_file = storage.token.token_file
630
+ Google::APIClient.any_instance.stub(:authorization=)
631
+ .and_return(true)
632
+ Google::APIClient.any_instance.stub(:discovered_api)
633
+ .and_return(true)
634
+ CloudDoor::GoogleDriveBridge.any_instance.stub(:request_root_id)
635
+ .and_return('top')
636
+ open(token_file, 'wb') { |file| file << Marshal.dump(storage.token) }
637
+ storage
638
+ end
639
+ let(:token_file) { storage.token.token_file }
640
+ it do
641
+ result = storage.load_token
642
+ expect(result.is_a?(CloudDoor::Token)).to be_truthy
643
+ end
644
+ after(:each) do
645
+ File.delete(token_file) if File.exist?(token_file)
646
+ end
647
+ end
648
+ end