Add real-world example for table inheritance to test

This commit is contained in:
Simon Binder 2019-10-11 22:03:32 +02:00
parent 0b9d4c897b
commit ff7d587339
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 29 additions and 4 deletions

View File

@ -55,6 +55,16 @@ void main() {
class Foos extends HasNameTable with IntIdTable {
TextColumn get name => text().nullable()();
}
class Socks extends Table {
TextColumn get name => text()();
IntColumn get id => integer().autoIncrement()();
}
class ArchivedSocks extends Socks {
TextColumn get archivedBy => text()();
DateTimeColumn get archivedOn => dateTime()();
}
'''
});
});
@ -156,10 +166,25 @@ void main() {
expect(table.columns.any((column) => column.hasAI), isFalse);
});
test('handles inheritance in column definitions', () async {
final table = await parse('Foos');
group('inheritance', () {
test('from abstract classes or mixins', () async {
final table = await parse('Foos');
expect(table.columns, hasLength(2));
expect(table.columns.map((c) => c.name.name), containsAll(['id', 'name']));
expect(table.columns, hasLength(2));
expect(
table.columns.map((c) => c.name.name), containsAll(['id', 'name']));
});
test('from regular classes', () async {
final socks = await parse('Socks');
final archivedSocks = await parse('ArchivedSocks');
expect(socks.columns, hasLength(2));
expect(socks.columns.map((c) => c.name.name), ['name', 'id']);
expect(archivedSocks.columns, hasLength(4));
expect(archivedSocks.columns.map((c) => c.name.name),
['name', 'id', 'archived_by', 'archived_on']);
});
});
}