imap-backup 4.0.5 → 4.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/imap-backup +5 -2
- data/lib/imap/backup/account/connection.rb +70 -58
- data/lib/imap/backup/account/folder.rb +23 -3
- data/lib/imap/backup/account.rb +6 -7
- data/lib/imap/backup/cli/accounts.rb +43 -0
- data/lib/imap/backup/cli/folders.rb +3 -1
- data/lib/imap/backup/cli/helpers.rb +8 -9
- data/lib/imap/backup/cli/local.rb +4 -2
- data/lib/imap/backup/cli/setup.rb +1 -1
- data/lib/imap/backup/cli/status.rb +1 -1
- data/lib/imap/backup/cli/utils.rb +3 -2
- data/lib/imap/backup/{configuration/store.rb → configuration.rb} +49 -14
- data/lib/imap/backup/downloader.rb +26 -12
- data/lib/imap/backup/logger.rb +42 -0
- data/lib/imap/backup/sanitizer.rb +42 -0
- data/lib/imap/backup/serializer/mbox_store.rb +2 -2
- data/lib/imap/backup/{configuration → setup}/account.rb +59 -41
- data/lib/imap/backup/{configuration → setup}/asker.rb +5 -5
- data/lib/imap/backup/setup/connection_tester.rb +26 -0
- data/lib/imap/backup/{configuration → setup}/folder_chooser.rb +25 -17
- data/lib/imap/backup/setup/helpers.rb +15 -0
- data/lib/imap/backup/{configuration/setup.rb → setup.rb} +33 -25
- data/lib/imap/backup/uploader.rb +2 -2
- data/lib/imap/backup/version.rb +2 -2
- data/lib/imap/backup.rb +7 -33
- data/lib/retry_on_error.rb +1 -1
- data/spec/features/backup_spec.rb +1 -0
- data/spec/features/status_spec.rb +43 -0
- data/spec/features/support/email_server.rb +5 -2
- data/spec/features/support/shared/connection_context.rb +7 -5
- data/spec/support/higline_test_helpers.rb +1 -1
- data/spec/support/silence_logging.rb +1 -1
- data/spec/unit/email/provider/base_spec.rb +1 -1
- data/spec/unit/email/provider_spec.rb +2 -2
- data/spec/unit/imap/backup/account/connection_spec.rb +22 -26
- data/spec/unit/imap/backup/cli/accounts_spec.rb +47 -0
- data/spec/unit/imap/backup/cli/local_spec.rb +15 -4
- data/spec/unit/imap/backup/cli/utils_spec.rb +54 -42
- data/spec/unit/imap/backup/{configuration/store_spec.rb → configuration_spec.rb} +23 -24
- data/spec/unit/imap/backup/downloader_spec.rb +1 -1
- data/spec/unit/imap/backup/logger_spec.rb +48 -0
- data/spec/unit/imap/backup/{configuration → setup}/account_spec.rb +78 -70
- data/spec/unit/imap/backup/{configuration → setup}/asker_spec.rb +2 -2
- data/spec/unit/imap/backup/{configuration → setup}/connection_tester_spec.rb +10 -10
- data/spec/unit/imap/backup/{configuration → setup}/folder_chooser_spec.rb +25 -26
- data/spec/unit/imap/backup/{configuration/setup_spec.rb → setup_spec.rb} +81 -52
- metadata +51 -48
- data/lib/imap/backup/configuration/connection_tester.rb +0 -14
- data/lib/imap/backup/configuration/list.rb +0 -53
- data/spec/support/shared_examples/account_flagging.rb +0 -23
- data/spec/unit/imap/backup/configuration/list_spec.rb +0 -89
- data/spec/unit/imap/backup_spec.rb +0 -28
@@ -1,23 +1,46 @@
|
|
1
|
-
describe Imap::Backup::
|
1
|
+
describe Imap::Backup::Setup do
|
2
2
|
include HighLineTestHelpers
|
3
3
|
|
4
4
|
subject { described_class.new }
|
5
5
|
|
6
|
-
let(:
|
7
|
-
|
6
|
+
let(:normal_account) do
|
7
|
+
instance_double(
|
8
|
+
Imap::Backup::Account,
|
9
|
+
username: "account@example.com",
|
10
|
+
marked_for_deletion?: false,
|
11
|
+
modified?: false
|
12
|
+
)
|
13
|
+
end
|
14
|
+
let(:modified_account) do
|
15
|
+
instance_double(
|
16
|
+
Imap::Backup::Account,
|
17
|
+
username: "modified@example.com",
|
18
|
+
marked_for_deletion?: false,
|
19
|
+
modified?: true
|
20
|
+
)
|
21
|
+
end
|
22
|
+
let(:deleted_account) do
|
23
|
+
instance_double(
|
24
|
+
Imap::Backup::Account,
|
25
|
+
username: "delete@example.com",
|
26
|
+
marked_for_deletion?: true,
|
27
|
+
modified?: false
|
28
|
+
)
|
29
|
+
end
|
30
|
+
let(:accounts) { [normal_account] }
|
8
31
|
let(:store) do
|
9
32
|
instance_double(
|
10
|
-
Imap::Backup::Configuration
|
33
|
+
Imap::Backup::Configuration,
|
11
34
|
"accounts": accounts,
|
12
35
|
"path": "/base/path",
|
13
36
|
"save": nil,
|
14
37
|
"debug?": debug,
|
15
38
|
"debug=": nil,
|
16
|
-
"modified?":
|
39
|
+
"modified?": config_modified
|
17
40
|
)
|
18
41
|
end
|
19
42
|
let(:debug) { false }
|
20
|
-
let(:
|
43
|
+
let(:config_modified) { false }
|
21
44
|
let!(:highline_streams) { prepare_highline }
|
22
45
|
let(:input) { highline_streams[0] }
|
23
46
|
let(:output) { highline_streams[1] }
|
@@ -33,39 +56,48 @@ describe Imap::Backup::Configuration::Setup do
|
|
33
56
|
|
34
57
|
describe "#run" do
|
35
58
|
before do
|
36
|
-
allow(Imap::Backup::Configuration
|
37
|
-
allow(Imap::Backup).to receive(:setup_logging)
|
59
|
+
allow(Imap::Backup::Configuration).to receive(:new) { store }
|
60
|
+
allow(Imap::Backup::Logger).to receive(:setup_logging)
|
38
61
|
allow(input).to receive(:eof?) { false }
|
39
|
-
allow(input).to receive(:gets) { "
|
62
|
+
allow(input).to receive(:gets) { "q\n" }
|
40
63
|
allow(Kernel).to receive(:system)
|
41
64
|
end
|
42
65
|
|
43
66
|
describe "main menu" do
|
44
|
-
|
67
|
+
context "when changes have not been made" do
|
68
|
+
before { subject.run }
|
45
69
|
|
46
|
-
|
47
|
-
|
48
|
-
|
70
|
+
["add account", "quit"].each do |choice|
|
71
|
+
it "includes #{choice}" do
|
72
|
+
expect(output.string).to include(choice)
|
73
|
+
end
|
49
74
|
end
|
50
75
|
end
|
51
|
-
end
|
52
76
|
|
53
|
-
|
54
|
-
|
77
|
+
context "when changes have been made" do
|
78
|
+
let(:config_modified) { true }
|
55
79
|
|
56
|
-
|
80
|
+
before do
|
81
|
+
allow(input).to receive(:gets) { "exit\n" }
|
82
|
+
subject.run
|
83
|
+
end
|
84
|
+
|
85
|
+
["save and exit", "exit without saving"].each do |choice|
|
86
|
+
it "includes '#{choice}'" do
|
87
|
+
expect(output.string).to include(choice)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
57
91
|
end
|
58
92
|
|
59
|
-
it "
|
60
|
-
expect(
|
93
|
+
it "clears the screen" do
|
94
|
+
expect(Kernel).to receive(:system).with("clear")
|
61
95
|
|
62
96
|
subject.run
|
63
97
|
end
|
64
98
|
|
65
99
|
describe "listing" do
|
66
|
-
let(:accounts) { [
|
67
|
-
let(:modified) { {username: "modified@example.com", modified: true} }
|
68
|
-
let(:deleted) { {username: "deleted@example.com", delete: true} }
|
100
|
+
let(:accounts) { [normal_account, modified_account, deleted_account] }
|
69
101
|
|
70
102
|
before { subject.run }
|
71
103
|
|
@@ -90,15 +122,16 @@ describe Imap::Backup::Configuration::Setup do
|
|
90
122
|
|
91
123
|
context "when editing accounts" do
|
92
124
|
let(:account) do
|
93
|
-
instance_double(Imap::Backup::
|
125
|
+
instance_double(Imap::Backup::Setup::Account, run: nil)
|
94
126
|
end
|
127
|
+
let(:config_modified) { true }
|
95
128
|
|
96
129
|
before do
|
97
130
|
allow(input).to receive(:gets).and_return("1\n", "exit\n")
|
98
|
-
allow(Imap::Backup::
|
131
|
+
allow(Imap::Backup::Setup::Asker).to receive(:email).
|
99
132
|
with(no_args) { "new@example.com" }
|
100
|
-
allow(Imap::Backup::
|
101
|
-
with(store,
|
133
|
+
allow(Imap::Backup::Setup::Account).to receive(:new).
|
134
|
+
with(store, normal_account, anything) { account }
|
102
135
|
end
|
103
136
|
|
104
137
|
it "edits the account" do
|
@@ -118,35 +151,36 @@ describe Imap::Backup::Configuration::Setup do
|
|
118
151
|
}
|
119
152
|
end
|
120
153
|
let(:account) do
|
121
|
-
instance_double(Imap::Backup::
|
154
|
+
instance_double(Imap::Backup::Setup::Account, run: nil)
|
122
155
|
end
|
156
|
+
let(:config_modified) { true }
|
123
157
|
let(:added_email) { "new@example.com" }
|
124
158
|
let(:local_path) { "/base/path/new_example.com" }
|
125
159
|
|
126
160
|
before do
|
127
161
|
allow(input).to receive(:gets).and_return("add\n", "exit\n")
|
128
|
-
allow(Imap::Backup::
|
162
|
+
allow(Imap::Backup::Setup::Asker).to receive(:email).
|
129
163
|
with(no_args) { added_email }
|
130
|
-
allow(Imap::Backup::
|
164
|
+
allow(Imap::Backup::Setup::Account).to receive(:new).
|
131
165
|
with(store, anything, anything) { account }
|
132
166
|
|
133
167
|
subject.run
|
134
168
|
end
|
135
169
|
|
136
170
|
it "sets username" do
|
137
|
-
expect(accounts[1]
|
171
|
+
expect(accounts[1].username).to eq(added_email)
|
138
172
|
end
|
139
173
|
|
140
174
|
it "sets blank password" do
|
141
|
-
expect(accounts[1]
|
175
|
+
expect(accounts[1].password).to eq("")
|
142
176
|
end
|
143
177
|
|
144
178
|
it "sets local_path" do
|
145
|
-
expect(accounts[1]
|
179
|
+
expect(accounts[1].local_path).to eq(local_path)
|
146
180
|
end
|
147
181
|
|
148
182
|
it "sets folders" do
|
149
|
-
expect(accounts[1]
|
183
|
+
expect(accounts[1].folders).to eq([])
|
150
184
|
end
|
151
185
|
|
152
186
|
context "when the account is a GMail account" do
|
@@ -154,17 +188,19 @@ describe Imap::Backup::Configuration::Setup do
|
|
154
188
|
let(:local_path) { "/base/path/new_gmail.com" }
|
155
189
|
|
156
190
|
it "sets the server" do
|
157
|
-
expect(accounts[1]
|
191
|
+
expect(accounts[1].server).to eq(gmail_imap_server)
|
158
192
|
end
|
159
193
|
end
|
160
194
|
|
161
195
|
it "doesn't flag the unedited account as modified" do
|
162
|
-
expect(accounts[1]
|
196
|
+
expect(accounts[1].modified?).to be_falsey
|
163
197
|
end
|
164
198
|
end
|
165
199
|
|
166
200
|
describe "logging" do
|
167
201
|
context "when debug logging is disabled" do
|
202
|
+
let(:config_modified) { true }
|
203
|
+
|
168
204
|
before do
|
169
205
|
allow(input).to receive(:gets).and_return("start\n", "exit\n")
|
170
206
|
end
|
@@ -183,7 +219,7 @@ describe Imap::Backup::Configuration::Setup do
|
|
183
219
|
end
|
184
220
|
|
185
221
|
it "updates logging status" do
|
186
|
-
expect(Imap::Backup).to receive(:setup_logging)
|
222
|
+
expect(Imap::Backup::Logger).to receive(:setup_logging)
|
187
223
|
|
188
224
|
subject.run
|
189
225
|
end
|
@@ -192,6 +228,7 @@ describe Imap::Backup::Configuration::Setup do
|
|
192
228
|
|
193
229
|
context "when debug logging is enabled" do
|
194
230
|
let(:debug) { true }
|
231
|
+
let(:config_modified) { true }
|
195
232
|
|
196
233
|
before do
|
197
234
|
allow(input).to receive(:gets).and_return("stop\n", "exit\n")
|
@@ -215,7 +252,7 @@ describe Imap::Backup::Configuration::Setup do
|
|
215
252
|
end
|
216
253
|
|
217
254
|
it "updates logging status" do
|
218
|
-
expect(Imap::Backup).to receive(:setup_logging)
|
255
|
+
expect(Imap::Backup::Logger).to receive(:setup_logging)
|
219
256
|
|
220
257
|
subject.run
|
221
258
|
end
|
@@ -224,6 +261,8 @@ describe Imap::Backup::Configuration::Setup do
|
|
224
261
|
end
|
225
262
|
|
226
263
|
context "when 'save' is selected" do
|
264
|
+
let(:config_modified) { true }
|
265
|
+
|
227
266
|
before do
|
228
267
|
allow(input).to receive(:gets) { "save\n" }
|
229
268
|
end
|
@@ -241,6 +280,8 @@ describe Imap::Backup::Configuration::Setup do
|
|
241
280
|
end
|
242
281
|
|
243
282
|
context "when 'exit without saving' is selected" do
|
283
|
+
let(:config_modified) { true }
|
284
|
+
|
244
285
|
before do
|
245
286
|
allow(input).to receive(:gets) { "exit\n" }
|
246
287
|
end
|
@@ -250,22 +291,10 @@ describe Imap::Backup::Configuration::Setup do
|
|
250
291
|
subject.run
|
251
292
|
end
|
252
293
|
|
253
|
-
|
254
|
-
|
294
|
+
it "doesn't save the configuration" do
|
295
|
+
expect(store).to_not receive(:save)
|
255
296
|
|
256
|
-
|
257
|
-
expect(store).to_not receive(:save)
|
258
|
-
|
259
|
-
subject.run
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
context "when the configuration isn't modified" do
|
264
|
-
it "doesn't save the configuration" do
|
265
|
-
expect(store).to_not receive(:save)
|
266
|
-
|
267
|
-
subject.run
|
268
|
-
end
|
297
|
+
subject.run
|
269
298
|
end
|
270
299
|
end
|
271
300
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imap-backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Yates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- lib/imap/backup/account/connection.rb
|
192
192
|
- lib/imap/backup/account/folder.rb
|
193
193
|
- lib/imap/backup/cli.rb
|
194
|
+
- lib/imap/backup/cli/accounts.rb
|
194
195
|
- lib/imap/backup/cli/backup.rb
|
195
196
|
- lib/imap/backup/cli/folders.rb
|
196
197
|
- lib/imap/backup/cli/helpers.rb
|
@@ -201,18 +202,20 @@ files:
|
|
201
202
|
- lib/imap/backup/cli/utils.rb
|
202
203
|
- lib/imap/backup/client/apple_mail.rb
|
203
204
|
- lib/imap/backup/client/default.rb
|
204
|
-
- lib/imap/backup/configuration
|
205
|
-
- lib/imap/backup/configuration/asker.rb
|
206
|
-
- lib/imap/backup/configuration/connection_tester.rb
|
207
|
-
- lib/imap/backup/configuration/folder_chooser.rb
|
208
|
-
- lib/imap/backup/configuration/list.rb
|
209
|
-
- lib/imap/backup/configuration/setup.rb
|
210
|
-
- lib/imap/backup/configuration/store.rb
|
205
|
+
- lib/imap/backup/configuration.rb
|
211
206
|
- lib/imap/backup/downloader.rb
|
207
|
+
- lib/imap/backup/logger.rb
|
208
|
+
- lib/imap/backup/sanitizer.rb
|
212
209
|
- lib/imap/backup/serializer.rb
|
213
210
|
- lib/imap/backup/serializer/mbox.rb
|
214
211
|
- lib/imap/backup/serializer/mbox_enumerator.rb
|
215
212
|
- lib/imap/backup/serializer/mbox_store.rb
|
213
|
+
- lib/imap/backup/setup.rb
|
214
|
+
- lib/imap/backup/setup/account.rb
|
215
|
+
- lib/imap/backup/setup/asker.rb
|
216
|
+
- lib/imap/backup/setup/connection_tester.rb
|
217
|
+
- lib/imap/backup/setup/folder_chooser.rb
|
218
|
+
- lib/imap/backup/setup/helpers.rb
|
216
219
|
- lib/imap/backup/thunderbird/mailbox_exporter.rb
|
217
220
|
- lib/imap/backup/uploader.rb
|
218
221
|
- lib/imap/backup/utils.rb
|
@@ -228,6 +231,7 @@ files:
|
|
228
231
|
- spec/features/backup_spec.rb
|
229
232
|
- spec/features/helper.rb
|
230
233
|
- spec/features/restore_spec.rb
|
234
|
+
- spec/features/status_spec.rb
|
231
235
|
- spec/features/support/backup_directory.rb
|
232
236
|
- spec/features/support/email_server.rb
|
233
237
|
- spec/features/support/shared/connection_context.rb
|
@@ -237,7 +241,6 @@ files:
|
|
237
241
|
- spec/spec_helper.rb
|
238
242
|
- spec/support/fixtures.rb
|
239
243
|
- spec/support/higline_test_helpers.rb
|
240
|
-
- spec/support/shared_examples/account_flagging.rb
|
241
244
|
- spec/support/silence_logging.rb
|
242
245
|
- spec/unit/email/mboxrd/message_spec.rb
|
243
246
|
- spec/unit/email/provider/apple_mail_spec.rb
|
@@ -247,23 +250,23 @@ files:
|
|
247
250
|
- spec/unit/email/provider_spec.rb
|
248
251
|
- spec/unit/imap/backup/account/connection_spec.rb
|
249
252
|
- spec/unit/imap/backup/account/folder_spec.rb
|
253
|
+
- spec/unit/imap/backup/cli/accounts_spec.rb
|
250
254
|
- spec/unit/imap/backup/cli/local_spec.rb
|
251
255
|
- spec/unit/imap/backup/cli/utils_spec.rb
|
252
256
|
- spec/unit/imap/backup/client/default_spec.rb
|
253
|
-
- spec/unit/imap/backup/
|
254
|
-
- spec/unit/imap/backup/configuration/asker_spec.rb
|
255
|
-
- spec/unit/imap/backup/configuration/connection_tester_spec.rb
|
256
|
-
- spec/unit/imap/backup/configuration/folder_chooser_spec.rb
|
257
|
-
- spec/unit/imap/backup/configuration/list_spec.rb
|
258
|
-
- spec/unit/imap/backup/configuration/setup_spec.rb
|
259
|
-
- spec/unit/imap/backup/configuration/store_spec.rb
|
257
|
+
- spec/unit/imap/backup/configuration_spec.rb
|
260
258
|
- spec/unit/imap/backup/downloader_spec.rb
|
259
|
+
- spec/unit/imap/backup/logger_spec.rb
|
261
260
|
- spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb
|
262
261
|
- spec/unit/imap/backup/serializer/mbox_spec.rb
|
263
262
|
- spec/unit/imap/backup/serializer/mbox_store_spec.rb
|
263
|
+
- spec/unit/imap/backup/setup/account_spec.rb
|
264
|
+
- spec/unit/imap/backup/setup/asker_spec.rb
|
265
|
+
- spec/unit/imap/backup/setup/connection_tester_spec.rb
|
266
|
+
- spec/unit/imap/backup/setup/folder_chooser_spec.rb
|
267
|
+
- spec/unit/imap/backup/setup_spec.rb
|
264
268
|
- spec/unit/imap/backup/uploader_spec.rb
|
265
269
|
- spec/unit/imap/backup/utils_spec.rb
|
266
|
-
- spec/unit/imap/backup_spec.rb
|
267
270
|
homepage: https://github.com/joeyates/imap-backup
|
268
271
|
licenses:
|
269
272
|
- MIT
|
@@ -283,47 +286,47 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
283
286
|
- !ruby/object:Gem::Version
|
284
287
|
version: '0'
|
285
288
|
requirements: []
|
286
|
-
rubygems_version: 3.1.
|
289
|
+
rubygems_version: 3.1.6
|
287
290
|
signing_key:
|
288
291
|
specification_version: 4
|
289
292
|
summary: Backup GMail (or other IMAP) accounts to disk
|
290
293
|
test_files:
|
291
|
-
- spec/
|
292
|
-
- spec/
|
294
|
+
- spec/features/helper.rb
|
295
|
+
- spec/features/support/backup_directory.rb
|
296
|
+
- spec/features/support/shared/message_fixtures.rb
|
297
|
+
- spec/features/support/shared/connection_context.rb
|
298
|
+
- spec/features/support/email_server.rb
|
299
|
+
- spec/features/restore_spec.rb
|
300
|
+
- spec/features/status_spec.rb
|
301
|
+
- spec/features/backup_spec.rb
|
302
|
+
- spec/support/higline_test_helpers.rb
|
303
|
+
- spec/support/fixtures.rb
|
304
|
+
- spec/support/silence_logging.rb
|
305
|
+
- spec/gather_rspec_coverage.rb
|
293
306
|
- spec/unit/email/provider/gmail_spec.rb
|
294
|
-
- spec/unit/email/provider/apple_mail_spec.rb
|
295
307
|
- spec/unit/email/provider/fastmail_spec.rb
|
296
308
|
- spec/unit/email/provider/base_spec.rb
|
297
|
-
- spec/unit/email/
|
309
|
+
- spec/unit/email/provider/apple_mail_spec.rb
|
298
310
|
- spec/unit/email/mboxrd/message_spec.rb
|
299
|
-
- spec/unit/
|
311
|
+
- spec/unit/email/provider_spec.rb
|
300
312
|
- spec/unit/imap/backup/cli/utils_spec.rb
|
313
|
+
- spec/unit/imap/backup/cli/accounts_spec.rb
|
301
314
|
- spec/unit/imap/backup/cli/local_spec.rb
|
315
|
+
- spec/unit/imap/backup/setup/account_spec.rb
|
316
|
+
- spec/unit/imap/backup/setup/connection_tester_spec.rb
|
317
|
+
- spec/unit/imap/backup/setup/folder_chooser_spec.rb
|
318
|
+
- spec/unit/imap/backup/setup/asker_spec.rb
|
319
|
+
- spec/unit/imap/backup/uploader_spec.rb
|
302
320
|
- spec/unit/imap/backup/utils_spec.rb
|
303
|
-
- spec/unit/imap/backup/
|
321
|
+
- spec/unit/imap/backup/configuration_spec.rb
|
322
|
+
- spec/unit/imap/backup/setup_spec.rb
|
323
|
+
- spec/unit/imap/backup/logger_spec.rb
|
324
|
+
- spec/unit/imap/backup/serializer/mbox_store_spec.rb
|
325
|
+
- spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb
|
326
|
+
- spec/unit/imap/backup/serializer/mbox_spec.rb
|
304
327
|
- spec/unit/imap/backup/downloader_spec.rb
|
305
|
-
- spec/unit/imap/backup/configuration/store_spec.rb
|
306
|
-
- spec/unit/imap/backup/configuration/connection_tester_spec.rb
|
307
|
-
- spec/unit/imap/backup/configuration/asker_spec.rb
|
308
|
-
- spec/unit/imap/backup/configuration/setup_spec.rb
|
309
|
-
- spec/unit/imap/backup/configuration/folder_chooser_spec.rb
|
310
|
-
- spec/unit/imap/backup/configuration/account_spec.rb
|
311
|
-
- spec/unit/imap/backup/configuration/list_spec.rb
|
312
328
|
- spec/unit/imap/backup/account/folder_spec.rb
|
313
329
|
- spec/unit/imap/backup/account/connection_spec.rb
|
314
|
-
- spec/unit/imap/backup/
|
315
|
-
- spec/
|
316
|
-
- spec/
|
317
|
-
- spec/unit/imap/backup/uploader_spec.rb
|
318
|
-
- spec/support/fixtures.rb
|
319
|
-
- spec/support/shared_examples/account_flagging.rb
|
320
|
-
- spec/support/higline_test_helpers.rb
|
321
|
-
- spec/support/silence_logging.rb
|
322
|
-
- spec/gather_rspec_coverage.rb
|
323
|
-
- spec/features/backup_spec.rb
|
324
|
-
- spec/features/helper.rb
|
325
|
-
- spec/features/support/backup_directory.rb
|
326
|
-
- spec/features/support/shared/message_fixtures.rb
|
327
|
-
- spec/features/support/shared/connection_context.rb
|
328
|
-
- spec/features/support/email_server.rb
|
329
|
-
- spec/features/restore_spec.rb
|
330
|
+
- spec/unit/imap/backup/client/default_spec.rb
|
331
|
+
- spec/spec_helper.rb
|
332
|
+
- spec/fixtures/connection.yml
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Imap::Backup
|
2
|
-
module Configuration; end
|
3
|
-
|
4
|
-
module Configuration::ConnectionTester
|
5
|
-
def self.test(account)
|
6
|
-
Account::Connection.new(account).client
|
7
|
-
"Connection successful"
|
8
|
-
rescue Net::IMAP::NoResponseError
|
9
|
-
"No response"
|
10
|
-
rescue StandardError => e
|
11
|
-
"Unexpected error: #{e}"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module Imap::Backup
|
2
|
-
module Configuration; end
|
3
|
-
|
4
|
-
class Configuration::List
|
5
|
-
attr_reader :required_accounts
|
6
|
-
|
7
|
-
def initialize(required_accounts = [])
|
8
|
-
@required_accounts = required_accounts
|
9
|
-
end
|
10
|
-
|
11
|
-
def setup_logging
|
12
|
-
return if !config_exists?
|
13
|
-
|
14
|
-
Imap::Backup.setup_logging config
|
15
|
-
Net::IMAP.debug = config.debug?
|
16
|
-
end
|
17
|
-
|
18
|
-
def each_connection
|
19
|
-
accounts.each do |account|
|
20
|
-
connection = Account::Connection.new(account)
|
21
|
-
yield connection
|
22
|
-
connection.disconnect
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def accounts
|
27
|
-
@accounts ||=
|
28
|
-
if required_accounts.empty?
|
29
|
-
config.accounts
|
30
|
-
else
|
31
|
-
config.accounts.select do |account|
|
32
|
-
required_accounts.include?(account[:username])
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def config
|
40
|
-
return @config if @config
|
41
|
-
|
42
|
-
if !config_exists?
|
43
|
-
path = Configuration::Store.default_pathname
|
44
|
-
raise ConfigurationNotFound, "Configuration file '#{path}' not found"
|
45
|
-
end
|
46
|
-
@config = Configuration::Store.new
|
47
|
-
end
|
48
|
-
|
49
|
-
def config_exists?
|
50
|
-
Configuration::Store.exist?
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
shared_examples "it flags the account as modified" do
|
2
|
-
it "flags that the account has changed" do
|
3
|
-
expect(account[:modified]).to be_truthy
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
shared_examples "it doesn't flag the account as modified" do
|
8
|
-
it "does not flag that the account has changed" do
|
9
|
-
expect(account[:modified]).to be_falsey
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
shared_examples "it flags the account to be deleted" do
|
14
|
-
it "flags that the account is to be deleted" do
|
15
|
-
expect(account[:delete]).to be_truthy
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
shared_examples "it doesn't flag the account to be deleted" do
|
20
|
-
it "does not flags that the account is to be deleted" do
|
21
|
-
expect(account[:delete]).to be_falsey
|
22
|
-
end
|
23
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
describe Imap::Backup::Configuration::List do
|
2
|
-
subject { described_class.new }
|
3
|
-
|
4
|
-
let(:accounts) do
|
5
|
-
[
|
6
|
-
{username: "a1@example.com"},
|
7
|
-
{username: "a2@example.com"}
|
8
|
-
]
|
9
|
-
end
|
10
|
-
let(:store) do
|
11
|
-
instance_double(Imap::Backup::Configuration::Store, accounts: accounts)
|
12
|
-
end
|
13
|
-
let(:exists) { true }
|
14
|
-
let(:connection1) do
|
15
|
-
instance_double(Imap::Backup::Account::Connection, disconnect: nil)
|
16
|
-
end
|
17
|
-
let(:connection2) do
|
18
|
-
instance_double(Imap::Backup::Account::Connection, disconnect: nil)
|
19
|
-
end
|
20
|
-
|
21
|
-
before do
|
22
|
-
allow(Imap::Backup::Configuration::Store).to receive(:new) { store }
|
23
|
-
allow(Imap::Backup::Configuration::Store).
|
24
|
-
to receive(:exist?) { exists }
|
25
|
-
allow(Imap::Backup::Account::Connection).
|
26
|
-
to receive(:new).with(accounts[0]) { connection1 }
|
27
|
-
allow(Imap::Backup::Account::Connection).
|
28
|
-
to receive(:new).with(accounts[1]) { connection2 }
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#setup_logging" do
|
32
|
-
let(:config_exists) { true }
|
33
|
-
|
34
|
-
before do
|
35
|
-
allow(Imap::Backup::Configuration::Store).
|
36
|
-
to receive(:exist?) { config_exists }
|
37
|
-
allow(Imap::Backup).to receive(:setup_logging)
|
38
|
-
allow(store).to receive(:debug?)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "sets global logging level" do
|
42
|
-
expect(Imap::Backup).to receive(:setup_logging).with(store)
|
43
|
-
|
44
|
-
subject.setup_logging
|
45
|
-
end
|
46
|
-
|
47
|
-
context "without a config" do
|
48
|
-
let(:config_exists) { false }
|
49
|
-
|
50
|
-
it "does nothing" do
|
51
|
-
expect(Imap::Backup).to_not receive(:setup_logging).with(store)
|
52
|
-
|
53
|
-
subject.setup_logging
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "#each_connection" do
|
59
|
-
specify "calls the block with each account's connection" do
|
60
|
-
connections = []
|
61
|
-
|
62
|
-
subject.each_connection { |a| connections << a }
|
63
|
-
|
64
|
-
expect(connections).to eq([connection1, connection2])
|
65
|
-
end
|
66
|
-
|
67
|
-
context "with account parameter" do
|
68
|
-
subject { described_class.new(["a2@example.com"]) }
|
69
|
-
|
70
|
-
it "only creates requested accounts" do
|
71
|
-
connections = []
|
72
|
-
|
73
|
-
subject.each_connection { |a| connections << a }
|
74
|
-
|
75
|
-
expect(connections).to eq([connection2])
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context "when the configuration file is missing" do
|
80
|
-
let(:exists) { false }
|
81
|
-
|
82
|
-
it "fails" do
|
83
|
-
expect do
|
84
|
-
subject.each_connection {}
|
85
|
-
end.to raise_error(Imap::Backup::ConfigurationNotFound, /not found/)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require "ostruct"
|
2
|
-
require "imap/backup"
|
3
|
-
|
4
|
-
describe Imap::Backup do
|
5
|
-
describe ".setup_logging" do
|
6
|
-
let!(:previous) { described_class.logger.level }
|
7
|
-
|
8
|
-
before { described_class.setup_logging(config) }
|
9
|
-
|
10
|
-
after { described_class.logger.level = previous }
|
11
|
-
|
12
|
-
context "when config.debug?" do
|
13
|
-
let(:config) { OpenStruct.new(debug?: true) }
|
14
|
-
|
15
|
-
it "sets logger level to debug" do
|
16
|
-
expect(described_class.logger.level).to eq(::Logger::Severity::DEBUG)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when not config.debug?" do
|
21
|
-
let(:config) { OpenStruct.new(debug?: false) }
|
22
|
-
|
23
|
-
it "sets logger level to debug" do
|
24
|
-
expect(described_class.logger.level).to eq(::Logger::Severity::ERROR)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|