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