Update existing tests to respect transactions

This commit is contained in:
Simon Binder 2019-03-10 12:06:02 +01:00
parent 049a970b37
commit b5237bf36b
No known key found for this signature in database
GPG Key ID: B807FDF954BA00CF
7 changed files with 13 additions and 11 deletions

View File

@ -117,7 +117,10 @@ mixin QueryEngine on DatabaseConnectionUser {
final affectedRows =
executor.doWhenOpened((_) => executor.runUpdate(query, mappedArgs));
await streamQueries.handleTableUpdates(updates.map((t) => t.$tableName).toSet());
if (updates != null) {
await streamQueries
.handleTableUpdates(updates.map((t) => t.$tableName).toSet());
}
return affectedRows;
}

View File

@ -25,7 +25,7 @@ class DeleteStatement<UserTable> extends Query<UserTable, dynamic> {
await ctx.database.executor.runDelete(ctx.sql, ctx.boundVariables);
if (rows > 0) {
database.markTableUpdated(table.$tableName);
database.markTablesUpdated({table.$tableName});
}
return rows;
});

View File

@ -44,7 +44,7 @@ class InsertStatement<DataClass> {
await database.executor.doWhenOpened((e) async {
await database.executor.runInsert(ctx.sql, ctx.boundVariables);
database.markTableUpdated(table.$tableName);
database.markTablesUpdated({table.$tableName});
});
}

View File

@ -39,7 +39,7 @@ class UpdateStatement<T, D> extends Query<T, D> {
});
if (rows > 0) {
database.markTableUpdated(table.$tableName);
database.markTablesUpdated({table.$tableName});
}
return rows;

View File

@ -49,7 +49,7 @@ void main() {
await db.delete(db.users).go();
verify(streamQueries.handleTableUpdates('users'));
verify(streamQueries.handleTableUpdates({'users'}));
});
test('are not issued when no data was changed', () async {

View File

@ -24,7 +24,7 @@ void main() {
test('streams fetch when the underlying data changes', () {
db.select(db.users).watch().listen((_) {});
db.markTableUpdated('users');
db.markTablesUpdated({'users'});
// twice: Once because the listener attached, once because the data changed
verify(executor.runSelect(any, any)).called(2);
@ -34,7 +34,7 @@ void main() {
test('when no listeners were attached', () {
db.select(db.users).watch();
db.markTableUpdated('users');
db.markTablesUpdated({'users'});
verifyNever(executor.runSelect(any, any));
});
@ -44,7 +44,7 @@ void main() {
clearInteractions(executor);
subscription.cancel();
db.markTableUpdated('users');
db.markTablesUpdated({'users'});
verifyNever(executor.runSelect(any, any));
});

View File

@ -67,7 +67,7 @@ void main() {
content: 'Updated content',
));
verify(streamQueries.handleTableUpdates('todos'));
verify(streamQueries.handleTableUpdates({'todos'}));
});
test('are not issued when no data was changed', () async {
@ -109,8 +109,7 @@ void main() {
test('informs about updated tables', () async {
await db.customUpdate('', updates: {db.users, db.todosTable});
verify(streamQueries.handleTableUpdates('users'));
verify(streamQueries.handleTableUpdates('todos'));
verify(streamQueries.handleTableUpdates({'users', 'todos'}));
});
});
}