backup 3.0.27 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.md +1 -1
- data/README.md +139 -386
- data/bin/backup +1 -7
- data/lib/backup.rb +3 -9
- data/lib/backup/archive.rb +26 -20
- data/lib/backup/cleaner.rb +2 -2
- data/lib/backup/cli.rb +366 -0
- data/lib/backup/compressor/base.rb +2 -2
- data/lib/backup/compressor/gzip.rb +35 -1
- data/lib/backup/config.rb +1 -2
- data/lib/backup/database/base.rb +2 -2
- data/lib/backup/database/mongodb.rb +3 -3
- data/lib/backup/database/mysql.rb +3 -2
- data/lib/backup/database/postgresql.rb +3 -2
- data/lib/backup/database/riak.rb +18 -5
- data/lib/backup/dependency.rb +144 -93
- data/lib/backup/encryptor/base.rb +2 -2
- data/lib/backup/logger.rb +108 -110
- data/lib/backup/logger/console.rb +51 -0
- data/lib/backup/logger/logfile.rb +113 -0
- data/lib/backup/logger/syslog.rb +116 -0
- data/lib/backup/model.rb +67 -65
- data/lib/backup/notifier/base.rb +1 -1
- data/lib/backup/notifier/hipchat.rb +1 -1
- data/lib/backup/notifier/mail.rb +1 -1
- data/lib/backup/notifier/pushover.rb +6 -3
- data/lib/backup/packager.rb +4 -4
- data/lib/backup/pipeline.rb +17 -3
- data/lib/backup/splitter.rb +2 -2
- data/lib/backup/storage/base.rb +2 -2
- data/lib/backup/storage/cloudfiles.rb +2 -2
- data/lib/backup/storage/dropbox.rb +4 -4
- data/lib/backup/storage/ftp.rb +2 -2
- data/lib/backup/storage/local.rb +2 -2
- data/lib/backup/storage/ninefold.rb +2 -2
- data/lib/backup/storage/rsync.rb +3 -3
- data/lib/backup/storage/s3.rb +2 -2
- data/lib/backup/storage/scp.rb +2 -6
- data/lib/backup/storage/sftp.rb +2 -5
- data/lib/backup/syncer/base.rb +1 -1
- data/lib/backup/syncer/cloud/base.rb +15 -8
- data/lib/backup/syncer/rsync/local.rb +1 -1
- data/lib/backup/syncer/rsync/pull.rb +1 -1
- data/lib/backup/syncer/rsync/push.rb +1 -1
- data/lib/backup/utilities.rb +211 -0
- data/lib/backup/version.rb +1 -1
- data/templates/cli/{utility/archive → archive} +4 -8
- data/templates/cli/{utility/compressor → compressor}/bzip2 +0 -0
- data/templates/cli/{utility/compressor → compressor}/custom +0 -0
- data/templates/cli/{utility/compressor → compressor}/gzip +0 -0
- data/templates/cli/{utility/compressor → compressor}/lzma +0 -0
- data/templates/cli/{utility/compressor → compressor}/pbzip2 +0 -0
- data/templates/cli/config +68 -0
- data/templates/cli/{utility/database → database}/mongodb +1 -1
- data/templates/cli/{utility/database → database}/mysql +1 -1
- data/templates/cli/{utility/database → database}/postgresql +1 -1
- data/templates/cli/{utility/database → database}/redis +0 -0
- data/templates/cli/database/riak +20 -0
- data/templates/cli/{utility/encryptor → encryptor}/gpg +0 -0
- data/templates/cli/{utility/encryptor → encryptor}/openssl +0 -0
- data/templates/cli/{utility/model.erb → model.erb} +4 -4
- data/templates/cli/{utility/notifier → notifier}/campfire +0 -0
- data/templates/cli/{utility/notifier → notifier}/hipchat +0 -0
- data/templates/cli/{utility/notifier → notifier}/mail +0 -0
- data/templates/cli/{utility/notifier → notifier}/prowl +0 -0
- data/templates/cli/{utility/notifier → notifier}/pushover +0 -0
- data/templates/cli/{utility/notifier → notifier}/twitter +0 -0
- data/templates/cli/{utility/splitter → splitter} +0 -0
- data/templates/cli/{utility/storage → storage}/cloud_files +0 -0
- data/templates/cli/{utility/storage → storage}/dropbox +0 -0
- data/templates/cli/{utility/storage → storage}/ftp +0 -0
- data/templates/cli/{utility/storage → storage}/local +0 -0
- data/templates/cli/{utility/storage → storage}/ninefold +0 -0
- data/templates/cli/{utility/storage → storage}/rsync +0 -0
- data/templates/cli/{utility/storage → storage}/s3 +0 -0
- data/templates/cli/{utility/storage → storage}/scp +0 -0
- data/templates/cli/{utility/storage → storage}/sftp +0 -0
- data/templates/cli/{utility/syncer → syncer}/cloud_files +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_local +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_pull +0 -0
- data/templates/cli/{utility/syncer → syncer}/rsync_push +0 -0
- data/templates/cli/{utility/syncer → syncer}/s3 +0 -0
- metadata +55 -131
- data/.gitignore +0 -8
- data/.travis.yml +0 -10
- data/Gemfile +0 -28
- data/Guardfile +0 -23
- data/backup.gemspec +0 -32
- data/lib/backup/cli/helpers.rb +0 -93
- data/lib/backup/cli/utility.rb +0 -255
- data/spec-live/.gitignore +0 -6
- data/spec-live/README +0 -7
- data/spec-live/backups/config.rb +0 -83
- data/spec-live/backups/config.yml.template +0 -46
- data/spec-live/backups/models.rb +0 -184
- data/spec-live/compressor/custom_spec.rb +0 -30
- data/spec-live/compressor/gzip_spec.rb +0 -30
- data/spec-live/encryptor/gpg_keys.rb +0 -239
- data/spec-live/encryptor/gpg_spec.rb +0 -287
- data/spec-live/notifier/mail_spec.rb +0 -121
- data/spec-live/spec_helper.rb +0 -151
- data/spec-live/storage/dropbox_spec.rb +0 -151
- data/spec-live/storage/local_spec.rb +0 -83
- data/spec-live/storage/scp_spec.rb +0 -193
- data/spec-live/syncer/cloud/s3_spec.rb +0 -124
- data/spec/archive_spec.rb +0 -335
- data/spec/cleaner_spec.rb +0 -312
- data/spec/cli/helpers_spec.rb +0 -301
- data/spec/cli/utility_spec.rb +0 -411
- data/spec/compressor/base_spec.rb +0 -52
- data/spec/compressor/bzip2_spec.rb +0 -217
- data/spec/compressor/custom_spec.rb +0 -106
- data/spec/compressor/gzip_spec.rb +0 -217
- data/spec/compressor/lzma_spec.rb +0 -123
- data/spec/compressor/pbzip2_spec.rb +0 -165
- data/spec/config_spec.rb +0 -321
- data/spec/configuration/helpers_spec.rb +0 -247
- data/spec/configuration/store_spec.rb +0 -39
- data/spec/configuration_spec.rb +0 -62
- data/spec/database/base_spec.rb +0 -63
- data/spec/database/mongodb_spec.rb +0 -510
- data/spec/database/mysql_spec.rb +0 -411
- data/spec/database/postgresql_spec.rb +0 -353
- data/spec/database/redis_spec.rb +0 -334
- data/spec/database/riak_spec.rb +0 -176
- data/spec/dependency_spec.rb +0 -51
- data/spec/encryptor/base_spec.rb +0 -40
- data/spec/encryptor/gpg_spec.rb +0 -909
- data/spec/encryptor/open_ssl_spec.rb +0 -148
- data/spec/errors_spec.rb +0 -306
- data/spec/logger_spec.rb +0 -367
- data/spec/model_spec.rb +0 -666
- data/spec/notifier/base_spec.rb +0 -104
- data/spec/notifier/campfire_spec.rb +0 -217
- data/spec/notifier/hipchat_spec.rb +0 -211
- data/spec/notifier/mail_spec.rb +0 -316
- data/spec/notifier/prowl_spec.rb +0 -138
- data/spec/notifier/pushover_spec.rb +0 -123
- data/spec/notifier/twitter_spec.rb +0 -153
- data/spec/package_spec.rb +0 -61
- data/spec/packager_spec.rb +0 -213
- data/spec/pipeline_spec.rb +0 -259
- data/spec/spec_helper.rb +0 -60
- data/spec/splitter_spec.rb +0 -120
- data/spec/storage/base_spec.rb +0 -166
- data/spec/storage/cloudfiles_spec.rb +0 -254
- data/spec/storage/cycler_spec.rb +0 -247
- data/spec/storage/dropbox_spec.rb +0 -480
- data/spec/storage/ftp_spec.rb +0 -271
- data/spec/storage/local_spec.rb +0 -259
- data/spec/storage/ninefold_spec.rb +0 -343
- data/spec/storage/rsync_spec.rb +0 -362
- data/spec/storage/s3_spec.rb +0 -245
- data/spec/storage/scp_spec.rb +0 -233
- data/spec/storage/sftp_spec.rb +0 -244
- data/spec/syncer/base_spec.rb +0 -109
- data/spec/syncer/cloud/base_spec.rb +0 -515
- data/spec/syncer/cloud/cloud_files_spec.rb +0 -181
- data/spec/syncer/cloud/s3_spec.rb +0 -174
- data/spec/syncer/rsync/base_spec.rb +0 -98
- data/spec/syncer/rsync/local_spec.rb +0 -149
- data/spec/syncer/rsync/pull_spec.rb +0 -98
- data/spec/syncer/rsync/push_spec.rb +0 -333
- data/spec/version_spec.rb +0 -21
- data/templates/cli/utility/config +0 -32
- data/templates/cli/utility/database/riak +0 -11
@@ -1,480 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path('../../spec_helper.rb', __FILE__)
|
4
|
-
|
5
|
-
describe Backup::Storage::Dropbox do
|
6
|
-
let(:model) { Backup::Model.new(:test_trigger, 'test label') }
|
7
|
-
let(:storage) do
|
8
|
-
Backup::Storage::Dropbox.new(model) do |db|
|
9
|
-
db.api_key = 'my_api_key'
|
10
|
-
db.api_secret = 'my_api_secret'
|
11
|
-
db.keep = 5
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should be a subclass of Storage::Base' do
|
16
|
-
Backup::Storage::Dropbox.
|
17
|
-
superclass.should == Backup::Storage::Base
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#initialize' do
|
21
|
-
after { Backup::Storage::Dropbox.clear_defaults! }
|
22
|
-
|
23
|
-
it 'should load pre-configured defaults through Base' do
|
24
|
-
Backup::Storage::Dropbox.any_instance.expects(:load_defaults!)
|
25
|
-
storage
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should pass the model reference to Base' do
|
29
|
-
storage.instance_variable_get(:@model).should == model
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should pass the storage_id to Base' do
|
33
|
-
storage = Backup::Storage::Dropbox.new(model, 'my_storage_id')
|
34
|
-
storage.storage_id.should == 'my_storage_id'
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when no pre-configured defaults have been set' do
|
38
|
-
it 'should use the values given' do
|
39
|
-
storage.api_key.should == 'my_api_key'
|
40
|
-
storage.api_secret.should == 'my_api_secret'
|
41
|
-
storage.access_type.should == :app_folder
|
42
|
-
storage.path.should == 'backups'
|
43
|
-
|
44
|
-
storage.storage_id.should be_nil
|
45
|
-
storage.keep.should == 5
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should use default values if none are given' do
|
49
|
-
storage = Backup::Storage::Dropbox.new(model)
|
50
|
-
storage.api_key.should be_nil
|
51
|
-
storage.api_secret.should be_nil
|
52
|
-
storage.access_type.should == :app_folder
|
53
|
-
storage.path.should == 'backups'
|
54
|
-
|
55
|
-
storage.storage_id.should be_nil
|
56
|
-
storage.keep.should be_nil
|
57
|
-
end
|
58
|
-
end # context 'when no pre-configured defaults have been set'
|
59
|
-
|
60
|
-
context 'when pre-configured defaults have been set' do
|
61
|
-
before do
|
62
|
-
Backup::Storage::Dropbox.defaults do |s|
|
63
|
-
s.api_key = 'some_api_key'
|
64
|
-
s.api_secret = 'some_api_secret'
|
65
|
-
s.access_type = 'some_access_type'
|
66
|
-
s.path = 'some_path'
|
67
|
-
s.keep = 15
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should use pre-configured defaults' do
|
72
|
-
storage = Backup::Storage::Dropbox.new(model)
|
73
|
-
|
74
|
-
storage.api_key.should == 'some_api_key'
|
75
|
-
storage.api_secret.should == 'some_api_secret'
|
76
|
-
storage.access_type.should == 'some_access_type'
|
77
|
-
storage.path.should == 'some_path'
|
78
|
-
|
79
|
-
storage.storage_id.should be_nil
|
80
|
-
storage.keep.should == 15
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should override pre-configured defaults' do
|
84
|
-
storage = Backup::Storage::Dropbox.new(model) do |s|
|
85
|
-
s.api_key = 'new_api_key'
|
86
|
-
s.api_secret = 'new_api_secret'
|
87
|
-
s.access_type = 'new_access_type'
|
88
|
-
s.path = 'new_path'
|
89
|
-
s.keep = 10
|
90
|
-
end
|
91
|
-
|
92
|
-
storage.api_key.should == 'new_api_key'
|
93
|
-
storage.api_secret.should == 'new_api_secret'
|
94
|
-
storage.access_type.should == 'new_access_type'
|
95
|
-
storage.path.should == 'new_path'
|
96
|
-
|
97
|
-
storage.storage_id.should be_nil
|
98
|
-
storage.keep.should == 10
|
99
|
-
end
|
100
|
-
end # context 'when pre-configured defaults have been set'
|
101
|
-
end # describe '#initialize'
|
102
|
-
|
103
|
-
describe '#connection' do
|
104
|
-
let(:session) { mock }
|
105
|
-
let(:client) { mock }
|
106
|
-
let(:s) { sequence '' }
|
107
|
-
|
108
|
-
context 'when a cached session exists' do
|
109
|
-
before do
|
110
|
-
storage.expects(:cached_session).in_sequence(s).returns(session)
|
111
|
-
storage.expects(:create_write_and_return_new_session!).never
|
112
|
-
DropboxClient.expects(:new).in_sequence(s).
|
113
|
-
with(session, :app_folder).returns(client)
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'should use the cached session to create the client' do
|
117
|
-
storage.send(:connection).should be(client)
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'should return an already existing client' do
|
121
|
-
storage.send(:connection).should be(client)
|
122
|
-
storage.send(:connection).should be(client)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context 'when a cached session does not exist' do
|
127
|
-
before do
|
128
|
-
storage.expects(:cached_session).in_sequence(s).returns(false)
|
129
|
-
Backup::Logger.expects(:message).in_sequence(s).with(
|
130
|
-
'Creating a new session!'
|
131
|
-
)
|
132
|
-
storage.expects(:create_write_and_return_new_session!).in_sequence(s).
|
133
|
-
returns(session)
|
134
|
-
DropboxClient.expects(:new).in_sequence(s).
|
135
|
-
with(session, :app_folder).returns(client)
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'should create a new session and return the client' do
|
139
|
-
storage.send(:connection).should be(client)
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'should return an already existing client' do
|
143
|
-
storage.send(:connection).should be(client)
|
144
|
-
storage.send(:connection).should be(client)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
context 'when an error is raised creating a client for the session' do
|
149
|
-
it 'should wrap and raise the error' do
|
150
|
-
storage.stubs(:cached_session).returns(true)
|
151
|
-
DropboxClient.expects(:new).raises('error')
|
152
|
-
|
153
|
-
expect do
|
154
|
-
storage.send(:connection)
|
155
|
-
end.to raise_error {|err|
|
156
|
-
err.should be_an_instance_of(
|
157
|
-
Backup::Errors::Storage::Dropbox::ConnectionError
|
158
|
-
)
|
159
|
-
err.message.should ==
|
160
|
-
'Storage::Dropbox::ConnectionError: RuntimeError: error'
|
161
|
-
}
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
end # describe '#connection'
|
166
|
-
|
167
|
-
describe '#cached_session' do
|
168
|
-
let(:session) { mock }
|
169
|
-
|
170
|
-
context 'when a cached session file exists' do
|
171
|
-
before do
|
172
|
-
storage.expects(:cache_exists?).returns(true)
|
173
|
-
storage.expects(:cached_file).returns('cached_file')
|
174
|
-
File.expects(:read).with('cached_file').returns('yaml_data')
|
175
|
-
end
|
176
|
-
|
177
|
-
context 'when the cached session is successfully loaded' do
|
178
|
-
it 'should return the sesssion' do
|
179
|
-
DropboxSession.expects(:deserialize).with('yaml_data').
|
180
|
-
returns(session)
|
181
|
-
Backup::Logger.expects(:message).with(
|
182
|
-
'Session data loaded from cache!'
|
183
|
-
)
|
184
|
-
|
185
|
-
storage.send(:cached_session).should be(session)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
context 'when errors occur loading the session' do
|
190
|
-
it 'should log a warning and return false' do
|
191
|
-
DropboxSession.expects(:deserialize).with('yaml_data').
|
192
|
-
raises('error message')
|
193
|
-
Backup::Logger.expects(:warn).with do |err|
|
194
|
-
err.should be_an_instance_of(
|
195
|
-
Backup::Errors::Storage::Dropbox::CacheError
|
196
|
-
)
|
197
|
-
err.message.should == 'Storage::Dropbox::CacheError: ' +
|
198
|
-
"Could not read session data from cache.\n" +
|
199
|
-
" Cache data might be corrupt.\n" +
|
200
|
-
" Reason: RuntimeError\n" +
|
201
|
-
" error message"
|
202
|
-
end
|
203
|
-
|
204
|
-
expect do
|
205
|
-
storage.send(:cached_session).should be_false
|
206
|
-
end.not_to raise_error
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
context 'when a cached session file does not exist' do
|
212
|
-
before { storage.stubs(:cache_exists?).returns(false) }
|
213
|
-
it 'should return false' do
|
214
|
-
storage.send(:cached_session).should be_false
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
describe '#transfer!' do
|
220
|
-
let(:connection) { mock }
|
221
|
-
let(:package) { mock }
|
222
|
-
let(:file) { mock }
|
223
|
-
let(:s) { sequence '' }
|
224
|
-
|
225
|
-
before do
|
226
|
-
storage.instance_variable_set(:@package, package)
|
227
|
-
storage.stubs(:storage_name).returns('Storage::Dropbox')
|
228
|
-
storage.stubs(:local_path).returns('/local/path')
|
229
|
-
storage.stubs(:connection).returns(connection)
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'should transfer the package files' do
|
233
|
-
storage.expects(:remote_path_for).in_sequence(s).with(package).
|
234
|
-
returns('remote/path')
|
235
|
-
storage.expects(:files_to_transfer_for).in_sequence(s).with(package).
|
236
|
-
multiple_yields(
|
237
|
-
['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
|
238
|
-
['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
|
239
|
-
)
|
240
|
-
# first yield
|
241
|
-
Backup::Logger.expects(:message).in_sequence(s).with(
|
242
|
-
"Storage::Dropbox started transferring " +
|
243
|
-
"'2011.12.31.11.00.02.backup.tar.enc-aa'."
|
244
|
-
)
|
245
|
-
File.expects(:open).in_sequence(s).with(
|
246
|
-
File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-aa'), 'r'
|
247
|
-
).yields(file)
|
248
|
-
connection.expects(:put_file).in_sequence(s).with(
|
249
|
-
File.join('remote/path', 'backup.tar.enc-aa'), file
|
250
|
-
)
|
251
|
-
# second yield
|
252
|
-
Backup::Logger.expects(:message).in_sequence(s).with(
|
253
|
-
"Storage::Dropbox started transferring " +
|
254
|
-
"'2011.12.31.11.00.02.backup.tar.enc-ab'."
|
255
|
-
)
|
256
|
-
File.expects(:open).in_sequence(s).with(
|
257
|
-
File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-ab'), 'r'
|
258
|
-
).yields(file)
|
259
|
-
connection.expects(:put_file).in_sequence(s).with(
|
260
|
-
File.join('remote/path', 'backup.tar.enc-ab'), file
|
261
|
-
)
|
262
|
-
|
263
|
-
storage.send(:transfer!)
|
264
|
-
end
|
265
|
-
end # describe '#transfer!'
|
266
|
-
|
267
|
-
describe '#remove!' do
|
268
|
-
let(:package) { mock }
|
269
|
-
let(:connection) { mock }
|
270
|
-
let(:s) { sequence '' }
|
271
|
-
|
272
|
-
before do
|
273
|
-
storage.stubs(:storage_name).returns('Storage::Dropbox')
|
274
|
-
storage.stubs(:connection).returns(connection)
|
275
|
-
end
|
276
|
-
|
277
|
-
it 'should remove the package files' do
|
278
|
-
storage.expects(:remote_path_for).in_sequence(s).with(package).
|
279
|
-
returns('remote/path')
|
280
|
-
storage.expects(:transferred_files_for).in_sequence(s).with(package).
|
281
|
-
multiple_yields(
|
282
|
-
['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
|
283
|
-
['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
|
284
|
-
)
|
285
|
-
# after both yields
|
286
|
-
Backup::Logger.expects(:message).in_sequence(s).with(
|
287
|
-
"Storage::Dropbox started removing " +
|
288
|
-
"'2011.12.31.11.00.02.backup.tar.enc-aa' from Dropbox.\n" +
|
289
|
-
"Storage::Dropbox started removing " +
|
290
|
-
"'2011.12.31.11.00.02.backup.tar.enc-ab' from Dropbox."
|
291
|
-
)
|
292
|
-
connection.expects(:file_delete).in_sequence(s).with('remote/path')
|
293
|
-
|
294
|
-
storage.send(:remove!, package)
|
295
|
-
end
|
296
|
-
end # describe '#remove!'
|
297
|
-
|
298
|
-
describe '#cached_file' do
|
299
|
-
it 'should return the path to the cache file' do
|
300
|
-
storage.send(:cached_file).should ==
|
301
|
-
File.join(Backup::Config.cache_path, 'my_api_keymy_api_secret')
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
describe '#cache_exists?' do
|
306
|
-
it 'should check if #cached_file exists' do
|
307
|
-
storage.expects(:cached_file).returns('/path/to/cache_file')
|
308
|
-
File.expects(:exist?).with('/path/to/cache_file')
|
309
|
-
|
310
|
-
storage.send(:cache_exists?)
|
311
|
-
end
|
312
|
-
end
|
313
|
-
|
314
|
-
describe '#write_cache!' do
|
315
|
-
let(:session) { mock }
|
316
|
-
let(:cache_file) { mock }
|
317
|
-
|
318
|
-
it 'should write a serialized session to file' do
|
319
|
-
storage.expects(:cached_file).returns('/path/to/cache_file')
|
320
|
-
session.expects(:serialize).returns('serialized_data')
|
321
|
-
|
322
|
-
File.expects(:open).with('/path/to/cache_file', 'w').yields(cache_file)
|
323
|
-
cache_file.expects(:write).with('serialized_data')
|
324
|
-
|
325
|
-
storage.send(:write_cache!, session)
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
describe '#create_write_and_return_new_session!' do
|
330
|
-
let(:session) { mock }
|
331
|
-
let(:template) { mock }
|
332
|
-
let(:s) { sequence '' }
|
333
|
-
|
334
|
-
before do
|
335
|
-
storage.stubs(:cached_file).returns('/path/to/cache_file')
|
336
|
-
|
337
|
-
DropboxSession.expects(:new).in_sequence(s).
|
338
|
-
with('my_api_key', 'my_api_secret').returns(session)
|
339
|
-
session.expects(:get_request_token).in_sequence(s)
|
340
|
-
Backup::Template.expects(:new).in_sequence(s).with(
|
341
|
-
{:session => session, :cached_file => '/path/to/cache_file'}
|
342
|
-
).returns(template)
|
343
|
-
template.expects(:render).in_sequence(s).with(
|
344
|
-
'storage/dropbox/authorization_url.erb'
|
345
|
-
)
|
346
|
-
Timeout.expects(:timeout).in_sequence(s).with(180).yields
|
347
|
-
STDIN.expects(:gets).in_sequence(s)
|
348
|
-
end
|
349
|
-
|
350
|
-
context 'when session is authenticated' do
|
351
|
-
before do
|
352
|
-
session.expects(:get_access_token).in_sequence(s)
|
353
|
-
end
|
354
|
-
|
355
|
-
it 'should cache and return the new session' do
|
356
|
-
template.expects(:render).in_sequence(s).with(
|
357
|
-
'storage/dropbox/authorized.erb'
|
358
|
-
)
|
359
|
-
storage.expects(:write_cache!).in_sequence(s).with(session)
|
360
|
-
template.expects(:render).in_sequence(s).with(
|
361
|
-
'storage/dropbox/cache_file_written.erb'
|
362
|
-
)
|
363
|
-
|
364
|
-
storage.send(:create_write_and_return_new_session!).should be(session)
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
context 'when session is not authenticated' do
|
369
|
-
before do
|
370
|
-
session.expects(:get_access_token).in_sequence(s).raises('error message')
|
371
|
-
end
|
372
|
-
|
373
|
-
it 'should wrap and re-raise the error' do
|
374
|
-
template.expects(:render).with('storage/dropbox/authorized.erb').never
|
375
|
-
storage.expects(:write_cache!).never
|
376
|
-
template.expects(:render).with('storage/dropbox/cache_file_written.erb').never
|
377
|
-
|
378
|
-
expect do
|
379
|
-
storage.send(:create_write_and_return_new_session!)
|
380
|
-
end.to raise_error {|err|
|
381
|
-
err.should be_an_instance_of(
|
382
|
-
Backup::Errors::Storage::Dropbox::AuthenticationError
|
383
|
-
)
|
384
|
-
err.message.should == 'Storage::Dropbox::AuthenticationError: ' +
|
385
|
-
"Could not create or authenticate a new session\n" +
|
386
|
-
" Reason: RuntimeError\n" +
|
387
|
-
" error message"
|
388
|
-
}
|
389
|
-
end
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
describe 'deprecations' do
|
394
|
-
after do
|
395
|
-
Backup::Storage::Dropbox.clear_defaults!
|
396
|
-
end
|
397
|
-
|
398
|
-
describe '#email' do
|
399
|
-
before do
|
400
|
-
Backup::Logger.expects(:warn).with do |err|
|
401
|
-
err.message.should match(
|
402
|
-
"Dropbox#email has been deprecated as of backup v.3.0.17"
|
403
|
-
)
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
context 'when set directly' do
|
408
|
-
it 'should issue a deprecation warning' do
|
409
|
-
Backup::Storage::Dropbox.new(model) do |storage|
|
410
|
-
storage.email = 'foo'
|
411
|
-
end
|
412
|
-
end
|
413
|
-
end
|
414
|
-
|
415
|
-
context 'when set as a default' do
|
416
|
-
it 'should issue a deprecation warning' do
|
417
|
-
Backup::Storage::Dropbox.defaults do |storage|
|
418
|
-
storage.email = 'foo'
|
419
|
-
end
|
420
|
-
Backup::Storage::Dropbox.new(model)
|
421
|
-
end
|
422
|
-
end
|
423
|
-
end
|
424
|
-
|
425
|
-
describe '#password' do
|
426
|
-
before do
|
427
|
-
Backup::Logger.expects(:warn).with do |err|
|
428
|
-
err.message.should match(
|
429
|
-
"Dropbox#password has been deprecated as of backup v.3.0.17"
|
430
|
-
)
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
context 'when set directly' do
|
435
|
-
it 'should issue a deprecation warning' do
|
436
|
-
Backup::Storage::Dropbox.new(model) do |storage|
|
437
|
-
storage.password = 'foo'
|
438
|
-
end
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
context 'when set as a default' do
|
443
|
-
it 'should issue a deprecation warning' do
|
444
|
-
Backup::Storage::Dropbox.defaults do |storage|
|
445
|
-
storage.password = 'foo'
|
446
|
-
end
|
447
|
-
Backup::Storage::Dropbox.new(model)
|
448
|
-
end
|
449
|
-
end
|
450
|
-
end
|
451
|
-
|
452
|
-
describe '#timeout' do
|
453
|
-
before do
|
454
|
-
Backup::Logger.expects(:warn).with do |err|
|
455
|
-
err.message.should match(
|
456
|
-
"Dropbox#timeout has been deprecated as of backup v.3.0.21"
|
457
|
-
)
|
458
|
-
end
|
459
|
-
end
|
460
|
-
|
461
|
-
context 'when set directly' do
|
462
|
-
it 'should issue a deprecation warning' do
|
463
|
-
Backup::Storage::Dropbox.new(model) do |storage|
|
464
|
-
storage.timeout = 'foo'
|
465
|
-
end
|
466
|
-
end
|
467
|
-
end
|
468
|
-
|
469
|
-
context 'when set as a default' do
|
470
|
-
it 'should issue a deprecation warning' do
|
471
|
-
Backup::Storage::Dropbox.defaults do |storage|
|
472
|
-
storage.timeout = 'foo'
|
473
|
-
end
|
474
|
-
Backup::Storage::Dropbox.new(model)
|
475
|
-
end
|
476
|
-
end
|
477
|
-
end
|
478
|
-
end
|
479
|
-
|
480
|
-
end
|