From e8d5d6a19080729d0f1ffcaa06acfe10716a5828 Mon Sep 17 00:00:00 2001 From: Pascal Edmond Date: Wed, 16 Dec 2015 16:47:57 +0100 Subject: [PATCH] WIP tests --- .../FetchedRecordsControllerTests.swift | 45 +++++++++++++++++++ GRDB.xcodeproj/project.pbxproj | 26 ++++++++++- GRDB/Record/FetchedRecordsController.swift | 34 +++++++------- 3 files changed, 84 insertions(+), 21 deletions(-) create mode 100644 GRDB Tests/Public/FetchedRecordsController/FetchedRecordsControllerTests.swift diff --git a/GRDB Tests/Public/FetchedRecordsController/FetchedRecordsControllerTests.swift b/GRDB Tests/Public/FetchedRecordsController/FetchedRecordsControllerTests.swift new file mode 100644 index 000000000..c1beab5d0 --- /dev/null +++ b/GRDB Tests/Public/FetchedRecordsController/FetchedRecordsControllerTests.swift @@ -0,0 +1,45 @@ +// +// FetchedRecordsControllerTests.swift +// GRDB +// +// Created by Pascal Edmond on 16/12/2015. +// Copyright © 2015 Gwendal Roué. All rights reserved. +// + +import XCTest + +class FetchedRecordsControllerTests: GRDBTestCase { + + override func setUp() { + super.setUp() + + var migrator = DatabaseMigrator() + migrator.registerMigration("createPersons") { db in + try db.execute( + "CREATE TABLE persons (" + + "id INTEGER PRIMARY KEY, " + + "firstName TEXT, " + + "lastName TEXT " + + ")") + } + migrator.registerMigration("addPersons") { db in + try Person(firstName: "Arthur", lastName: "Miller").insert(db) + try Person(firstName: "Barbara", lastName: "Streisand").insert(db) + try Person(firstName: "Cinderella").insert(db) + } + try! migrator.migrate(dbQueue) + } + + func testExample() { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measureBlock { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/GRDB.xcodeproj/project.pbxproj b/GRDB.xcodeproj/project.pbxproj index ed017db7c..6577e8f10 100644 --- a/GRDB.xcodeproj/project.pbxproj +++ b/GRDB.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 315013971C21BDA400951DE3 /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 315013961C21BDA400951DE3 /* FetchedRecordsControllerTests.swift */; }; + 315013981C21BDA400951DE3 /* FetchedRecordsControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 315013961C21BDA400951DE3 /* FetchedRecordsControllerTests.swift */; }; 31AEFE3F1C185E63003DB703 /* FetchedRecordsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31AEFE3E1C185E63003DB703 /* FetchedRecordsController.swift */; }; 31AEFE421C185E63003DB703 /* FetchedRecordsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31AEFE3E1C185E63003DB703 /* FetchedRecordsController.swift */; }; 5606AF911C0ED37000D20487 /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 56BB86301BA98AB0001F9168 /* libsqlite3.tbd */; }; @@ -299,7 +301,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 31AEFE3E1C185E63003DB703 /* FetchedRecordsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FetchedRecordsController.swift; sourceTree = ""; }; + 315013961C21BDA400951DE3 /* FetchedRecordsControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FetchedRecordsControllerTests.swift; path = FetchedRecordsController/FetchedRecordsControllerTests.swift; sourceTree = ""; }; + 31AEFE3E1C185E63003DB703 /* FetchedRecordsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FetchedRecordsController.swift; path = Record/FetchedRecordsController.swift; sourceTree = ""; }; 5607EFD21BB8254800605DE3 /* TransactionObserverTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionObserverTests.swift; sourceTree = ""; }; 560B3FAB1C19E01000C58EC7 /* DatabasePersistableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePersistableTests.swift; sourceTree = ""; }; 560C97C61BFD0B8400BF8471 /* FunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FunctionTests.swift; sourceTree = ""; }; @@ -472,6 +475,22 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 315013941C21BCE600951DE3 /* FetchedRecordsController */ = { + isa = PBXGroup; + children = ( + 31AEFE3E1C185E63003DB703 /* FetchedRecordsController.swift */, + ); + name = FetchedRecordsController; + sourceTree = ""; + }; + 315013951C21BD6200951DE3 /* FetchedRecordsController */ = { + isa = PBXGroup; + children = ( + 315013961C21BDA400951DE3 /* FetchedRecordsControllerTests.swift */, + ); + name = FetchedRecordsController; + sourceTree = ""; + }; 5607EFD11BB8253300605DE3 /* TransactionObserver */ = { isa = PBXGroup; children = ( @@ -529,6 +548,7 @@ 56CB92EC1BA453E500DFD5FC /* CrashTests.swift */, 56A238111B9C74A90082EB20 /* Core */, 56B7F4281BE149F600E39BBF /* CoreGraphics */, + 315013951C21BD6200951DE3 /* FetchedRecordsController */, 56F0B98C1B6001C600A2F135 /* Foundation */, 56A238231B9C74A90082EB20 /* Migrations */, 56A238251B9C74A90082EB20 /* Record */, @@ -722,7 +742,6 @@ isa = PBXGroup; children = ( 56A238A11B9C753B0082EB20 /* Record.swift */, - 31AEFE3E1C185E63003DB703 /* FetchedRecordsController.swift */, ); path = Record; sourceTree = ""; @@ -901,6 +920,7 @@ children = ( 56A2386F1B9C75030082EB20 /* Core */, 56B7F4251BE148FE00E39BBF /* CoreGraphics */, + 315013941C21BCE600951DE3 /* FetchedRecordsController */, 56A238001B9C6A1E0082EB20 /* Foundation */, 56A238911B9C750B0082EB20 /* Migrations */, 56A2389F1B9C753B0082EB20 /* Record */, @@ -1287,6 +1307,7 @@ 565B0FF01BBC7D980098DE03 /* RowConvertibleTests.swift in Sources */, 56E8CE0E1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift in Sources */, 56A238581B9C74A90082EB20 /* PrimaryKeyRowIDTests.swift in Sources */, + 315013981C21BDA400951DE3 /* FetchedRecordsControllerTests.swift in Sources */, 56A238621B9C74A90082EB20 /* RecordEditedTests.swift in Sources */, 56A2385C1B9C74A90082EB20 /* PrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */, 56A238401B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, @@ -1345,6 +1366,7 @@ 56A238611B9C74A90082EB20 /* RecordEditedTests.swift in Sources */, 56A2385B1B9C74A90082EB20 /* PrimaryKeySingleWithReplaceConflictResolutionTests.swift in Sources */, 565B0FEF1BBC7D980098DE03 /* RowConvertibleTests.swift in Sources */, + 315013971C21BDA400951DE3 /* FetchedRecordsControllerTests.swift in Sources */, 56A2383F1B9C74A90082EB20 /* DatabaseValueConvertibleSubclassTests.swift in Sources */, 56E8CE0D1BB4FA5600828BEC /* DatabaseValueConvertibleFetchTests.swift in Sources */, 56A2383B1B9C74A90082EB20 /* DatabaseErrorTests.swift in Sources */, diff --git a/GRDB/Record/FetchedRecordsController.swift b/GRDB/Record/FetchedRecordsController.swift index bbdb24cab..44053fc44 100644 --- a/GRDB/Record/FetchedRecordsController.swift +++ b/GRDB/Record/FetchedRecordsController.swift @@ -100,10 +100,8 @@ public class FetchedRecordsController 0 { + let update = FetchedRecordsUpdate.Update(item: newItem, at: newIndexPath, changes: changes) + updates.append(update) + apply(update) + } + } else { + // Not a record + let update = FetchedRecordsUpdate.Update(item: newItem, at: newIndexPath, changes: nil) + updates.append(update) + apply(update) } - - // Not a record - let update = FetchedRecordsUpdate.Update(item: newItem, at: newIndexPath, changes: changes) - updates.append(update) - apply(update) - } else { // item moved let update = FetchedRecordsUpdate.Move(item: newItem, from: oldIndexPath, to: newIndexPath) updates.append(update) apply(update) } - } else { // item deleted let update = FetchedRecordsUpdate.Delete(item: oldItem, at: oldIndexPath) @@ -205,7 +201,7 @@ public enum FetchedRecordsUpdate { case Insert(item:T, at: NSIndexPath) case Delete(item:T, at: NSIndexPath) case Move(item:T, from: NSIndexPath, to: NSIndexPath) - case Update(item:T, at: NSIndexPath, changes: [String: (old: DatabaseValue?, new: DatabaseValue)]?) + case Update(item:T, at: NSIndexPath, changes: [String: DatabaseValue?]?) var description: String { switch self {