use of com.orm.androrm.impl.migration.ModelWithRelation in project androrm by androrm.
the class RenameModelMigrationTest method testRenameRelation.
public void testRenameRelation() {
Migrator<NewModelWithRelation> migrator = new Migrator<NewModelWithRelation>(NewModelWithRelation.class);
assertTrue(mHelper.hasRelationTable(ModelWithRelation.class));
assertTrue(mHelper.tableExists("emptymodel_modelwithrelation"));
ModelWithRelation model1 = new ModelWithRelation();
model1.save(getContext());
EmptyModel empty = new EmptyModel();
empty.save(getContext());
model1.addRelation(empty);
model1.save(getContext());
assertEquals(1, model1.getRelations(getContext()).count());
assertEquals(0, NewModelWithRelation.objects(getContext()).count());
migrator.renameModel("ModelWithRelation", NewModelWithRelation.class);
migrator.migrate(getContext());
NewModelWithRelation one = NewModelWithRelation.objects(getContext()).get(1);
assertEquals(1, one.getRelations(getContext()).count());
assertTrue(mHelper.hasRelationTable(NewModelWithRelation.class));
assertFalse(mHelper.hasRelationTable(ModelWithRelation.class));
assertFalse(mHelper.tableExists("emptymodel_modelwithrelation"));
Filter filter = new Filter();
filter.is("mModel", "newmodelwithrelation").is("mAction", "rename_relation").is("mValue", "emptymodel_modelwithrelation");
assertEquals(1, Migration.objects(getContext()).filter(filter).count());
}
Aggregations