From 77e444b13b554c9637144de347859baa8688cfbe Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 23 Aug 2019 22:57:16 +0200 Subject: [PATCH] Verify that INTEGER PRIMARY KEY accepts absent values Verifies that #112 is fixed --- .../parsed_sql/moor_files_integration_test.dart | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/moor/test/parsed_sql/moor_files_integration_test.dart b/moor/test/parsed_sql/moor_files_integration_test.dart index d29a6953..4ea88f04 100644 --- a/moor/test/parsed_sql/moor_files_integration_test.dart +++ b/moor/test/parsed_sql/moor_files_integration_test.dart @@ -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', [])); + }); }