mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-26 04:07:50 +00:00
FetchRequest tests
This commit is contained in:
1 parent
1ee4437970
commit
5fe7c5d888
2 files changed
+155
No files matched your search
@@ -224,6 +224,12 @@
|
||||
563363F91C960711000BE133 /* PerformanceRealmTests.realm in Resources */ = {isa = PBXBuildFile; fileRef = 563363F81C960711000BE133 /* PerformanceRealmTests.realm */; };
|
||||
563445051C4A7FD7003D3DC6 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563445041C4A7FD7003D3DC6 /* Utils.swift */; };
|
||||
563445061C4A7FD7003D3DC6 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 563445041C4A7FD7003D3DC6 /* Utils.swift */; };
|
||||
5634B0731CF22BEF005360B9 /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B0721CF22BEF005360B9 /* FetchRequestTests.swift */; };
|
||||
5634B0741CF22BEF005360B9 /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B0721CF22BEF005360B9 /* FetchRequestTests.swift */; };
|
||||
5634B0751CF22BEF005360B9 /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B0721CF22BEF005360B9 /* FetchRequestTests.swift */; };
|
||||
5634B0761CF22BEF005360B9 /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B0721CF22BEF005360B9 /* FetchRequestTests.swift */; };
|
||||
5634B0771CF22BEF005360B9 /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B0721CF22BEF005360B9 /* FetchRequestTests.swift */; };
|
||||
5634B0781CF22BEF005360B9 /* FetchRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5634B0721CF22BEF005360B9 /* FetchRequestTests.swift */; };
|
||||
564A50C71BFF4B7F00B3A3A2 /* CollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A50C61BFF4B7F00B3A3A2 /* CollationTests.swift */; };
|
||||
564A50C81BFF4B7F00B3A3A2 /* CollationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564A50C61BFF4B7F00B3A3A2 /* CollationTests.swift */; };
|
||||
565049051CE32543000A97D8 /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565049041CE32543000A97D8 /* FetchedRecordsControllerTests.swift */; };
|
||||
@@ -907,6 +913,7 @@
|
||||
563363DE1C959295000BE133 /* DatabasePoolFileAttributesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePoolFileAttributesTests.swift; sourceTree = "<group>"; };
|
||||
563363F81C960711000BE133 /* PerformanceRealmTests.realm */ = {isa = PBXFileReference; lastKnownFileType = file; path = PerformanceRealmTests.realm; sourceTree = "<group>"; };
|
||||
563445041C4A7FD7003D3DC6 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
|
||||
5634B0721CF22BEF005360B9 /* FetchRequestTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchRequestTests.swift; sourceTree = "<group>"; };
|
||||
564A50C61BFF4B7F00B3A3A2 /* CollationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollationTests.swift; sourceTree = "<group>"; };
|
||||
565049041CE32543000A97D8 /* FetchedRecordsControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedRecordsControllerTests.swift; sourceTree = "<group>"; };
|
||||
56553C181C3E906C00522B5C /* GRDBOSXCrashTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GRDBOSXCrashTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@@ -1301,6 +1308,14 @@
|
||||
path = DatabaseQueue;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
5634B06A1CF22BD8005360B9 /* FetchRequest */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5634B0721CF22BEF005360B9 /* FetchRequestTests.swift */,
|
||||
);
|
||||
path = FetchRequest;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
564A50BF1BFF4B6E00B3A3A2 /* Collation */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -1368,6 +1383,7 @@
|
||||
56B7F4281BE149F600E39BBF /* CoreGraphics */,
|
||||
5671566F1CB18039007DC145 /* Encryption */,
|
||||
56B15CFC1CD4C33A00A24C8B /* FetchedRecordsController */,
|
||||
5634B06A1CF22BD8005360B9 /* FetchRequest */,
|
||||
56F0B98C1B6001C600A2F135 /* Foundation */,
|
||||
56A238231B9C74A90082EB20 /* Migrations */,
|
||||
56300B5C1C53C38F005A543B /* QueryInterfaceRequest */,
|
||||
@@ -2363,6 +2379,7 @@
|
||||
560FC59B1CB00B880014AA8E /* DatabaseTimestampTests.swift in Sources */,
|
||||
560FC59C1CB00B880014AA8E /* StatementArguments+FoundationTests.swift in Sources */,
|
||||
560FC59D1CB00B880014AA8E /* TableMapping+QueryInterfaceRequestTests.swift in Sources */,
|
||||
5634B0741CF22BEF005360B9 /* FetchRequestTests.swift in Sources */,
|
||||
560FC59E1CB00B880014AA8E /* NSDateTests.swift in Sources */,
|
||||
560FC59F1CB00B880014AA8E /* DatabaseTests.swift in Sources */,
|
||||
560FC5A01CB00B880014AA8E /* QueryInterfaceRequestTests.swift in Sources */,
|
||||
@@ -2465,6 +2482,7 @@
|
||||
5671565D1CB16729007DC145 /* DatabaseTests.swift in Sources */,
|
||||
5671565E1CB16729007DC145 /* QueryInterfaceRequestTests.swift in Sources */,
|
||||
569178481CED9B6000E179EA /* DatabaseQueueTests.swift in Sources */,
|
||||
5634B0751CF22BEF005360B9 /* FetchRequestTests.swift in Sources */,
|
||||
5671565F1CB16729007DC145 /* NSDateComponentsTests.swift in Sources */,
|
||||
567156601CB16729007DC145 /* FunctionTests.swift in Sources */,
|
||||
567156611CB16729007DC145 /* RecordWithColumnNameManglingTests.swift in Sources */,
|
||||
@@ -2599,6 +2617,7 @@
|
||||
56AFCA6F1CB1AA9900F48B96 /* DatabaseTests.swift in Sources */,
|
||||
56AFCA701CB1AA9900F48B96 /* QueryInterfaceRequestTests.swift in Sources */,
|
||||
56AFCA711CB1AA9900F48B96 /* NSDateComponentsTests.swift in Sources */,
|
||||
5634B0771CF22BEF005360B9 /* FetchRequestTests.swift in Sources */,
|
||||
56AFCA721CB1AA9900F48B96 /* FunctionTests.swift in Sources */,
|
||||
56AFCA731CB1AA9900F48B96 /* InMemoryDatabaseTests.swift in Sources */,
|
||||
56AFCA741CB1AA9900F48B96 /* RecordWithColumnNameManglingTests.swift in Sources */,
|
||||
@@ -2689,6 +2708,7 @@
|
||||
56AFCACE1CB1ABC800F48B96 /* CGFloatTests.swift in Sources */,
|
||||
56AFCACF1CB1ABC800F48B96 /* StatementInformationTests.swift in Sources */,
|
||||
56AFCAD01CB1ABC800F48B96 /* GRDBTestCase.swift in Sources */,
|
||||
5634B0781CF22BEF005360B9 /* FetchRequestTests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -2816,6 +2836,7 @@
|
||||
56A238381B9C74A90082EB20 /* DatabaseTests.swift in Sources */,
|
||||
56300B5F1C53C38F005A543B /* QueryInterfaceRequestTests.swift in Sources */,
|
||||
56F0B9901B6001C600A2F135 /* NSDateComponentsTests.swift in Sources */,
|
||||
5634B0761CF22BEF005360B9 /* FetchRequestTests.swift in Sources */,
|
||||
560C97C81BFD0B8400BF8471 /* FunctionTests.swift in Sources */,
|
||||
56A2383A1B9C74A90082EB20 /* InMemoryDatabaseTests.swift in Sources */,
|
||||
56A5E40A1BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift in Sources */,
|
||||
@@ -2893,6 +2914,7 @@
|
||||
567404931CF02B56003ED5CC /* AdapterRowTests.swift in Sources */,
|
||||
56300B6B1C53D3E8005A543B /* TableMapping+QueryInterfaceRequestTests.swift in Sources */,
|
||||
56F0B9911B6001C600A2F135 /* NSDateTests.swift in Sources */,
|
||||
5634B0731CF22BEF005360B9 /* FetchRequestTests.swift in Sources */,
|
||||
56A238371B9C74A90082EB20 /* DatabaseTests.swift in Sources */,
|
||||
56300B661C53C8A7005A543B /* QueryInterfaceRequestTests.swift in Sources */,
|
||||
56F0B98F1B6001C600A2F135 /* NSDateComponentsTests.swift in Sources */,
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
import XCTest
|
||||
#if SQLITE_HAS_CODEC
|
||||
import GRDBCipher
|
||||
#else
|
||||
import GRDB
|
||||
#endif
|
||||
|
||||
private struct CustomFetchRequest : FetchRequest {
|
||||
func selectStatement(db: Database) throws -> SelectStatement {
|
||||
return try db.selectStatement("SELECT 1 AS 'produced'")
|
||||
}
|
||||
|
||||
func adapter(statement: SelectStatement) throws -> RowAdapter? {
|
||||
return RowAdapter(mapping: ["consumed": "produced"])
|
||||
}
|
||||
}
|
||||
|
||||
private struct CustomRecord: RowConvertible {
|
||||
let consumed: Int
|
||||
init(_ row: Row) {
|
||||
consumed = row.value(named: "consumed")
|
||||
}
|
||||
}
|
||||
|
||||
class FetchRequestTests: GRDBTestCase {
|
||||
|
||||
func testDatabaseValueConvertibleFetch() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.inDatabase { db in
|
||||
var fetchedInt: Int? = nil
|
||||
for i in Int.fetch(db, CustomFetchRequest()) {
|
||||
fetchedInt = i
|
||||
}
|
||||
XCTAssertEqual(fetchedInt!, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testDatabaseValueConvertibleFetchAll() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.inDatabase { db in
|
||||
let fetchedInts = Int.fetchAll(db, CustomFetchRequest())
|
||||
XCTAssertEqual(fetchedInts, [1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testDatabaseValueConvertibleFetchOne() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.inDatabase { db in
|
||||
let fetchedInt = Int.fetchOne(db, CustomFetchRequest())!
|
||||
XCTAssertEqual(fetchedInt, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRowFetch() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.inDatabase { db in
|
||||
var fetched = false
|
||||
for row in Row.fetch(db, CustomFetchRequest()) {
|
||||
fetched = true
|
||||
XCTAssertEqual(Array(row.columnNames), ["consumed"])
|
||||
XCTAssertEqual(Array(row.databaseValues), [1.databaseValue])
|
||||
}
|
||||
XCTAssertTrue(fetched)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRowFetchAll() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.inDatabase { db in
|
||||
let rows = Row.fetchAll(db, CustomFetchRequest())
|
||||
XCTAssertEqual(rows.count, 1)
|
||||
XCTAssertEqual(Array(rows[0].columnNames), ["consumed"])
|
||||
XCTAssertEqual(Array(rows[0].databaseValues), [1.databaseValue])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRowFetchOne() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.inDatabase { db in
|
||||
let row = Row.fetchOne(db, CustomFetchRequest())!
|
||||
XCTAssertEqual(Array(row.columnNames), ["consumed"])
|
||||
XCTAssertEqual(Array(row.databaseValues), [1.databaseValue])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRowConvertibleFetch() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.inDatabase { db in
|
||||
var fetched = false
|
||||
for record in CustomRecord.fetch(db, CustomFetchRequest()) {
|
||||
fetched = true
|
||||
XCTAssertEqual(record.consumed, 1)
|
||||
}
|
||||
XCTAssertTrue(fetched)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRowConvertibleFetchAll() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.inDatabase { db in
|
||||
let records = CustomRecord.fetchAll(db, CustomFetchRequest())
|
||||
XCTAssertEqual(records.count, 1)
|
||||
XCTAssertEqual(records[0].consumed, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRowConvertibleFetchOne() {
|
||||
assertNoError {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
dbQueue.inDatabase { db in
|
||||
let record = CustomRecord.fetchOne(db, CustomFetchRequest())!
|
||||
XCTAssertEqual(record.consumed, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user