imap-backup 6.0.0.rc2 → 6.0.0
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 +4 -4
- data/imap-backup.gemspec +5 -1
- data/lib/cli_coverage.rb +11 -11
- data/lib/email/provider/base.rb +2 -0
- data/lib/email/provider/unknown.rb +2 -0
- data/lib/email/provider.rb +2 -0
- data/lib/imap/backup/account/connection/backup_folders.rb +27 -0
- data/lib/imap/backup/account/connection/client_factory.rb +54 -0
- data/lib/imap/backup/account/connection/folder_names.rb +26 -0
- data/lib/imap/backup/account/connection.rb +11 -95
- data/lib/imap/backup/account/folder.rb +9 -6
- data/lib/imap/backup/account.rb +3 -5
- data/lib/imap/backup/cli/backup.rb +1 -3
- data/lib/imap/backup/cli/helpers.rb +24 -22
- data/lib/imap/backup/cli/local.rb +20 -13
- data/lib/imap/backup/cli/migrate.rb +4 -10
- data/lib/imap/backup/cli/restore.rb +8 -7
- data/lib/imap/backup/cli/setup.rb +10 -8
- data/lib/imap/backup/cli/stats.rb +78 -0
- data/lib/imap/backup/cli/status.rb +2 -2
- data/lib/imap/backup/cli/utils.rb +4 -6
- data/lib/imap/backup/cli.rb +24 -3
- data/lib/imap/backup/configuration.rb +9 -11
- data/lib/imap/backup/downloader.rb +48 -30
- data/lib/imap/backup/migrator.rb +5 -5
- data/lib/imap/backup/sanitizer.rb +3 -2
- data/lib/imap/backup/serializer/appender.rb +49 -0
- data/lib/imap/backup/serializer/message_enumerator.rb +29 -0
- data/lib/imap/backup/serializer/unused_name_finder.rb +27 -0
- data/lib/imap/backup/serializer.rb +24 -78
- data/lib/imap/backup/setup/account/header.rb +75 -0
- data/lib/imap/backup/setup/account.rb +14 -91
- data/lib/imap/backup/setup/asker.rb +4 -15
- data/lib/imap/backup/setup/backup_path.rb +41 -0
- data/lib/imap/backup/setup/email.rb +45 -0
- data/lib/imap/backup/setup/folder_chooser.rb +3 -3
- data/lib/imap/backup/setup/helpers.rb +1 -1
- data/lib/imap/backup/setup.rb +5 -4
- data/lib/imap/backup/thunderbird/mailbox_exporter.rb +39 -20
- data/lib/imap/backup/uploader.rb +46 -8
- data/lib/imap/backup/utils.rb +1 -1
- data/lib/imap/backup/version.rb +1 -1
- data/lib/imap/backup.rb +0 -1
- metadata +31 -134
- data/spec/features/backup_spec.rb +0 -100
- data/spec/features/configuration/minimal_configuration.rb +0 -15
- data/spec/features/configuration/missing_configuration.rb +0 -14
- data/spec/features/folders_spec.rb +0 -36
- data/spec/features/helper.rb +0 -2
- data/spec/features/local/list_accounts_spec.rb +0 -12
- data/spec/features/local/list_emails_spec.rb +0 -21
- data/spec/features/local/list_folders_spec.rb +0 -21
- data/spec/features/local/show_an_email_spec.rb +0 -34
- data/spec/features/migrate_spec.rb +0 -35
- data/spec/features/remote/list_account_folders_spec.rb +0 -16
- data/spec/features/restore_spec.rb +0 -162
- data/spec/features/status_spec.rb +0 -43
- data/spec/features/support/aruba.rb +0 -78
- data/spec/features/support/backup_directory.rb +0 -43
- data/spec/features/support/email_server.rb +0 -110
- data/spec/features/support/shared/connection_context.rb +0 -14
- data/spec/features/support/shared/message_fixtures.rb +0 -16
- data/spec/fixtures/connection.yml +0 -7
- data/spec/spec_helper.rb +0 -15
- data/spec/support/fixtures.rb +0 -11
- data/spec/support/higline_test_helpers.rb +0 -8
- data/spec/support/silence_logging.rb +0 -7
- data/spec/unit/email/mboxrd/message_spec.rb +0 -177
- data/spec/unit/email/provider/apple_mail_spec.rb +0 -7
- data/spec/unit/email/provider/base_spec.rb +0 -11
- data/spec/unit/email/provider/fastmail_spec.rb +0 -7
- data/spec/unit/email/provider/gmail_spec.rb +0 -7
- data/spec/unit/email/provider_spec.rb +0 -27
- data/spec/unit/imap/backup/account/connection_spec.rb +0 -433
- data/spec/unit/imap/backup/account/folder_spec.rb +0 -261
- data/spec/unit/imap/backup/account_spec.rb +0 -246
- data/spec/unit/imap/backup/cli/accounts_spec.rb +0 -58
- data/spec/unit/imap/backup/cli/backup_spec.rb +0 -19
- data/spec/unit/imap/backup/cli/folders_spec.rb +0 -39
- data/spec/unit/imap/backup/cli/helpers_spec.rb +0 -87
- data/spec/unit/imap/backup/cli/local_spec.rb +0 -100
- data/spec/unit/imap/backup/cli/migrate_spec.rb +0 -80
- data/spec/unit/imap/backup/cli/restore_spec.rb +0 -67
- data/spec/unit/imap/backup/cli/setup_spec.rb +0 -17
- data/spec/unit/imap/backup/cli/utils_spec.rb +0 -125
- data/spec/unit/imap/backup/cli_spec.rb +0 -93
- data/spec/unit/imap/backup/client/apple_mail_spec.rb +0 -9
- data/spec/unit/imap/backup/client/default_spec.rb +0 -22
- data/spec/unit/imap/backup/configuration_spec.rb +0 -238
- data/spec/unit/imap/backup/downloader_spec.rb +0 -96
- data/spec/unit/imap/backup/logger_spec.rb +0 -48
- data/spec/unit/imap/backup/migrator_spec.rb +0 -58
- data/spec/unit/imap/backup/sanitizer_spec.rb +0 -42
- data/spec/unit/imap/backup/serializer/directory_spec.rb +0 -37
- data/spec/unit/imap/backup/serializer/imap_spec.rb +0 -218
- data/spec/unit/imap/backup/serializer/mbox_enumerator_spec.rb +0 -45
- data/spec/unit/imap/backup/serializer/mbox_spec.rb +0 -101
- data/spec/unit/imap/backup/serializer_spec.rb +0 -296
- data/spec/unit/imap/backup/setup/account_spec.rb +0 -461
- data/spec/unit/imap/backup/setup/asker_spec.rb +0 -137
- data/spec/unit/imap/backup/setup/connection_tester_spec.rb +0 -51
- data/spec/unit/imap/backup/setup/folder_chooser_spec.rb +0 -146
- data/spec/unit/imap/backup/setup/helpers_spec.rb +0 -15
- data/spec/unit/imap/backup/setup_spec.rb +0 -301
- data/spec/unit/imap/backup/thunderbird/mailbox_exporter_spec.rb +0 -116
- data/spec/unit/imap/backup/uploader_spec.rb +0 -54
- data/spec/unit/imap/backup/utils_spec.rb +0 -92
- data/spec/unit/retry_on_error_spec.rb +0 -34
|
@@ -1,461 +0,0 @@
|
|
|
1
|
-
describe Imap::Backup::Setup::Account do
|
|
2
|
-
ACCOUNT = "account".freeze
|
|
3
|
-
GMAIL_IMAP_SERVER = "imap.gmail.com".freeze
|
|
4
|
-
HIGHLINE = "highline".freeze
|
|
5
|
-
CONFIG = "config".freeze
|
|
6
|
-
|
|
7
|
-
subject { described_class.new(config, account, highline) }
|
|
8
|
-
|
|
9
|
-
let(:account) do
|
|
10
|
-
instance_double(
|
|
11
|
-
Imap::Backup::Account,
|
|
12
|
-
username: existing_email,
|
|
13
|
-
password: existing_password,
|
|
14
|
-
local_path: "/backup/path",
|
|
15
|
-
folders: [{name: "my_folder"}],
|
|
16
|
-
multi_fetch_size: multi_fetch_size,
|
|
17
|
-
server: current_server,
|
|
18
|
-
connection_options: connection_options,
|
|
19
|
-
modified?: false
|
|
20
|
-
)
|
|
21
|
-
end
|
|
22
|
-
let(:account1) do
|
|
23
|
-
instance_double(
|
|
24
|
-
Imap::Backup::Account,
|
|
25
|
-
username: other_email,
|
|
26
|
-
local_path: other_existing_path
|
|
27
|
-
)
|
|
28
|
-
end
|
|
29
|
-
let(:accounts) { [account, account1] }
|
|
30
|
-
let(:existing_email) { "user@example.com" }
|
|
31
|
-
let(:new_email) { "foo@example.com" }
|
|
32
|
-
let(:existing_password) { "password" }
|
|
33
|
-
let(:other_email) { "other@example.com" }
|
|
34
|
-
let(:other_existing_path) { "/other/existing/path" }
|
|
35
|
-
let(:multi_fetch_size) { 1 }
|
|
36
|
-
let(:current_server) { "imap.example.com" }
|
|
37
|
-
let(:connection_options) { nil }
|
|
38
|
-
|
|
39
|
-
let(:highline) { HIGHLINE }
|
|
40
|
-
let(:config) { CONFIG }
|
|
41
|
-
|
|
42
|
-
describe "#initialize" do
|
|
43
|
-
[:config, :account, :highline].each do |param|
|
|
44
|
-
it "expects #{param}" do
|
|
45
|
-
expect(subject.send(param)).to eq(send(param))
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
describe "#run" do
|
|
51
|
-
let(:highline_menu_class) do
|
|
52
|
-
Class.new do
|
|
53
|
-
attr_reader :choices
|
|
54
|
-
attr_accessor :header
|
|
55
|
-
|
|
56
|
-
def initialize
|
|
57
|
-
@choices = {}
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def choice(name, &block)
|
|
61
|
-
choices[name] = block
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def hidden(name, &block)
|
|
65
|
-
choices[name] = block
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
let(:highline) { instance_double(HighLine) }
|
|
71
|
-
let(:menu) { highline_menu_class.new }
|
|
72
|
-
let(:config) do
|
|
73
|
-
instance_double(Imap::Backup::Configuration, accounts: accounts)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
before do
|
|
77
|
-
allow(Kernel).to receive(:system)
|
|
78
|
-
allow(Kernel).to receive(:puts)
|
|
79
|
-
allow(highline).to receive(:choose) do |&block|
|
|
80
|
-
block.call(menu)
|
|
81
|
-
throw :done
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
describe "preparation" do
|
|
86
|
-
it "clears the screen" do
|
|
87
|
-
expect(Kernel).to receive(:system).with("clear")
|
|
88
|
-
|
|
89
|
-
subject.run
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
describe "menu" do
|
|
93
|
-
it "shows the menu" do
|
|
94
|
-
expect(highline).to receive(:choose)
|
|
95
|
-
|
|
96
|
-
subject.run
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
describe "menu" do
|
|
102
|
-
[
|
|
103
|
-
"modify email",
|
|
104
|
-
"modify password",
|
|
105
|
-
"modify backup path",
|
|
106
|
-
"choose backup folders",
|
|
107
|
-
"modify multi-fetch size (number of emails to fetch at a time)",
|
|
108
|
-
"modify server",
|
|
109
|
-
"modify connection options",
|
|
110
|
-
"test connection",
|
|
111
|
-
"delete",
|
|
112
|
-
"(q) return to main menu",
|
|
113
|
-
"quit" # TODO: quit is hidden
|
|
114
|
-
].each do |item|
|
|
115
|
-
before { subject.run }
|
|
116
|
-
|
|
117
|
-
it "has a '#{item}' item" do
|
|
118
|
-
expect(menu.choices).to include(item)
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
describe "account details" do
|
|
124
|
-
[
|
|
125
|
-
["email", /email\s+user@example.com/],
|
|
126
|
-
["password", /password\s+x+/],
|
|
127
|
-
["path", %r(path\s+/backup/path)],
|
|
128
|
-
["folders", /folders\s+my_folder/],
|
|
129
|
-
["server", /server\s+imap.example.com/]
|
|
130
|
-
].each do |attribute, value|
|
|
131
|
-
before { subject.run }
|
|
132
|
-
|
|
133
|
-
it "shows the #{attribute}" do
|
|
134
|
-
expect(menu.header).to match(value)
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
context "with no password" do
|
|
139
|
-
let(:existing_password) { "" }
|
|
140
|
-
|
|
141
|
-
before { subject.run }
|
|
142
|
-
|
|
143
|
-
it "indicates that a password is not set" do
|
|
144
|
-
expect(menu.header).to match(/^password\s+\(unset\)/)
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
context "with multi_fetch_size" do
|
|
149
|
-
let(:multi_fetch_size) { 4 }
|
|
150
|
-
|
|
151
|
-
it "shows the size" do
|
|
152
|
-
expect(menu.header).to match(/^multi-fetch\s+4/)
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
context "with connection_options" do
|
|
157
|
-
let(:connection_options) { {some: "option"} }
|
|
158
|
-
|
|
159
|
-
it "shows the options" do
|
|
160
|
-
expect(menu.header).to match(/^connection options\s+'{"some":"option"}'/)
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
describe "choosing 'modify email'" do
|
|
166
|
-
before do
|
|
167
|
-
allow(account).to receive(:"username=")
|
|
168
|
-
allow(account).to receive(:"server=")
|
|
169
|
-
allow(Imap::Backup::Setup::Asker).
|
|
170
|
-
to receive(:email) { new_email }
|
|
171
|
-
subject.run
|
|
172
|
-
menu.choices["modify email"].call
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
context "when the server is blank" do
|
|
176
|
-
[
|
|
177
|
-
["GMail", "foo@gmail.com", GMAIL_IMAP_SERVER],
|
|
178
|
-
["Fastmail", "bar@fastmail.fm", "imap.fastmail.com"],
|
|
179
|
-
["Fastmail", "bar@fastmail.com", "imap.fastmail.com"]
|
|
180
|
-
].each do |service, email, expected|
|
|
181
|
-
context service do
|
|
182
|
-
let(:new_email) { email }
|
|
183
|
-
|
|
184
|
-
context "with nil" do
|
|
185
|
-
let(:current_server) { nil }
|
|
186
|
-
|
|
187
|
-
it "sets a default server" do
|
|
188
|
-
expect(account).to have_received(:"server=").with(expected)
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
context "with an empty string" do
|
|
193
|
-
let(:current_server) { "" }
|
|
194
|
-
|
|
195
|
-
it "sets a default server" do
|
|
196
|
-
expect(account).to have_received(:"server=").with(expected)
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
context "when the domain is unrecognized" do
|
|
203
|
-
let(:current_server) { nil }
|
|
204
|
-
let(:provider) do
|
|
205
|
-
instance_double(Email::Provider, provider: :default)
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
before do
|
|
209
|
-
allow(Email::Provider).to receive(:for_address) { provider }
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
it "does not set a default server" do
|
|
213
|
-
expect(account).to_not have_received(:"server=")
|
|
214
|
-
end
|
|
215
|
-
end
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
context "when the email is new" do
|
|
219
|
-
it "modifies the email address" do
|
|
220
|
-
expect(account).to have_received(:"username=").with(new_email)
|
|
221
|
-
end
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
context "when the email already exists" do
|
|
225
|
-
let(:new_email) { other_email }
|
|
226
|
-
|
|
227
|
-
it "indicates the error" do
|
|
228
|
-
expect(Kernel).to have_received(:puts).
|
|
229
|
-
with("There is already an account set up with that email address")
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
it "doesn't set the email" do
|
|
233
|
-
expect(account.username).to eq(existing_email)
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
describe "choosing 'modify password'" do
|
|
239
|
-
let(:new_password) { "new_password" }
|
|
240
|
-
|
|
241
|
-
before do
|
|
242
|
-
allow(account).to receive(:"password=")
|
|
243
|
-
allow(Imap::Backup::Setup::Asker).
|
|
244
|
-
to receive(:password) { new_password }
|
|
245
|
-
subject.run
|
|
246
|
-
menu.choices["modify password"].call
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
context "when the user enters a password" do
|
|
250
|
-
it "updates the password" do
|
|
251
|
-
expect(account).to have_received(:"password=").with(new_password)
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
context "when the user cancels" do
|
|
256
|
-
let(:new_password) { nil }
|
|
257
|
-
|
|
258
|
-
it "does nothing" do
|
|
259
|
-
expect(account.password).to eq(existing_password)
|
|
260
|
-
end
|
|
261
|
-
end
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
describe "choosing 'modify backup path'" do
|
|
265
|
-
let(:new_backup_path) { "/new/path" }
|
|
266
|
-
|
|
267
|
-
before do
|
|
268
|
-
allow(account).to receive(:"local_path=")
|
|
269
|
-
@validator = nil
|
|
270
|
-
allow(
|
|
271
|
-
Imap::Backup::Setup::Asker
|
|
272
|
-
).to receive(:backup_path) do |_path, validator|
|
|
273
|
-
@validator = validator
|
|
274
|
-
new_backup_path
|
|
275
|
-
end
|
|
276
|
-
subject.run
|
|
277
|
-
menu.choices["modify backup path"].call
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
it "updates the path" do
|
|
281
|
-
expect(account).to have_received(:"local_path=").with(new_backup_path)
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
context "when the path is not used by other backups" do
|
|
285
|
-
it "is accepts it" do
|
|
286
|
-
# rubocop:disable RSpec/InstanceVariable
|
|
287
|
-
expect(@validator.call("/unknown/path")).to be_truthy
|
|
288
|
-
# rubocop:enable RSpec/InstanceVariable
|
|
289
|
-
end
|
|
290
|
-
end
|
|
291
|
-
|
|
292
|
-
context "when the path is used by other backups" do
|
|
293
|
-
it "fails validation" do
|
|
294
|
-
# rubocop:disable RSpec/InstanceVariable
|
|
295
|
-
expect(@validator.call(other_existing_path)).to be_falsey
|
|
296
|
-
# rubocop:enable RSpec/InstanceVariable
|
|
297
|
-
end
|
|
298
|
-
end
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
describe "choosing 'choose backup folders'" do
|
|
302
|
-
let(:chooser) do
|
|
303
|
-
instance_double(Imap::Backup::Setup::FolderChooser, run: nil)
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
before do
|
|
307
|
-
allow(Imap::Backup::Setup::FolderChooser).
|
|
308
|
-
to receive(:new) { chooser }
|
|
309
|
-
subject.run
|
|
310
|
-
menu.choices["choose backup folders"].call
|
|
311
|
-
end
|
|
312
|
-
|
|
313
|
-
it "edits folders" do
|
|
314
|
-
expect(chooser).to have_received(:run)
|
|
315
|
-
end
|
|
316
|
-
end
|
|
317
|
-
|
|
318
|
-
describe "choosing 'modify multi-fetch size'" do
|
|
319
|
-
let(:supplied) { "10" }
|
|
320
|
-
|
|
321
|
-
before do
|
|
322
|
-
allow(account).to receive(:multi_fetch_size=)
|
|
323
|
-
allow(highline).to receive(:ask).with("size: ") { supplied }
|
|
324
|
-
|
|
325
|
-
subject.run
|
|
326
|
-
menu.choices[
|
|
327
|
-
"modify multi-fetch size (number of emails to fetch at a time)"
|
|
328
|
-
].call
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
it "sets the multi-fetch size" do
|
|
332
|
-
expect(account).to have_received(:multi_fetch_size=).with(10)
|
|
333
|
-
end
|
|
334
|
-
|
|
335
|
-
context "when the supplied value is not a number" do
|
|
336
|
-
let(:supplied) { "wrong!" }
|
|
337
|
-
|
|
338
|
-
it "does nothing" do
|
|
339
|
-
expect(account).to_not have_received(:multi_fetch_size=)
|
|
340
|
-
end
|
|
341
|
-
end
|
|
342
|
-
|
|
343
|
-
context "when the supplied value is not a positive number" do
|
|
344
|
-
let(:supplied) { "0" }
|
|
345
|
-
|
|
346
|
-
it "does nothing" do
|
|
347
|
-
expect(account).to_not have_received(:multi_fetch_size=)
|
|
348
|
-
end
|
|
349
|
-
end
|
|
350
|
-
end
|
|
351
|
-
|
|
352
|
-
describe "choosing 'modify server'" do
|
|
353
|
-
let(:server) { "server" }
|
|
354
|
-
|
|
355
|
-
before do
|
|
356
|
-
allow(account).to receive(:"server=")
|
|
357
|
-
allow(highline).to receive(:ask).with("server: ") { server }
|
|
358
|
-
|
|
359
|
-
subject.run
|
|
360
|
-
|
|
361
|
-
menu.choices["modify server"].call
|
|
362
|
-
end
|
|
363
|
-
|
|
364
|
-
it "updates the server" do
|
|
365
|
-
expect(account).to have_received(:"server=").with(server)
|
|
366
|
-
end
|
|
367
|
-
end
|
|
368
|
-
|
|
369
|
-
describe "choosing 'modify connection options'" do
|
|
370
|
-
context "when the JSON is well formed" do
|
|
371
|
-
let(:json) { "{}" }
|
|
372
|
-
|
|
373
|
-
before do
|
|
374
|
-
allow(highline).to receive(:ask).with("connections options (as JSON): ") { json }
|
|
375
|
-
allow(account).to receive(:"connection_options=")
|
|
376
|
-
|
|
377
|
-
subject.run
|
|
378
|
-
|
|
379
|
-
menu.choices["modify connection options"].call
|
|
380
|
-
end
|
|
381
|
-
|
|
382
|
-
it "updates the connection options" do
|
|
383
|
-
expect(account).to have_received(:"connection_options=").with(json)
|
|
384
|
-
end
|
|
385
|
-
end
|
|
386
|
-
|
|
387
|
-
context "when the JSON is malformed" do
|
|
388
|
-
before do
|
|
389
|
-
allow(highline).to receive(:ask).with("connections options (as JSON): ") { "xx" }
|
|
390
|
-
allow(account).to receive(:"connection_options=").and_raise(JSON::ParserError)
|
|
391
|
-
allow(highline).to receive(:ask).with("Press a key ")
|
|
392
|
-
|
|
393
|
-
subject.run
|
|
394
|
-
|
|
395
|
-
menu.choices["modify connection options"].call
|
|
396
|
-
end
|
|
397
|
-
|
|
398
|
-
it "does not fail" do
|
|
399
|
-
subject.run
|
|
400
|
-
end
|
|
401
|
-
|
|
402
|
-
it "reports the problem" do
|
|
403
|
-
expect(Kernel).to have_received(:puts).
|
|
404
|
-
with(/Malformed/)
|
|
405
|
-
end
|
|
406
|
-
end
|
|
407
|
-
end
|
|
408
|
-
|
|
409
|
-
describe "choosing 'test connection'" do
|
|
410
|
-
let(:connection_tester) do
|
|
411
|
-
instance_double(
|
|
412
|
-
Imap::Backup::Setup::ConnectionTester,
|
|
413
|
-
test: "All fine"
|
|
414
|
-
)
|
|
415
|
-
end
|
|
416
|
-
|
|
417
|
-
before do
|
|
418
|
-
allow(Imap::Backup::Setup::ConnectionTester).
|
|
419
|
-
to receive(:new) { connection_tester }
|
|
420
|
-
allow(highline).to receive(:ask)
|
|
421
|
-
subject.run
|
|
422
|
-
menu.choices["test connection"].call
|
|
423
|
-
end
|
|
424
|
-
|
|
425
|
-
it "tests the connection" do
|
|
426
|
-
expect(connection_tester).to have_received(:test)
|
|
427
|
-
end
|
|
428
|
-
end
|
|
429
|
-
|
|
430
|
-
describe "choosing 'delete'" do
|
|
431
|
-
let(:confirmed) { true }
|
|
432
|
-
|
|
433
|
-
before do
|
|
434
|
-
allow(account).to receive(:mark_for_deletion)
|
|
435
|
-
allow(highline).to receive(:agree) { confirmed }
|
|
436
|
-
subject.run
|
|
437
|
-
catch :done do
|
|
438
|
-
menu.choices["delete"].call
|
|
439
|
-
end
|
|
440
|
-
end
|
|
441
|
-
|
|
442
|
-
it "asks for confirmation" do
|
|
443
|
-
expect(highline).to have_received(:agree)
|
|
444
|
-
end
|
|
445
|
-
|
|
446
|
-
context "when the user confirms deletion" do
|
|
447
|
-
it "flags the account to be deleted" do
|
|
448
|
-
expect(account).to have_received(:mark_for_deletion)
|
|
449
|
-
end
|
|
450
|
-
end
|
|
451
|
-
|
|
452
|
-
context "without confirmation" do
|
|
453
|
-
let(:confirmed) { false }
|
|
454
|
-
|
|
455
|
-
it "doesn't flag the account to be deleted" do
|
|
456
|
-
expect(account).to_not have_received(:mark_for_deletion)
|
|
457
|
-
end
|
|
458
|
-
end
|
|
459
|
-
end
|
|
460
|
-
end
|
|
461
|
-
end
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
module Imap::Backup
|
|
2
|
-
describe Setup::Asker do
|
|
3
|
-
subject { described_class.new(highline) }
|
|
4
|
-
|
|
5
|
-
let(:highline) { double }
|
|
6
|
-
let(:query) do
|
|
7
|
-
instance_double(
|
|
8
|
-
HighLine::Question,
|
|
9
|
-
"default=": nil,
|
|
10
|
-
"readline=": nil,
|
|
11
|
-
"validate=": nil,
|
|
12
|
-
"responses": {},
|
|
13
|
-
"echo=": nil
|
|
14
|
-
)
|
|
15
|
-
end
|
|
16
|
-
let(:answer) { "foo" }
|
|
17
|
-
|
|
18
|
-
before do
|
|
19
|
-
allow(Setup).to receive(:highline) { highline }
|
|
20
|
-
allow(highline).to receive(:ask) do |&b|
|
|
21
|
-
b.call query
|
|
22
|
-
answer
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
[
|
|
27
|
-
[:email, [], "email address"],
|
|
28
|
-
[:password, [], "password"],
|
|
29
|
-
[:backup_path, %w(x y), "backup directory"]
|
|
30
|
-
].each do |method, params, prompt|
|
|
31
|
-
context ".#{method}" do
|
|
32
|
-
it "asks for input" do
|
|
33
|
-
expect(highline).to receive(:ask).with("#{prompt}: ")
|
|
34
|
-
|
|
35
|
-
described_class.send(method, *params)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "returns the answer" do
|
|
39
|
-
expect(described_class.send(method, *params)).to eq(answer)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
describe "#initialize" do
|
|
45
|
-
it "requires 1 parameter" do
|
|
46
|
-
expect do
|
|
47
|
-
described_class.new
|
|
48
|
-
end.to raise_error(ArgumentError, /wrong number/)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "expects a higline" do
|
|
52
|
-
expect(subject.highline).to eq(highline)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
describe "#email" do
|
|
57
|
-
let(:email) { "email@example.com" }
|
|
58
|
-
let(:answer) { email }
|
|
59
|
-
|
|
60
|
-
it "asks for an email" do
|
|
61
|
-
expect(highline).to receive(:ask).with(/email/)
|
|
62
|
-
|
|
63
|
-
subject.email
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "returns the address" do
|
|
67
|
-
expect(subject.email).to eq(email)
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
describe "#password" do
|
|
72
|
-
let(:password1) { "password" }
|
|
73
|
-
let(:password2) { "password" }
|
|
74
|
-
let(:answers) { [true, false] }
|
|
75
|
-
|
|
76
|
-
before do
|
|
77
|
-
i = 0
|
|
78
|
-
allow(highline).to receive(:ask).with("password: ") { password1 }
|
|
79
|
-
allow(highline).to receive(:ask).with("repeat password: ") { password2 }
|
|
80
|
-
allow(highline).to receive(:agree) do
|
|
81
|
-
answer = answers[i]
|
|
82
|
-
i += 1
|
|
83
|
-
answer
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it "asks for a password" do
|
|
88
|
-
expect(highline).to receive(:ask).with("password: ")
|
|
89
|
-
|
|
90
|
-
subject.password
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it "asks for confirmation" do
|
|
94
|
-
expect(highline).to receive(:ask).with("repeat password: ")
|
|
95
|
-
|
|
96
|
-
subject.password
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "returns the password" do
|
|
100
|
-
expect(subject.password).to eq(password1)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
context "with different answers" do
|
|
104
|
-
let(:password2) { "secret" }
|
|
105
|
-
|
|
106
|
-
it "asks to continue" do
|
|
107
|
-
expect(highline).to receive(:agree).
|
|
108
|
-
at_least(:once).with(/Continue\?/)
|
|
109
|
-
|
|
110
|
-
subject.password
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
describe "#backup_path" do
|
|
116
|
-
let(:path) { "/path" }
|
|
117
|
-
let(:answer) { path }
|
|
118
|
-
|
|
119
|
-
before do
|
|
120
|
-
allow(highline).to receive(:ask) do |&b|
|
|
121
|
-
b.call query
|
|
122
|
-
path
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
it "asks for a directory" do
|
|
127
|
-
expect(highline).to receive(:ask).with(/directory/)
|
|
128
|
-
|
|
129
|
-
subject.backup_path("", //)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it "returns the path" do
|
|
133
|
-
expect(subject.backup_path("", //)).to eq(path)
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
describe Imap::Backup::Setup::ConnectionTester do
|
|
2
|
-
describe "#test" do
|
|
3
|
-
subject { described_class.new("foo") }
|
|
4
|
-
|
|
5
|
-
let(:connection) do
|
|
6
|
-
instance_double(Imap::Backup::Account::Connection, client: nil)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
before do
|
|
10
|
-
allow(Imap::Backup::Account::Connection).to receive(:new) { connection }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "tries to connect" do
|
|
14
|
-
expect(connection).to receive(:client)
|
|
15
|
-
|
|
16
|
-
subject.test
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe "success" do
|
|
20
|
-
it "returns success" do
|
|
21
|
-
expect(subject.test).to match(/successful/)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe "failure" do
|
|
26
|
-
before do
|
|
27
|
-
allow(connection).to receive(:client).and_raise(error)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
context "with no connection" do
|
|
31
|
-
let(:error) do
|
|
32
|
-
data = OpenStruct.new(text: "bar")
|
|
33
|
-
response = OpenStruct.new(data: data)
|
|
34
|
-
Net::IMAP::NoResponseError.new(response)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "returns error" do
|
|
38
|
-
expect(subject.test).to match(/no response/i)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
context "when caused by other errors" do
|
|
43
|
-
let(:error) { "Error" }
|
|
44
|
-
|
|
45
|
-
it "returns error" do
|
|
46
|
-
expect(subject.test).to match(/unexpected error/i)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|