Verify that INTEGER PRIMARY KEY accepts absent values

Verifies that #112 is fixed
This commit is contained in:
Simon Binder 2019-08-23 22:57:16 +02:00
parent 397d3f2383
commit 77e444b13b
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 14 additions and 0 deletions

View File

@ -19,6 +19,10 @@ const _createConfig = 'CREATE TABLE IF NOT EXISTS config ('
'config_key VARCHAR not null primary key, '
'config_value VARCHAR);';
const _createMyTable = 'CREATE TABLE IF NOT EXISTS mytable ('
'someid INTEGER NOT NULL PRIMARY KEY, '
'sometext VARCHAR);';
void main() {
// see ../data/tables/tables.moor
test('creates tables as specified in .moor files', () async {
@ -31,6 +35,7 @@ void main() {
verify(mockQueryExecutor.call(_createWithDefaults, []));
verify(mockQueryExecutor.call(_createWithConstraints, []));
verify(mockQueryExecutor.call(_createConfig, []));
verify(mockQueryExecutor.call(_createMyTable, []));
});
test('infers primary keys correctly', () async {
@ -40,4 +45,13 @@ void main() {
expect(db.withDefaults.primaryKey, isEmpty);
expect(db.config.primaryKey, [db.config.configKey]);
});
test('supports absent values for primary key integers', () async {
// regression test for #112: https://github.com/simolus3/moor/issues/112
final mock = MockExecutor();
final db = CustomTablesDb(mock);
await db.into(db.mytable).insert(const MytableCompanion());
verify(mock.runInsert('INSERT INTO mytable DEFAULT VALUES', []));
});
}