imap-backup 4.0.5 → 4.1.2
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/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
data/lib/retry_on_error.rb
CHANGED
@@ -58,6 +58,7 @@ RSpec.describe "backup", type: :feature, docker: true do
|
|
58
58
|
email3
|
59
59
|
original_folder_uid_validity
|
60
60
|
connection.run_backup
|
61
|
+
connection.disconnect
|
61
62
|
server_rename_folder folder, new_name
|
62
63
|
end
|
63
64
|
let(:renamed_folder) { "#{folder}.#{original_folder_uid_validity}" }
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "features/helper"
|
2
|
+
require "imap/backup/cli/status"
|
3
|
+
|
4
|
+
RSpec.describe "status", type: :feature, docker: true do
|
5
|
+
include_context "imap-backup connection"
|
6
|
+
include_context "message-fixtures"
|
7
|
+
|
8
|
+
context "when there are non-backed-up messages" do
|
9
|
+
let(:options) do
|
10
|
+
{accounts: "address@example.org"}
|
11
|
+
end
|
12
|
+
let(:folder) { "my-stuff" }
|
13
|
+
let(:backup_folders) { [{name: folder}] }
|
14
|
+
let(:email1) { send_email folder, msg1 }
|
15
|
+
let(:output) { StringIO.new }
|
16
|
+
|
17
|
+
before do
|
18
|
+
allow(Imap::Backup::CLI::Accounts).to receive(:new) { [account] }
|
19
|
+
server_create_folder folder
|
20
|
+
email1
|
21
|
+
end
|
22
|
+
|
23
|
+
around do |example|
|
24
|
+
stdout = $stdout
|
25
|
+
$stdout = output
|
26
|
+
example.run
|
27
|
+
$stdout = stdout
|
28
|
+
end
|
29
|
+
|
30
|
+
after do
|
31
|
+
FileUtils.rm_rf local_backup_path
|
32
|
+
delete_emails folder
|
33
|
+
server_delete_folder folder
|
34
|
+
connection.disconnect
|
35
|
+
end
|
36
|
+
|
37
|
+
it "prints the number" do
|
38
|
+
Imap::Backup::CLI::Status.new(options).run
|
39
|
+
|
40
|
+
expect(output.string).to eq("address@example.org\nmy-stuff: 1\n")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -63,11 +63,14 @@ module EmailServerHelpers
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def server_folders
|
66
|
-
root_info = imap.list("", "")[0]
|
67
|
-
root = root_info.name
|
68
66
|
imap.list(root, "*")
|
69
67
|
end
|
70
68
|
|
69
|
+
def root
|
70
|
+
root_info = imap.list("", "")[0]
|
71
|
+
root_info.name
|
72
|
+
end
|
73
|
+
|
71
74
|
def server_create_folder(folder)
|
72
75
|
imap.create(folder)
|
73
76
|
imap.disconnect
|
@@ -2,11 +2,13 @@ shared_context "imap-backup connection" do
|
|
2
2
|
let(:local_backup_path) { Dir.mktmpdir(nil, "tmp") }
|
3
3
|
let(:default_connection) { fixture("connection") }
|
4
4
|
let(:backup_folders) { nil }
|
5
|
-
let(:
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
let(:account) do
|
6
|
+
Imap::Backup::Account.new(
|
7
|
+
default_connection.merge(
|
8
|
+
local_path: local_backup_path,
|
9
|
+
folders: backup_folders
|
10
|
+
)
|
9
11
|
)
|
10
12
|
end
|
11
|
-
let(:connection) { Imap::Backup::Account::Connection.new(
|
13
|
+
let(:connection) { Imap::Backup::Account::Connection.new(account) }
|
12
14
|
end
|
@@ -2,7 +2,7 @@ module HighLineTestHelpers
|
|
2
2
|
def prepare_highline
|
3
3
|
@input = instance_double(IO, eof?: false, gets: "q\n")
|
4
4
|
@output = StringIO.new
|
5
|
-
Imap::Backup::
|
5
|
+
Imap::Backup::Setup.highline = HighLine.new(@input, @output)
|
6
6
|
[@input, @output]
|
7
7
|
end
|
8
8
|
end
|
@@ -17,10 +17,10 @@ describe Email::Provider do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
context "with unknown providers" do
|
20
|
-
it "returns
|
20
|
+
it "returns the Unknown provider" do
|
21
21
|
result = described_class.for_address("foo@unknown.com")
|
22
22
|
|
23
|
-
expect(result).to be_a(Email::Provider::
|
23
|
+
expect(result).to be_a(Email::Provider::Unknown)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -5,6 +5,7 @@ describe Imap::Backup::Account::Connection do
|
|
5
5
|
FOLDER_CONFIG = {name: BACKUP_FOLDER}.freeze
|
6
6
|
FOLDER_NAME = "my_folder".freeze
|
7
7
|
GMAIL_IMAP_SERVER = "imap.gmail.com".freeze
|
8
|
+
IMAP_FOLDER = "imap_folder".freeze
|
8
9
|
LOCAL_PATH = "local_path".freeze
|
9
10
|
LOCAL_UID = "local_uid".freeze
|
10
11
|
PASSWORD = "secret".freeze
|
@@ -12,7 +13,7 @@ describe Imap::Backup::Account::Connection do
|
|
12
13
|
SERVER = "imap.example.com".freeze
|
13
14
|
USERNAME = "username@example.com".freeze
|
14
15
|
|
15
|
-
subject { described_class.new(
|
16
|
+
subject { described_class.new(account) }
|
16
17
|
|
17
18
|
let(:client) do
|
18
19
|
instance_double(
|
@@ -20,14 +21,16 @@ describe Imap::Backup::Account::Connection do
|
|
20
21
|
)
|
21
22
|
end
|
22
23
|
let(:imap_folders) { [] }
|
23
|
-
let(:
|
24
|
-
|
24
|
+
let(:account) do
|
25
|
+
instance_double(
|
26
|
+
Imap::Backup::Account,
|
25
27
|
username: USERNAME,
|
26
28
|
password: PASSWORD,
|
27
29
|
local_path: LOCAL_PATH,
|
28
30
|
folders: config_folders,
|
29
|
-
server: server
|
30
|
-
|
31
|
+
server: server,
|
32
|
+
connection_options: nil
|
33
|
+
)
|
31
34
|
end
|
32
35
|
let(:config_folders) { [FOLDER_CONFIG] }
|
33
36
|
let(:root_info) do
|
@@ -59,21 +62,10 @@ describe Imap::Backup::Account::Connection do
|
|
59
62
|
end
|
60
63
|
|
61
64
|
describe "#initialize" do
|
62
|
-
[
|
63
|
-
[:username, USERNAME],
|
64
|
-
[:password, PASSWORD],
|
65
|
-
[:local_path, LOCAL_PATH],
|
66
|
-
[:server, SERVER]
|
67
|
-
].each do |attr, expected|
|
68
|
-
it "expects #{attr}" do
|
69
|
-
expect(subject.public_send(attr)).to eq(expected)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
65
|
it "creates the path" do
|
74
66
|
expect(Imap::Backup::Utils).to receive(:make_folder)
|
75
67
|
|
76
|
-
subject
|
68
|
+
subject
|
77
69
|
end
|
78
70
|
end
|
79
71
|
|
@@ -110,19 +102,23 @@ describe Imap::Backup::Account::Connection do
|
|
110
102
|
end
|
111
103
|
end
|
112
104
|
|
113
|
-
describe "#
|
105
|
+
describe "#folder_names" do
|
114
106
|
let(:imap_folders) do
|
115
|
-
[
|
107
|
+
[IMAP_FOLDER]
|
116
108
|
end
|
117
109
|
|
118
110
|
it "returns the list of folders" do
|
119
|
-
expect(subject.
|
111
|
+
expect(subject.folder_names).to eq([IMAP_FOLDER])
|
120
112
|
end
|
121
113
|
end
|
122
114
|
|
123
115
|
describe "#status" do
|
124
116
|
let(:folder) do
|
125
|
-
instance_double(
|
117
|
+
instance_double(
|
118
|
+
Imap::Backup::Account::Folder,
|
119
|
+
uids: [remote_uid],
|
120
|
+
name: IMAP_FOLDER
|
121
|
+
)
|
126
122
|
end
|
127
123
|
let(:remote_uid) { "remote_uid" }
|
128
124
|
|
@@ -132,7 +128,7 @@ describe Imap::Backup::Account::Connection do
|
|
132
128
|
end
|
133
129
|
|
134
130
|
it "returns the names of folders" do
|
135
|
-
expect(subject.status[0][:name]).to eq(
|
131
|
+
expect(subject.status[0][:name]).to eq(IMAP_FOLDER)
|
136
132
|
end
|
137
133
|
|
138
134
|
it "returns local message uids" do
|
@@ -148,7 +144,7 @@ describe Imap::Backup::Account::Connection do
|
|
148
144
|
let(:folder) do
|
149
145
|
instance_double(
|
150
146
|
Imap::Backup::Account::Folder,
|
151
|
-
name:
|
147
|
+
name: IMAP_FOLDER,
|
152
148
|
exist?: exists,
|
153
149
|
uid_validity: uid_validity
|
154
150
|
)
|
@@ -159,11 +155,11 @@ describe Imap::Backup::Account::Connection do
|
|
159
155
|
|
160
156
|
before do
|
161
157
|
allow(Imap::Backup::Downloader).
|
162
|
-
to receive(:new).with(folder, serializer) { downloader }
|
158
|
+
to receive(:new).with(folder, serializer, anything) { downloader }
|
163
159
|
allow(Imap::Backup::Account::Folder).to receive(:new).
|
164
160
|
with(subject, BACKUP_FOLDER) { folder }
|
165
161
|
allow(Imap::Backup::Serializer::Mbox).to receive(:new).
|
166
|
-
with(LOCAL_PATH,
|
162
|
+
with(LOCAL_PATH, IMAP_FOLDER) { serializer }
|
167
163
|
end
|
168
164
|
|
169
165
|
context "with supplied config_folders" do
|
@@ -257,7 +253,7 @@ describe Imap::Backup::Account::Connection do
|
|
257
253
|
Imap::Backup::Account::Folder,
|
258
254
|
create: nil,
|
259
255
|
uids: uids,
|
260
|
-
name:
|
256
|
+
name: IMAP_FOLDER,
|
261
257
|
uid_validity: uid_validity
|
262
258
|
)
|
263
259
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "imap/backup/cli/accounts"
|
2
|
+
|
3
|
+
describe Imap::Backup::CLI::Accounts do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
let(:accounts) { [account1, account2] }
|
7
|
+
let(:account1) do
|
8
|
+
instance_double(
|
9
|
+
Imap::Backup::Account,
|
10
|
+
username: "a1@example.com"
|
11
|
+
)
|
12
|
+
end
|
13
|
+
let(:account2) do
|
14
|
+
instance_double(
|
15
|
+
Imap::Backup::Account,
|
16
|
+
username: "a2@example.com"
|
17
|
+
)
|
18
|
+
end
|
19
|
+
let(:store) do
|
20
|
+
instance_double(Imap::Backup::Configuration, accounts: accounts)
|
21
|
+
end
|
22
|
+
let(:exists) { true }
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(Imap::Backup::Configuration).to receive(:new) { store }
|
26
|
+
allow(Imap::Backup::Configuration).
|
27
|
+
to receive(:exist?) { exists }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#each" do
|
31
|
+
specify "calls the block with each account" do
|
32
|
+
result = subject.map { |a| a }
|
33
|
+
|
34
|
+
expect(result).to eq(accounts)
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when the configuration file is missing" do
|
38
|
+
let(:exists) { false }
|
39
|
+
|
40
|
+
it "fails" do
|
41
|
+
expect do
|
42
|
+
subject.each {}
|
43
|
+
end.to raise_error(Imap::Backup::ConfigurationNotFound, /not found/)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,8 +1,18 @@
|
|
1
1
|
describe Imap::Backup::CLI::Local do
|
2
|
-
let(:
|
3
|
-
instance_double(
|
2
|
+
let(:accounts) do
|
3
|
+
instance_double(
|
4
|
+
Imap::Backup::CLI::Accounts,
|
5
|
+
find: ->(&block) { [account].find { |a| block.call(a) } }
|
6
|
+
)
|
7
|
+
end
|
8
|
+
let(:account) do
|
9
|
+
instance_double(
|
10
|
+
Imap::Backup::Account,
|
11
|
+
username: email,
|
12
|
+
marked_for_deletion?: false,
|
13
|
+
modified?: false
|
14
|
+
)
|
4
15
|
end
|
5
|
-
let(:accounts) { [{username: email}] }
|
6
16
|
let(:connection) do
|
7
17
|
instance_double(
|
8
18
|
Imap::Backup::Account::Connection,
|
@@ -31,9 +41,10 @@ describe Imap::Backup::CLI::Local do
|
|
31
41
|
|
32
42
|
before do
|
33
43
|
allow(Kernel).to receive(:puts)
|
34
|
-
allow(Imap::Backup::
|
44
|
+
allow(Imap::Backup::CLI::Accounts).to receive(:new) { accounts }
|
35
45
|
allow(Imap::Backup::Account::Connection).to receive(:new) { connection }
|
36
46
|
allow(Mail).to receive(:new) { mail }
|
47
|
+
allow(accounts).to receive(:each).and_yield(account)
|
37
48
|
end
|
38
49
|
|
39
50
|
describe "accounts" do
|
@@ -1,50 +1,62 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
1
|
+
module Imap::Backup
|
2
|
+
describe CLI::Utils do
|
3
|
+
let(:accounts) do
|
4
|
+
instance_double(
|
5
|
+
CLI::Accounts,
|
6
|
+
find: ->(&block) { [account].find { |a| block.call(a) } }
|
7
|
+
)
|
8
|
+
end
|
9
|
+
let(:account) { instance_double(Account, username: email) }
|
10
|
+
let(:connection) do
|
11
|
+
instance_double(
|
12
|
+
Account::Connection,
|
13
|
+
account: account,
|
14
|
+
backup_folders: [folder]
|
15
|
+
)
|
16
|
+
end
|
17
|
+
let(:account) do
|
18
|
+
instance_double(
|
19
|
+
Account,
|
20
|
+
local_path: "path"
|
21
|
+
)
|
22
|
+
end
|
23
|
+
let(:folder) do
|
24
|
+
instance_double(
|
25
|
+
Account::Folder,
|
26
|
+
exist?: true,
|
27
|
+
name: "name",
|
28
|
+
uid_validity: "uid_validity",
|
29
|
+
uids: %w(123 456)
|
30
|
+
)
|
31
|
+
end
|
32
|
+
let(:serializer) do
|
33
|
+
instance_double(
|
34
|
+
Serializer::Mbox,
|
35
|
+
uids: %w(123 789),
|
36
|
+
apply_uid_validity: nil,
|
37
|
+
save: nil
|
38
|
+
)
|
39
|
+
end
|
40
|
+
let(:email) { "foo@example.com" }
|
31
41
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
42
|
+
before do
|
43
|
+
allow(CLI::Accounts).to receive(:new) { accounts }
|
44
|
+
allow(Account::Connection).to receive(:new) { connection }
|
45
|
+
allow(Serializer::Mbox).to receive(:new) { serializer }
|
46
|
+
end
|
36
47
|
|
37
|
-
|
38
|
-
|
39
|
-
|
48
|
+
describe "ignore_history" do
|
49
|
+
it "ensures the local UID validity matches the server" do
|
50
|
+
subject.ignore_history(email)
|
40
51
|
|
41
|
-
|
42
|
-
|
52
|
+
expect(serializer).to have_received(:apply_uid_validity).with("uid_validity")
|
53
|
+
end
|
43
54
|
|
44
|
-
|
45
|
-
|
55
|
+
it "fills the local folder with fake emails" do
|
56
|
+
subject.ignore_history(email)
|
46
57
|
|
47
|
-
|
58
|
+
expect(serializer).to have_received(:save).with("456", /From: fake@email.com/)
|
59
|
+
end
|
48
60
|
end
|
49
61
|
end
|
50
62
|
end
|
@@ -3,19 +3,21 @@ require "os"
|
|
3
3
|
|
4
4
|
# rubocop:disable RSpec/PredicateMatcher
|
5
5
|
|
6
|
-
describe Imap::Backup::Configuration
|
6
|
+
describe Imap::Backup::Configuration do
|
7
7
|
let(:directory) { "/base/path" }
|
8
8
|
let(:file_path) { File.join(directory, "/config.json") }
|
9
9
|
let(:file_exists) { true }
|
10
10
|
let(:directory_exists) { true }
|
11
|
-
let(:data) { {debug: debug, accounts: accounts} }
|
12
11
|
let(:debug) { true }
|
13
|
-
let(:accounts) { [] }
|
14
12
|
let(:configuration) { data.to_json }
|
13
|
+
let(:data) { {debug: debug, accounts: accounts.map(&:to_h)} }
|
14
|
+
let(:accounts) { [account1, account2] }
|
15
|
+
let(:account1) { Imap::Backup::Account.new({username: "username1"}) }
|
16
|
+
let(:account2) { Imap::Backup::Account.new({username: "username2"}) }
|
15
17
|
|
16
18
|
before do
|
17
19
|
stub_const(
|
18
|
-
"Imap::Backup::Configuration::
|
20
|
+
"Imap::Backup::Configuration::CONFIGURATION_DIRECTORY", directory
|
19
21
|
)
|
20
22
|
allow(File).to receive(:directory?).with(directory) { directory_exists }
|
21
23
|
allow(File).to receive(:exist?).and_call_original
|
@@ -48,8 +50,8 @@ describe Imap::Backup::Configuration::Store do
|
|
48
50
|
end
|
49
51
|
|
50
52
|
describe "#modified?" do
|
51
|
-
context "with accounts
|
52
|
-
|
53
|
+
context "with modified accounts" do
|
54
|
+
before { subject.accounts[0].username = "changed" }
|
53
55
|
|
54
56
|
it "is true" do
|
55
57
|
expect(subject.modified?).to be_truthy
|
@@ -57,7 +59,7 @@ describe Imap::Backup::Configuration::Store do
|
|
57
59
|
end
|
58
60
|
|
59
61
|
context "with accounts flagged 'delete'" do
|
60
|
-
|
62
|
+
before { subject.accounts[0].mark_for_deletion! }
|
61
63
|
|
62
64
|
it "is true" do
|
63
65
|
expect(subject.modified?).to be_truthy
|
@@ -65,8 +67,6 @@ describe Imap::Backup::Configuration::Store do
|
|
65
67
|
end
|
66
68
|
|
67
69
|
context "without accounts flagged 'modified'" do
|
68
|
-
let(:accounts) { [{name: "foo"}] }
|
69
|
-
|
70
70
|
it "is false" do
|
71
71
|
expect(subject.modified?).to be_falsey
|
72
72
|
end
|
@@ -156,19 +156,14 @@ describe Imap::Backup::Configuration::Store do
|
|
156
156
|
subject.save
|
157
157
|
end
|
158
158
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
before { subject.save }
|
163
|
-
|
164
|
-
it "skips the 'modified' flag" do
|
165
|
-
expected = Marshal.load(Marshal.dump(data))
|
166
|
-
expected[:accounts][0].delete(:modified)
|
159
|
+
it "uses the Account#to_h method" do
|
160
|
+
allow(subject.accounts[0]).to receive(:to_h) { "Account1" }
|
161
|
+
allow(subject.accounts[1]).to receive(:to_h) { "Account2" }
|
167
162
|
|
168
|
-
|
163
|
+
expect(JSON).to receive(:pretty_generate).
|
164
|
+
with(hash_including({accounts: ["Account1", "Account2"]}))
|
169
165
|
|
170
|
-
|
171
|
-
end
|
166
|
+
subject.save
|
172
167
|
end
|
173
168
|
|
174
169
|
context "when accounts are to be deleted" do
|
@@ -179,11 +174,15 @@ describe Imap::Backup::Configuration::Store do
|
|
179
174
|
]
|
180
175
|
end
|
181
176
|
|
182
|
-
|
183
|
-
|
184
|
-
|
177
|
+
before do
|
178
|
+
allow(subject.accounts[0]).to receive(:to_h) { "Account1" }
|
179
|
+
allow(subject.accounts[1]).to receive(:to_h) { "Account2" }
|
180
|
+
subject.accounts[0].mark_for_deletion!
|
181
|
+
end
|
185
182
|
|
186
|
-
|
183
|
+
it "does not save them" do
|
184
|
+
expect(JSON).to receive(:pretty_generate).
|
185
|
+
with(hash_including({accounts: ["Account2"]}))
|
187
186
|
|
188
187
|
subject.save
|
189
188
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "net/imap"
|
2
|
+
|
3
|
+
module Imap::Backup
|
4
|
+
describe Logger do
|
5
|
+
describe ".setup_logging" do
|
6
|
+
let(:config) { instance_double(Configuration, debug?: debug) }
|
7
|
+
|
8
|
+
around do |example|
|
9
|
+
logger_previous = described_class.logger.level
|
10
|
+
net_imap_previous = Net::IMAP.debug
|
11
|
+
described_class.logger.level = 42
|
12
|
+
Net::IMAP.debug = 42
|
13
|
+
example.run
|
14
|
+
Net::IMAP.debug = net_imap_previous
|
15
|
+
described_class.logger.level = logger_previous
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
allow(Configuration).to receive(:new) { config }
|
20
|
+
described_class.setup_logging
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when config.debug?" do
|
24
|
+
let(:debug) { true }
|
25
|
+
|
26
|
+
it "sets logger level to debug" do
|
27
|
+
expect(described_class.logger.level).to eq(::Logger::Severity::DEBUG)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "sets the Net::IMAP debug flag" do
|
31
|
+
expect(Net::IMAP.debug).to be_a(TrueClass)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when not config.debug?" do
|
36
|
+
let(:debug) { false }
|
37
|
+
|
38
|
+
it "sets logger level to error" do
|
39
|
+
expect(described_class.logger.level).to eq(::Logger::Severity::ERROR)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "sets the Net::IMAP debug flag" do
|
43
|
+
expect(Net::IMAP.debug).to be_a(FalseClass)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|