Fix not being able to re-add account previously removed from the engine.

This commit is contained in:
Michael James Gratton 2018-06-17 17:56:06 +10:00
parent fa3b8fa53f
commit f79f5ee255
2 changed files with 59 additions and 6 deletions

View file

@ -418,12 +418,14 @@ public class Geary.Engine : BaseObject {
check_opened();
// Ensure account is closed.
if (account_instances.has_key(account.id) && account_instances.get(account.id).is_open()) {
throw new EngineError.CLOSE_REQUIRED("Account %s must be closed before removal",
account.id);
if (this.account_instances.has_key(account.id) &&
this.account_instances.get(account.id).is_open()) {
throw new EngineError.CLOSE_REQUIRED(
"Account %s must be closed before removal", account.id
);
}
if (accounts.has_key(account.id)) {
if (this.accounts.has_key(account.id)) {
account.untrusted_host.disconnect(on_untrusted_host);
account.disconnect_endpoints();
@ -433,7 +435,8 @@ public class Geary.Engine : BaseObject {
account_unavailable(account);
// 2. Remove the account data from the engine.
account_instances.unset(account.id);
this.accounts.unset(account.id);
this.account_instances.unset(account.id);
}
}

View file

@ -15,8 +15,11 @@ class Geary.EngineTest : TestCase {
public EngineTest() {
base("Geary.EngineTest");
add_test("create_orphan_account", create_orphan_account);
add_test("add_account", add_account);
add_test("remove_account", remove_account);
add_test("re_add_account", re_add_account);
add_test("create_orphan_account_with_legacy", create_orphan_account_with_legacy);
add_test("create_orphan_account", create_orphan_account);
}
~EngineTest() {
@ -61,6 +64,53 @@ class Geary.EngineTest : TestCase {
}
}
public void add_account() throws GLib.Error {
AccountInformation info = this.engine.create_orphan_account(
new MockServiceInformation(),
new MockServiceInformation()
);
assert_false(this.engine.has_account(info.id));
this.engine.add_account(info);
assert_true(this.engine.has_account(info.id), "Account not added");
try {
this.engine.add_account(info);
assert_not_reached();
} catch (GLib.Error err) {
// expected
}
}
public void remove_account() throws GLib.Error {
AccountInformation info = this.engine.create_orphan_account(
new MockServiceInformation(),
new MockServiceInformation()
);
this.engine.add_account(info);
assert_true(this.engine.has_account(info.id));
this.engine.remove_account(info);
assert_false(this.engine.has_account(info.id), "Account not rmoeved");
// Should not throw an error
this.engine.remove_account(info);
}
public void re_add_account() throws GLib.Error {
AccountInformation info = this.engine.create_orphan_account(
new MockServiceInformation(),
new MockServiceInformation()
);
assert_false(this.engine.has_account(info.id));
this.engine.add_account(info);
this.engine.remove_account(info);
this.engine.add_account(info);
assert_true(this.engine.has_account(info.id));
}
public void create_orphan_account() throws Error {
try {
AccountInformation info = this.engine.create_orphan_account(