-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DB] prepackaged dbs now can run migrations to get to current version…
… when db version is 0 but we set our db version to something higher.
- Loading branch information
Showing
6 changed files
with
81 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 35 additions & 6 deletions
41
tests/src/androidTest/java/com/dbflow5/prepackaged/PrepackagedDBTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,50 @@ | ||
package com.dbflow5.prepackaged | ||
|
||
import com.dbflow5.BaseUnitTest | ||
import com.dbflow5.config.databaseForTable | ||
import com.dbflow5.DBFlowInstrumentedTestRule | ||
import com.dbflow5.DemoApp | ||
import com.dbflow5.config.database | ||
import com.dbflow5.database.AndroidSQLiteOpenHelper | ||
import com.dbflow5.query.select | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
/** | ||
* Description: Asserts our prepackaged DB loads. | ||
*/ | ||
class PrepackagedDBTest : BaseUnitTest() { | ||
class PrepackagedDBTest { | ||
|
||
@JvmField | ||
@Rule | ||
var dblflowTestRule = DBFlowInstrumentedTestRule.create { | ||
database<PrepackagedDB>({ | ||
databaseName("prepackaged") | ||
}, AndroidSQLiteOpenHelper.createHelperCreator(DemoApp.context)) | ||
database<MigratedPrepackagedDB>({ | ||
databaseName("prepackaged_2") | ||
}, AndroidSQLiteOpenHelper.createHelperCreator(DemoApp.context)) | ||
} | ||
|
||
@Test | ||
fun assertWeCanLoadFromDB() { | ||
databaseForTable<Dog> { dbFlowDatabase -> | ||
val list = (select from Dog::class).queryList(dbFlowDatabase) | ||
assertTrue(!list.isEmpty()) | ||
database<PrepackagedDB> { db -> | ||
val list = (select from Dog::class).queryList(db) | ||
assertTrue(list.isNotEmpty()) | ||
} | ||
} | ||
|
||
@Test | ||
fun assertWeCanLoadFromDBPostMigrate() { | ||
database<MigratedPrepackagedDB> { db -> | ||
val list = (select from Dog2::class).queryList(db) | ||
assertTrue(list.isNotEmpty()) | ||
|
||
val newData = (select | ||
from Dog2::class | ||
where Dog2_Table.breed.eq("NewBreed") | ||
and Dog2_Table.newField.eq("New Field Data")) | ||
.querySingle(db) | ||
assertTrue(newData != null) | ||
} | ||
} | ||
} |
Binary file not shown.