AbstractChangeNotes: Fix auto-rebuilding conditional

This was not caught in I265ef862 because we didn't have any explicit
tests for the createWithAutoRebuildingDisabled method. Add a
regression test that would have caught it.

Change-Id: I1867f6332821c8a3e5a05f5bb48de2166cc47426
This commit is contained in:
Dave Borowitz
2016-05-16 17:30:19 -04:00
parent 1766703b05
commit bfa6eb342f
2 changed files with 25 additions and 1 deletions

View File

@@ -579,6 +579,30 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
assertThat(notes.getChange().getSubject()).isEqualTo(PushOneCommit.SUBJECT);
}
@Test
public void createWithAutoRebuildingDisabled() throws Exception {
ReviewDb oldDb = db;
setNotesMigration(true, true);
PushOneCommit.Result r = createChange();
Change.Id id = r.getPatchSetId().getParentKey();
ChangeNotes oldNotes = notesFactory.create(db, project, id);
// Make a ReviewDb change behind NoteDb's back.
Change c = oldDb.changes().get(id);
assertThat(c.getTopic()).isNull();
String topic = name("a-topic");
c.setTopic(topic);
oldDb.changes().update(Collections.singleton(c));
c = oldDb.changes().get(c.getId());
ChangeNotes newNotes =
notesFactory.createWithAutoRebuildingDisabled(c, null);
assertThat(newNotes.getChange().getTopic()).isNotEqualTo(topic);
assertThat(newNotes.getChange().getTopic())
.isEqualTo(oldNotes.getChange().getTopic());
}
private void setInvalidNoteDbState(Change.Id id) throws Exception {
ReviewDb db = unwrapDb();
Change c = db.changes().get(id);

View File

@@ -124,7 +124,7 @@ public abstract class AbstractChangeNotes<T> {
}
boolean read = args.migration.readChanges();
boolean readOrWrite = read || args.migration.writeChanges();
if (!readOrWrite || !autoRebuild) {
if (!readOrWrite && !autoRebuild) {
loadDefaults();
return self();
}