Search in sources :

Example 1 with NewModelWithRelation

use of com.orm.androrm.impl.migration.NewModelWithRelation 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());
}
Also used : NewModelWithRelation(com.orm.androrm.impl.migration.NewModelWithRelation) Filter(com.orm.androrm.Filter) NewModelWithRelation(com.orm.androrm.impl.migration.NewModelWithRelation) ModelWithRelation(com.orm.androrm.impl.migration.ModelWithRelation) EmptyModel(com.orm.androrm.impl.migration.EmptyModel) NewEmptyModel(com.orm.androrm.impl.migration.NewEmptyModel) Migrator(com.orm.androrm.migration.Migrator)

Aggregations

Filter (com.orm.androrm.Filter)1 EmptyModel (com.orm.androrm.impl.migration.EmptyModel)1 ModelWithRelation (com.orm.androrm.impl.migration.ModelWithRelation)1 NewEmptyModel (com.orm.androrm.impl.migration.NewEmptyModel)1 NewModelWithRelation (com.orm.androrm.impl.migration.NewModelWithRelation)1 Migrator (com.orm.androrm.migration.Migrator)1