mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-18 23:43:57 +01:00
WIP: segfault
This commit is contained in:
@@ -36,11 +36,11 @@ class BaseTestCase: XCTestCase {
|
||||
// MARK: Internal
|
||||
|
||||
@nonobjc
|
||||
func prepareStack<T>(configurations configurations: [String?] = [nil], @noescape _ closure: (dataStack: DataStack) -> T) -> T {
|
||||
func prepareStack<T>(_ configurations: [String?] = [nil], @noescape _ closure: (dataStack: DataStack) -> T) -> T {
|
||||
|
||||
let stack = DataStack(
|
||||
modelName: "Model",
|
||||
bundle: NSBundle(forClass: self.dynamicType)
|
||||
bundle: Bundle(forClass: self.dynamicType)
|
||||
)
|
||||
do {
|
||||
|
||||
@@ -49,10 +49,10 @@ class BaseTestCase: XCTestCase {
|
||||
try stack.addStorageAndWait(
|
||||
SQLiteStore(
|
||||
fileURL: SQLiteStore.defaultRootDirectory
|
||||
.URLByAppendingPathComponent(NSUUID().UUIDString)
|
||||
.URLByAppendingPathComponent(UUID().UUIDString)
|
||||
.URLByAppendingPathComponent("\(self.dynamicType)_\(($0 ?? "-null-")).sqlite"),
|
||||
configuration: $0,
|
||||
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||
localStorageOptions: .recreateStoreOnModelMismatch
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class BaseTestCase: XCTestCase {
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
func expectLogger<T>(expectations: [TestLogger.Expectation], @noescape closure: () -> T) -> T {
|
||||
func expectLogger<T>(_ expectations: [TestLogger.Expectation], @noescape closure: () -> T) -> T {
|
||||
|
||||
CoreStore.logger = TestLogger(self.prepareLoggerExpectations(expectations))
|
||||
defer {
|
||||
@@ -77,18 +77,18 @@ class BaseTestCase: XCTestCase {
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
func expectLogger(expectations: [TestLogger.Expectation: XCTestExpectation]) {
|
||||
func expectLogger(_ expectations: [TestLogger.Expectation: XCTestExpectation]) {
|
||||
|
||||
CoreStore.logger = TestLogger(expectations)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
func prepareLoggerExpectations(expectations: [TestLogger.Expectation]) -> [TestLogger.Expectation: XCTestExpectation] {
|
||||
func prepareLoggerExpectations(_ expectations: [TestLogger.Expectation]) -> [TestLogger.Expectation: XCTestExpectation] {
|
||||
|
||||
var testExpectations: [TestLogger.Expectation: XCTestExpectation] = [:]
|
||||
for expectation in expectations {
|
||||
|
||||
testExpectations[expectation] = self.expectationWithDescription("Logger Expectation: \(expectation)")
|
||||
testExpectations[expectation] = self.expectation(withDescription: "Logger Expectation: \(expectation)")
|
||||
}
|
||||
return testExpectations
|
||||
}
|
||||
@@ -96,13 +96,13 @@ class BaseTestCase: XCTestCase {
|
||||
@nonobjc
|
||||
func checkExpectationsImmediately() {
|
||||
|
||||
self.waitForExpectationsWithTimeout(0, handler: nil)
|
||||
self.waitForExpectations(withTimeout: 0, handler: nil)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
func waitAndCheckExpectations() {
|
||||
|
||||
self.waitForExpectationsWithTimeout(10, handler: nil)
|
||||
self.waitForExpectations(withTimeout: 10, handler: nil)
|
||||
}
|
||||
|
||||
// MARK: XCTestCase
|
||||
@@ -126,7 +126,7 @@ class BaseTestCase: XCTestCase {
|
||||
|
||||
private func deleteStores() {
|
||||
|
||||
_ = try? NSFileManager.defaultManager().removeItemAtURL(SQLiteStore.defaultRootDirectory)
|
||||
_ = try? FileManager.defaultManager().removeItemAtURL(SQLiteStore.defaultRootDirectory)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,11 +137,11 @@ class TestLogger: CoreStoreLogger {
|
||||
|
||||
enum Expectation {
|
||||
|
||||
case LogWarning
|
||||
case LogFatal
|
||||
case LogError
|
||||
case AssertionFailure
|
||||
case FatalError
|
||||
case logWarning
|
||||
case logFatal
|
||||
case logError
|
||||
case assertionFailure
|
||||
case fatalError
|
||||
}
|
||||
|
||||
init(_ expectations: [Expectation: XCTestExpectation]) {
|
||||
@@ -152,33 +152,33 @@ class TestLogger: CoreStoreLogger {
|
||||
|
||||
// MARK: CoreStoreLogger
|
||||
|
||||
func log(level level: LogLevel, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||
func log(_ level: LogLevel, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||
|
||||
switch level {
|
||||
|
||||
case .Warning: self.fulfill(.LogWarning)
|
||||
case .Fatal: self.fulfill(.LogFatal)
|
||||
case .warning: self.fulfill(.logWarning)
|
||||
case .fatal: self.fulfill(.logFatal)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
|
||||
func log(error error: CoreStoreError, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||
func log(_ error: CoreStoreError, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||
|
||||
self.fulfill(.LogError)
|
||||
self.fulfill(.logError)
|
||||
}
|
||||
|
||||
func assert(@autoclosure condition: () -> Bool, @autoclosure message: () -> String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||
func assert(@autoclosure _ condition: () -> Bool, @autoclosure message: () -> String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||
|
||||
if condition() {
|
||||
|
||||
return
|
||||
}
|
||||
self.fulfill(.AssertionFailure)
|
||||
self.fulfill(.assertionFailure)
|
||||
}
|
||||
|
||||
func abort(message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||
func abort(_ message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||
|
||||
self.fulfill(.FatalError)
|
||||
self.fulfill(.fatalError)
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ class TestLogger: CoreStoreLogger {
|
||||
|
||||
private var expectations: [Expectation: XCTestExpectation]
|
||||
|
||||
private func fulfill(expectation: Expectation) {
|
||||
private func fulfill(_ expectation: Expectation) {
|
||||
|
||||
if let instance = self.expectations[expectation] {
|
||||
|
||||
|
||||
@@ -17,18 +17,18 @@ import CoreStore
|
||||
class BaseTestDataTestCase: BaseTestCase {
|
||||
|
||||
@nonobjc
|
||||
let dateFormatter: NSDateFormatter = {
|
||||
let dateFormatter: DateFormatter = {
|
||||
|
||||
let formatter = NSDateFormatter()
|
||||
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
|
||||
formatter.timeZone = NSTimeZone(name: "UTC")
|
||||
formatter.calendar = NSCalendar(identifier: NSCalendarIdentifierGregorian)
|
||||
let formatter = DateFormatter()
|
||||
formatter.locale = Locale(localeIdentifier: "en_US_POSIX")
|
||||
formatter.timeZone = TimeZone(name: "UTC")
|
||||
formatter.calendar = Calendar(identifier: Calendar.Identifier.gregorian)
|
||||
formatter.dateFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ssZ"
|
||||
return formatter
|
||||
}()
|
||||
|
||||
@nonobjc
|
||||
func prepareTestDataForStack(stack: DataStack, configurations: [String?] = [nil]) {
|
||||
func prepareTestDataForStack(_ stack: DataStack, configurations: [String?] = [nil]) {
|
||||
|
||||
stack.beginSynchronous { (transaction) in
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ final class ErrorTests: XCTestCase {
|
||||
@objc
|
||||
dynamic func test_ThatDifferentStorageExistsAtURLErrors_BridgeCorrectly() {
|
||||
|
||||
let dummyURL = NSURL(string: "file:///test1/test2.sqlite")!
|
||||
let dummyURL = URL(string: "file:///test1/test2.sqlite")!
|
||||
|
||||
let error = CoreStoreError.DifferentStorageExistsAtURL(existingPersistentStoreURL: dummyURL)
|
||||
XCTAssertEqual((error as NSError).domain, CoreStoreErrorDomain)
|
||||
@@ -83,9 +83,9 @@ final class ErrorTests: XCTestCase {
|
||||
@objc
|
||||
dynamic func test_ThatMappingModelNotFoundErrors_BridgeCorrectly() {
|
||||
|
||||
let dummyURL = NSURL(string: "file:///test1/test2.sqlite")!
|
||||
let dummyURL = URL(string: "file:///test1/test2.sqlite")!
|
||||
|
||||
let model = NSManagedObjectModel.fromBundle(NSBundle(forClass: self.dynamicType), modelName: "Model")
|
||||
let model = NSManagedObjectModel.fromBundle(Bundle(forClass: self.dynamicType), modelName: "Model")
|
||||
let version = "1.0.0"
|
||||
|
||||
let error = CoreStoreError.MappingModelNotFound(localStoreURL: dummyURL, targetModel: model, targetModelVersion: version)
|
||||
@@ -113,7 +113,7 @@ final class ErrorTests: XCTestCase {
|
||||
@objc
|
||||
dynamic func test_ThatProgressiveMigrationRequiredErrors_BridgeCorrectly() {
|
||||
|
||||
let dummyURL = NSURL(string: "file:///test1/test2.sqlite")!
|
||||
let dummyURL = URL(string: "file:///test1/test2.sqlite")!
|
||||
|
||||
let error = CoreStoreError.ProgressiveMigrationRequired(localStoreURL: dummyURL)
|
||||
XCTAssertEqual((error as NSError).domain, CoreStoreErrorDomain)
|
||||
@@ -144,7 +144,7 @@ final class ErrorTests: XCTestCase {
|
||||
userInfo: [
|
||||
"key1": "value1",
|
||||
"key2": 2,
|
||||
"key3": NSDate()
|
||||
"key3": Date()
|
||||
]
|
||||
)
|
||||
let error = CoreStoreError.InternalError(NSError: internalError)
|
||||
|
||||
@@ -97,7 +97,7 @@ final class FetchTests: BaseTestDataTestCase {
|
||||
XCTAssertEqual(existing1!.objectID, object.objectID)
|
||||
XCTAssertEqual(existing1!.managedObjectContext, transaction.context)
|
||||
|
||||
GCDQueue.Main.async {
|
||||
GCDQueue.main.async {
|
||||
|
||||
let existing2 = stack.fetchExisting(existing1!)
|
||||
XCTAssertNotNil(existing2)
|
||||
@@ -204,7 +204,7 @@ final class FetchTests: BaseTestDataTestCase {
|
||||
|
||||
XCTAssertEqual(object.managedObjectContext, transaction.context)
|
||||
}
|
||||
GCDQueue.Main.async {
|
||||
GCDQueue.main.async {
|
||||
|
||||
let existing2 = stack.fetchExisting(existing1)
|
||||
XCTAssertEqual(
|
||||
|
||||
@@ -883,17 +883,17 @@ class ImportTests: BaseTestDataTestCase {
|
||||
|
||||
// MARK: - TestInsertError
|
||||
|
||||
private struct TestInsertError: ErrorType {}
|
||||
private struct TestInsertError: ErrorProtocol {}
|
||||
|
||||
|
||||
// MARK: - TestUpdateError
|
||||
|
||||
private struct TestUpdateError: ErrorType {}
|
||||
private struct TestUpdateError: ErrorProtocol {}
|
||||
|
||||
|
||||
// MARK: - TestIDError
|
||||
|
||||
private struct TestIDError: ErrorType {}
|
||||
private struct TestIDError: ErrorProtocol {}
|
||||
|
||||
|
||||
// MARK: - TestEntity1
|
||||
@@ -904,12 +904,12 @@ extension TestEntity1: ImportableUniqueObject {
|
||||
|
||||
typealias ImportSource = [String: AnyObject]
|
||||
|
||||
static func shouldInsertFromImportSource(source: [String: AnyObject], inTransaction transaction: BaseDataTransaction) -> Bool {
|
||||
static func shouldInsertFromImportSource(_ source: [String: AnyObject], inTransaction transaction: BaseDataTransaction) -> Bool {
|
||||
|
||||
return source["skip_insert"] == nil
|
||||
}
|
||||
|
||||
func didInsertFromImportSource(source: [String: AnyObject], inTransaction transaction: BaseDataTransaction) throws {
|
||||
func didInsertFromImportSource(_ source: [String: AnyObject], inTransaction transaction: BaseDataTransaction) throws {
|
||||
|
||||
if let _ = source["throw_on_insert"] {
|
||||
|
||||
@@ -919,8 +919,8 @@ extension TestEntity1: ImportableUniqueObject {
|
||||
self.testNumber = source["testNumber"] as? NSNumber
|
||||
self.testDecimal = source["testDecimal"] as? NSDecimalNumber
|
||||
self.testString = source["testString"] as? String
|
||||
self.testData = source["testData"] as? NSData
|
||||
self.testDate = source["testDate"] as? NSDate
|
||||
self.testData = source["testData"] as? Data
|
||||
self.testDate = source["testDate"] as? Date
|
||||
self.testNil = nil
|
||||
}
|
||||
|
||||
@@ -951,12 +951,12 @@ extension TestEntity1: ImportableUniqueObject {
|
||||
}
|
||||
}
|
||||
|
||||
static func shouldUpdateFromImportSource(source: [String: AnyObject], inTransaction transaction: BaseDataTransaction) -> Bool {
|
||||
static func shouldUpdateFromImportSource(_ source: [String: AnyObject], inTransaction transaction: BaseDataTransaction) -> Bool {
|
||||
|
||||
return source["skip_update"] == nil
|
||||
}
|
||||
|
||||
static func uniqueIDFromImportSource(source: [String: AnyObject], inTransaction transaction: BaseDataTransaction) throws -> NSNumber? {
|
||||
static func uniqueIDFromImportSource(_ source: [String: AnyObject], inTransaction transaction: BaseDataTransaction) throws -> NSNumber? {
|
||||
|
||||
if let _ = source["throw_on_id"] {
|
||||
|
||||
@@ -965,7 +965,7 @@ extension TestEntity1: ImportableUniqueObject {
|
||||
return source["testEntityID"] as? NSNumber
|
||||
}
|
||||
|
||||
func updateFromImportSource(source: [String: AnyObject], inTransaction transaction: BaseDataTransaction) throws {
|
||||
func updateFromImportSource(_ source: [String: AnyObject], inTransaction transaction: BaseDataTransaction) throws {
|
||||
|
||||
if let _ = source["throw_on_update"] {
|
||||
|
||||
@@ -975,8 +975,8 @@ extension TestEntity1: ImportableUniqueObject {
|
||||
self.testNumber = source["testNumber"] as? NSNumber
|
||||
self.testDecimal = source["testDecimal"] as? NSDecimalNumber
|
||||
self.testString = source["testString"] as? String
|
||||
self.testData = source["testData"] as? NSData
|
||||
self.testDate = source["testDate"] as? NSDate
|
||||
self.testData = source["testData"] as? Data
|
||||
self.testDate = source["testDate"] as? Date
|
||||
self.testNil = nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,37 +562,37 @@ class TestListObserver: ListSectionObserver {
|
||||
|
||||
typealias ListEntityType = TestEntity1
|
||||
|
||||
func listMonitorWillChange(monitor: ListMonitor<TestEntity1>) {
|
||||
func listMonitorWillChange(_ monitor: ListMonitor<TestEntity1>) {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||
"listMonitorWillChange:",
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.Name(rawValue: "listMonitorWillChange:"),
|
||||
object: self,
|
||||
userInfo: [:]
|
||||
)
|
||||
}
|
||||
|
||||
func listMonitorDidChange(monitor: ListMonitor<TestEntity1>) {
|
||||
func listMonitorDidChange(_ monitor: ListMonitor<TestEntity1>) {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||
"listMonitorDidChange:",
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.Name(rawValue: "listMonitorDidChange:"),
|
||||
object: self,
|
||||
userInfo: [:]
|
||||
)
|
||||
}
|
||||
|
||||
func listMonitorWillRefetch(monitor: ListMonitor<TestEntity1>) {
|
||||
func listMonitorWillRefetch(_ monitor: ListMonitor<TestEntity1>) {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||
"listMonitorWillRefetch:",
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.Name(rawValue: "listMonitorWillRefetch:"),
|
||||
object: self,
|
||||
userInfo: [:]
|
||||
)
|
||||
}
|
||||
|
||||
func listMonitorDidRefetch(monitor: ListMonitor<TestEntity1>) {
|
||||
func listMonitorDidRefetch(_ monitor: ListMonitor<TestEntity1>) {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||
"listMonitorDidRefetch:",
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.Name(rawValue: "listMonitorDidRefetch:"),
|
||||
object: self,
|
||||
userInfo: [:]
|
||||
)
|
||||
@@ -601,10 +601,10 @@ class TestListObserver: ListSectionObserver {
|
||||
|
||||
// MARK: ListObjectObserver
|
||||
|
||||
func listMonitor(monitor: ListMonitor<TestEntity1>, didInsertObject object: TestEntity1, toIndexPath indexPath: NSIndexPath) {
|
||||
func listMonitor(_ monitor: ListMonitor<TestEntity1>, didInsertObject object: TestEntity1, toIndexPath indexPath: IndexPath) {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||
"listMonitor:didInsertObject:toIndexPath:",
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.Name(rawValue: "listMonitor:didInsertObject:toIndexPath:"),
|
||||
object: self,
|
||||
userInfo: [
|
||||
"object": object,
|
||||
@@ -613,10 +613,10 @@ class TestListObserver: ListSectionObserver {
|
||||
)
|
||||
}
|
||||
|
||||
func listMonitor(monitor: ListMonitor<TestEntity1>, didDeleteObject object: TestEntity1, fromIndexPath indexPath: NSIndexPath) {
|
||||
func listMonitor(_ monitor: ListMonitor<TestEntity1>, didDeleteObject object: TestEntity1, fromIndexPath indexPath: IndexPath) {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||
"listMonitor:didDeleteObject:fromIndexPath:",
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.Name(rawValue: "listMonitor:didDeleteObject:fromIndexPath:"),
|
||||
object: self,
|
||||
userInfo: [
|
||||
"object": object,
|
||||
@@ -625,10 +625,10 @@ class TestListObserver: ListSectionObserver {
|
||||
)
|
||||
}
|
||||
|
||||
func listMonitor(monitor: ListMonitor<TestEntity1>, didUpdateObject object: TestEntity1, atIndexPath indexPath: NSIndexPath) {
|
||||
func listMonitor(_ monitor: ListMonitor<TestEntity1>, didUpdateObject object: TestEntity1, atIndexPath indexPath: IndexPath) {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||
"listMonitor:didUpdateObject:atIndexPath:",
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.Name(rawValue: "listMonitor:didUpdateObject:atIndexPath:"),
|
||||
object: self,
|
||||
userInfo: [
|
||||
"object": object,
|
||||
@@ -638,10 +638,10 @@ class TestListObserver: ListSectionObserver {
|
||||
}
|
||||
|
||||
|
||||
func listMonitor(monitor: ListMonitor<TestEntity1>, didMoveObject object: TestEntity1, fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
|
||||
func listMonitor(_ monitor: ListMonitor<TestEntity1>, didMoveObject object: TestEntity1, fromIndexPath: IndexPath, toIndexPath: IndexPath) {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||
"listMonitor:didMoveObject:fromIndexPath:toIndexPath:",
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.Name(rawValue: "listMonitor:didMoveObject:fromIndexPath:toIndexPath:"),
|
||||
object: self,
|
||||
userInfo: [
|
||||
"object": object,
|
||||
@@ -654,9 +654,9 @@ class TestListObserver: ListSectionObserver {
|
||||
|
||||
// MARK: ListSectionObserver
|
||||
|
||||
func listMonitor(monitor: ListMonitor<TestEntity1>, didInsertSection sectionInfo: NSFetchedResultsSectionInfo, toSectionIndex sectionIndex: Int) {
|
||||
func listMonitor(_ monitor: ListMonitor<TestEntity1>, didInsertSection sectionInfo: NSFetchedResultsSectionInfo, toSectionIndex sectionIndex: Int) {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||
NotificationCenter.defaultCenter().postNotificationName(
|
||||
"listMonitor:didInsertSection:toSectionIndex:",
|
||||
object: self,
|
||||
userInfo: [
|
||||
@@ -666,9 +666,9 @@ class TestListObserver: ListSectionObserver {
|
||||
)
|
||||
}
|
||||
|
||||
func listMonitor(monitor: ListMonitor<TestEntity1>, didDeleteSection sectionInfo: NSFetchedResultsSectionInfo, fromSectionIndex sectionIndex: Int) {
|
||||
func listMonitor(_ monitor: ListMonitor<TestEntity1>, didDeleteSection sectionInfo: NSFetchedResultsSectionInfo, fromSectionIndex sectionIndex: Int) {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||
NotificationCenter.defaultCenter().postNotificationName(
|
||||
"listMonitor:didDeleteSection:fromSectionIndex:",
|
||||
object: self,
|
||||
userInfo: [
|
||||
|
||||
@@ -208,10 +208,10 @@ class TestObjectObserver: ObjectObserver {
|
||||
|
||||
typealias ObjectEntityType = TestEntity1
|
||||
|
||||
func objectMonitor(monitor: ObjectMonitor<TestEntity1>, willUpdateObject object: TestEntity1) {
|
||||
func objectMonitor(_ monitor: ObjectMonitor<TestEntity1>, willUpdateObject object: TestEntity1) {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||
"objectMonitor:willUpdateObject:",
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.Name(rawValue: "objectMonitor:willUpdateObject:"),
|
||||
object: self,
|
||||
userInfo: [
|
||||
"object": object
|
||||
@@ -219,9 +219,9 @@ class TestObjectObserver: ObjectObserver {
|
||||
)
|
||||
}
|
||||
|
||||
func objectMonitor(monitor: ObjectMonitor<TestEntity1>, didUpdateObject object: TestEntity1, changedPersistentKeys: Set<KeyPath>) {
|
||||
func objectMonitor(_ monitor: ObjectMonitor<TestEntity1>, didUpdateObject object: TestEntity1, changedPersistentKeys: Set<KeyPath>) {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||
NotificationCenter.defaultCenter().postNotificationName(
|
||||
"objectMonitor:didUpdateObject:changedPersistentKeys:",
|
||||
object: self,
|
||||
userInfo: [
|
||||
@@ -231,10 +231,10 @@ class TestObjectObserver: ObjectObserver {
|
||||
)
|
||||
}
|
||||
|
||||
func objectMonitor(monitor: ObjectMonitor<TestEntity1>, didDeleteObject object: TestEntity1) {
|
||||
func objectMonitor(_ monitor: ObjectMonitor<TestEntity1>, didDeleteObject object: TestEntity1) {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(
|
||||
"objectMonitor:didDeleteObject:",
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.Name(rawValue: "objectMonitor:didDeleteObject:"),
|
||||
object: self,
|
||||
userInfo: [
|
||||
"object": object
|
||||
|
||||
@@ -40,26 +40,26 @@ final class OrderByTests: XCTestCase {
|
||||
|
||||
let orderBy = OrderBy()
|
||||
XCTAssertEqual(orderBy, OrderBy([] as [NSSortDescriptor]))
|
||||
XCTAssertNotEqual(orderBy, OrderBy(NSSortDescriptor(key: "key", ascending: false)))
|
||||
XCTAssertNotEqual(orderBy, OrderBy(SortDescriptor(key: "key", ascending: false)))
|
||||
XCTAssertTrue(orderBy.sortDescriptors.isEmpty)
|
||||
}
|
||||
do {
|
||||
|
||||
let sortDescriptor = NSSortDescriptor(key: "key1", ascending: true)
|
||||
let sortDescriptor = SortDescriptor(key: "key1", ascending: true)
|
||||
let orderBy = OrderBy(sortDescriptor)
|
||||
XCTAssertEqual(orderBy, OrderBy(sortDescriptor))
|
||||
XCTAssertEqual(orderBy, OrderBy(.Ascending("key1")))
|
||||
XCTAssertNotEqual(orderBy, OrderBy(.Ascending("key2")))
|
||||
XCTAssertNotEqual(orderBy, OrderBy(.Descending("key1")))
|
||||
XCTAssertNotEqual(orderBy, OrderBy(NSSortDescriptor(key: "key1", ascending: false)))
|
||||
XCTAssertNotEqual(orderBy, OrderBy(SortDescriptor(key: "key1", ascending: false)))
|
||||
XCTAssertEqual(orderBy, OrderBy([sortDescriptor]))
|
||||
XCTAssertEqual(orderBy.sortDescriptors, [sortDescriptor])
|
||||
}
|
||||
do {
|
||||
|
||||
let sortDescriptors = [
|
||||
NSSortDescriptor(key: "key1", ascending: true),
|
||||
NSSortDescriptor(key: "key2", ascending: false)
|
||||
SortDescriptor(key: "key1", ascending: true),
|
||||
SortDescriptor(key: "key2", ascending: false)
|
||||
]
|
||||
let orderBy = OrderBy(sortDescriptors)
|
||||
XCTAssertEqual(orderBy, OrderBy(sortDescriptors))
|
||||
@@ -68,8 +68,8 @@ final class OrderByTests: XCTestCase {
|
||||
orderBy,
|
||||
OrderBy(
|
||||
[
|
||||
NSSortDescriptor(key: "key1", ascending: false),
|
||||
NSSortDescriptor(key: "key2", ascending: false)
|
||||
SortDescriptor(key: "key1", ascending: false),
|
||||
SortDescriptor(key: "key2", ascending: false)
|
||||
]
|
||||
)
|
||||
)
|
||||
@@ -80,7 +80,7 @@ final class OrderByTests: XCTestCase {
|
||||
do {
|
||||
|
||||
let orderBy = OrderBy(.Ascending("key1"))
|
||||
let sortDescriptor = NSSortDescriptor(key: "key1", ascending: true)
|
||||
let sortDescriptor = SortDescriptor(key: "key1", ascending: true)
|
||||
XCTAssertEqual(orderBy, OrderBy(sortDescriptor))
|
||||
XCTAssertEqual(orderBy, OrderBy(.Ascending("key1")))
|
||||
XCTAssertNotEqual(orderBy, OrderBy(.Descending("key1")))
|
||||
@@ -92,8 +92,8 @@ final class OrderByTests: XCTestCase {
|
||||
|
||||
let orderBy = OrderBy(.Ascending("key1"), .Descending("key2"))
|
||||
let sortDescriptors = [
|
||||
NSSortDescriptor(key: "key1", ascending: true),
|
||||
NSSortDescriptor(key: "key2", ascending: false)
|
||||
SortDescriptor(key: "key1", ascending: true),
|
||||
SortDescriptor(key: "key2", ascending: false)
|
||||
]
|
||||
XCTAssertEqual(orderBy, OrderBy(sortDescriptors))
|
||||
XCTAssertEqual(orderBy, OrderBy(.Ascending("key1"), .Descending("key2")))
|
||||
@@ -101,8 +101,8 @@ final class OrderByTests: XCTestCase {
|
||||
orderBy,
|
||||
OrderBy(
|
||||
[
|
||||
NSSortDescriptor(key: "key1", ascending: false),
|
||||
NSSortDescriptor(key: "key2", ascending: false)
|
||||
SortDescriptor(key: "key1", ascending: false),
|
||||
SortDescriptor(key: "key2", ascending: false)
|
||||
]
|
||||
)
|
||||
)
|
||||
@@ -115,8 +115,8 @@ final class OrderByTests: XCTestCase {
|
||||
let sortKeys: [SortKey] = [.Ascending("key1"), .Descending("key2")]
|
||||
let orderBy = OrderBy(sortKeys)
|
||||
let sortDescriptors = [
|
||||
NSSortDescriptor(key: "key1", ascending: true),
|
||||
NSSortDescriptor(key: "key2", ascending: false)
|
||||
SortDescriptor(key: "key1", ascending: true),
|
||||
SortDescriptor(key: "key2", ascending: false)
|
||||
]
|
||||
XCTAssertEqual(orderBy, OrderBy(sortDescriptors))
|
||||
XCTAssertEqual(orderBy, OrderBy(.Ascending("key1"), .Descending("key2")))
|
||||
@@ -124,8 +124,8 @@ final class OrderByTests: XCTestCase {
|
||||
orderBy,
|
||||
OrderBy(
|
||||
[
|
||||
NSSortDescriptor(key: "key1", ascending: false),
|
||||
NSSortDescriptor(key: "key2", ascending: false)
|
||||
SortDescriptor(key: "key1", ascending: false),
|
||||
SortDescriptor(key: "key2", ascending: false)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
@@ -49,7 +49,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.ObjectID())
|
||||
switch term {
|
||||
|
||||
case ._Attribute(let key):
|
||||
case ._attribute(let key):
|
||||
XCTAssertEqual(key, "attribute")
|
||||
|
||||
default:
|
||||
@@ -68,7 +68,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.ObjectID())
|
||||
switch term {
|
||||
|
||||
case ._Attribute(let key):
|
||||
case ._attribute(let key):
|
||||
XCTAssertEqual(key, "attribute")
|
||||
|
||||
default:
|
||||
@@ -94,7 +94,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.ObjectID())
|
||||
switch term {
|
||||
|
||||
case ._Aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
case ._aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
XCTAssertEqual(function, "average:")
|
||||
XCTAssertEqual(keyPath, "attribute")
|
||||
XCTAssertEqual(alias, "average(attribute)")
|
||||
@@ -118,7 +118,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.ObjectID())
|
||||
switch term {
|
||||
|
||||
case ._Aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
case ._aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
XCTAssertEqual(function, "average:")
|
||||
XCTAssertEqual(keyPath, "attribute")
|
||||
XCTAssertEqual(alias, "alias")
|
||||
@@ -147,7 +147,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.ObjectID())
|
||||
switch term {
|
||||
|
||||
case ._Aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
case ._aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
XCTAssertEqual(function, "count:")
|
||||
XCTAssertEqual(keyPath, "attribute")
|
||||
XCTAssertEqual(alias, "count(attribute)")
|
||||
@@ -171,7 +171,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.ObjectID())
|
||||
switch term {
|
||||
|
||||
case ._Aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
case ._aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
XCTAssertEqual(function, "count:")
|
||||
XCTAssertEqual(keyPath, "attribute")
|
||||
XCTAssertEqual(alias, "alias")
|
||||
@@ -200,7 +200,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.ObjectID())
|
||||
switch term {
|
||||
|
||||
case ._Aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
case ._aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
XCTAssertEqual(function, "max:")
|
||||
XCTAssertEqual(keyPath, "attribute")
|
||||
XCTAssertEqual(alias, "max(attribute)")
|
||||
@@ -224,7 +224,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.ObjectID())
|
||||
switch term {
|
||||
|
||||
case ._Aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
case ._aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
XCTAssertEqual(function, "max:")
|
||||
XCTAssertEqual(keyPath, "attribute")
|
||||
XCTAssertEqual(alias, "alias")
|
||||
@@ -253,7 +253,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.ObjectID())
|
||||
switch term {
|
||||
|
||||
case ._Aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
case ._aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
XCTAssertEqual(function, "min:")
|
||||
XCTAssertEqual(keyPath, "attribute")
|
||||
XCTAssertEqual(alias, "min(attribute)")
|
||||
@@ -277,7 +277,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.ObjectID())
|
||||
switch term {
|
||||
|
||||
case ._Aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
case ._aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
XCTAssertEqual(function, "min:")
|
||||
XCTAssertEqual(keyPath, "attribute")
|
||||
XCTAssertEqual(alias, "alias")
|
||||
@@ -306,7 +306,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.ObjectID())
|
||||
switch term {
|
||||
|
||||
case ._Aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
case ._aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
XCTAssertEqual(function, "sum:")
|
||||
XCTAssertEqual(keyPath, "attribute")
|
||||
XCTAssertEqual(alias, "sum(attribute)")
|
||||
@@ -330,7 +330,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.ObjectID())
|
||||
switch term {
|
||||
|
||||
case ._Aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
case ._aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
XCTAssertEqual(function, "sum:")
|
||||
XCTAssertEqual(keyPath, "attribute")
|
||||
XCTAssertEqual(alias, "alias")
|
||||
@@ -358,7 +358,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.Sum("attribute"))
|
||||
switch term {
|
||||
|
||||
case ._Identity(let alias, let nativeType):
|
||||
case ._identity(let alias, let nativeType):
|
||||
XCTAssertEqual(alias, "objectID")
|
||||
XCTAssertTrue(nativeType == .ObjectIDAttributeType)
|
||||
|
||||
@@ -380,7 +380,7 @@ final class SelectTests: XCTestCase {
|
||||
XCTAssertNotEqual(term, SelectTerm.Sum("attribute"))
|
||||
switch term {
|
||||
|
||||
case ._Identity(let alias, let nativeType):
|
||||
case ._identity(let alias, let nativeType):
|
||||
XCTAssertEqual(alias, "alias")
|
||||
XCTAssertTrue(nativeType == .ObjectIDAttributeType)
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class SetupTests: BaseTestCase {
|
||||
|
||||
do {
|
||||
|
||||
let model = NSManagedObjectModel.mergedModelFromBundles([NSBundle(forClass: self.dynamicType)])!
|
||||
let model = NSManagedObjectModel.mergedModelFromBundles([Bundle(forClass: self.dynamicType)])!
|
||||
|
||||
let stack = DataStack(model: model, migrationChain: nil)
|
||||
XCTAssertEqual(stack.coordinator.managedObjectModel, model)
|
||||
@@ -60,7 +60,7 @@ class SetupTests: BaseTestCase {
|
||||
|
||||
DataStack(
|
||||
modelName: "Model",
|
||||
bundle: NSBundle(forClass: self.dynamicType),
|
||||
bundle: Bundle(forClass: self.dynamicType),
|
||||
migrationChain: migrationChain
|
||||
)
|
||||
}
|
||||
@@ -77,7 +77,7 @@ class SetupTests: BaseTestCase {
|
||||
|
||||
let stack = DataStack(
|
||||
modelName: "Model",
|
||||
bundle: NSBundle(forClass: self.dynamicType)
|
||||
bundle: Bundle(forClass: self.dynamicType)
|
||||
)
|
||||
do {
|
||||
|
||||
@@ -132,7 +132,7 @@ class SetupTests: BaseTestCase {
|
||||
|
||||
let stack = DataStack(
|
||||
modelName: "Model",
|
||||
bundle: NSBundle(forClass: self.dynamicType)
|
||||
bundle: Bundle(forClass: self.dynamicType)
|
||||
)
|
||||
do {
|
||||
|
||||
@@ -154,7 +154,7 @@ class SetupTests: BaseTestCase {
|
||||
let sqliteStore = SQLiteStore(
|
||||
fileName: "ConfigStore1.sqlite",
|
||||
configuration: "Config1",
|
||||
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||
localStorageOptions: .recreateStoreOnModelMismatch
|
||||
)
|
||||
do {
|
||||
|
||||
@@ -173,7 +173,7 @@ class SetupTests: BaseTestCase {
|
||||
let sqliteStore = SQLiteStore(
|
||||
fileName: "ConfigStore2.sqlite",
|
||||
configuration: "Config2",
|
||||
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||
localStorageOptions: .recreateStoreOnModelMismatch
|
||||
)
|
||||
do {
|
||||
|
||||
@@ -194,7 +194,7 @@ class SetupTests: BaseTestCase {
|
||||
|
||||
let stack = DataStack(
|
||||
modelName: "Model",
|
||||
bundle: NSBundle(forClass: self.dynamicType)
|
||||
bundle: Bundle(forClass: self.dynamicType)
|
||||
)
|
||||
do {
|
||||
|
||||
@@ -216,7 +216,7 @@ class SetupTests: BaseTestCase {
|
||||
let sqliteStore = SQLiteStore(
|
||||
fileName: "ConfigStore1.sqlite",
|
||||
configuration: "Config1",
|
||||
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||
localStorageOptions: .recreateStoreOnModelMismatch
|
||||
)
|
||||
do {
|
||||
|
||||
@@ -235,7 +235,7 @@ class SetupTests: BaseTestCase {
|
||||
let sqliteStore = SQLiteStore(
|
||||
fileName: "ConfigStore2.sqlite",
|
||||
configuration: "Config2",
|
||||
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||
localStorageOptions: .recreateStoreOnModelMismatch
|
||||
)
|
||||
do {
|
||||
|
||||
|
||||
@@ -57,22 +57,21 @@ final class StorageInterfaceTests: XCTestCase {
|
||||
#if os(tvOS)
|
||||
let systemDirectorySearchPath = NSSearchPathDirectory.CachesDirectory
|
||||
#else
|
||||
let systemDirectorySearchPath = NSSearchPathDirectory.ApplicationSupportDirectory
|
||||
let systemDirectorySearchPath = FileManager.SearchPathDirectory.applicationSupportDirectory
|
||||
#endif
|
||||
|
||||
let defaultSystemDirectory = NSFileManager
|
||||
.defaultManager()
|
||||
.URLsForDirectory(systemDirectorySearchPath, inDomains: .UserDomainMask).first!
|
||||
let defaultSystemDirectory = FileManager.default
|
||||
.urlsForDirectory(systemDirectorySearchPath, inDomains: .userDomainMask).first!
|
||||
|
||||
let defaultRootDirectory = defaultSystemDirectory.URLByAppendingPathComponent(
|
||||
NSBundle.mainBundle().bundleIdentifier ?? "com.CoreStore.DataStack",
|
||||
let defaultRootDirectory = try! defaultSystemDirectory.appendingPathComponent(
|
||||
Bundle.main.bundleIdentifier ?? "com.CoreStore.DataStack",
|
||||
isDirectory: true
|
||||
)
|
||||
let applicationName = (NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleName") as? String) ?? "CoreData"
|
||||
let applicationName = (Bundle.main.objectForInfoDictionaryKey("CFBundleName") as? String) ?? "CoreData"
|
||||
|
||||
let defaultFileURL = defaultRootDirectory
|
||||
.URLByAppendingPathComponent(applicationName, isDirectory: false)
|
||||
.URLByAppendingPathExtension("sqlite")
|
||||
let defaultFileURL = try! defaultRootDirectory
|
||||
.appendingPathComponent(applicationName, isDirectory: false)
|
||||
.appendingPathExtension("sqlite")
|
||||
|
||||
XCTAssertEqual(SQLiteStore.defaultRootDirectory, defaultRootDirectory)
|
||||
XCTAssertEqual(SQLiteStore.defaultFileURL, defaultFileURL)
|
||||
@@ -87,23 +86,23 @@ final class StorageInterfaceTests: XCTestCase {
|
||||
XCTAssertEqual(store.storeOptions, [NSSQLitePragmasOption: ["journal_mode": "WAL"]] as NSDictionary)
|
||||
|
||||
XCTAssertEqual(store.fileURL, SQLiteStore.defaultFileURL)
|
||||
XCTAssertEqual(store.mappingModelBundles, NSBundle.allBundles())
|
||||
XCTAssertEqual(store.mappingModelBundles, Bundle.allBundles())
|
||||
XCTAssertEqual(store.localStorageOptions, [.None])
|
||||
}
|
||||
|
||||
@objc
|
||||
dynamic func test_ThatFileURLSQLiteStores_ConfigureCorrectly() {
|
||||
|
||||
let fileURL = NSURL(fileURLWithPath: NSTemporaryDirectory())
|
||||
.URLByAppendingPathComponent(NSUUID().UUIDString, isDirectory: false)
|
||||
.URLByAppendingPathExtension("db")
|
||||
let bundles = [NSBundle(forClass: self.dynamicType)]
|
||||
let fileURL = try! URL(fileURLWithPath: NSTemporaryDirectory())
|
||||
.appendingPathComponent(UUID().uuidString, isDirectory: false)
|
||||
.appendingPathExtension("db")
|
||||
let bundles = [Bundle(for: self.dynamicType)]
|
||||
|
||||
let store = SQLiteStore(
|
||||
fileURL: fileURL,
|
||||
configuration: "config1",
|
||||
mappingModelBundles: bundles,
|
||||
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||
localStorageOptions: .recreateStoreOnModelMismatch
|
||||
)
|
||||
XCTAssertEqual(store.dynamicType.storeType, NSSQLiteStoreType)
|
||||
XCTAssertEqual(store.configuration, "config1")
|
||||
@@ -111,20 +110,20 @@ final class StorageInterfaceTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(store.fileURL, fileURL)
|
||||
XCTAssertEqual(store.mappingModelBundles, bundles)
|
||||
XCTAssertEqual(store.localStorageOptions, [.RecreateStoreOnModelMismatch])
|
||||
XCTAssertEqual(store.localStorageOptions, [.recreateStoreOnModelMismatch])
|
||||
}
|
||||
|
||||
@objc
|
||||
dynamic func test_ThatFileNameSQLiteStores_ConfigureCorrectly() {
|
||||
|
||||
let fileName = NSUUID().UUIDString + ".db"
|
||||
let bundles = [NSBundle(forClass: self.dynamicType)]
|
||||
let fileName = UUID().uuidString + ".db"
|
||||
let bundles = [Bundle(for: self.dynamicType)]
|
||||
|
||||
let store = SQLiteStore(
|
||||
fileName: fileName,
|
||||
configuration: "config1",
|
||||
mappingModelBundles: bundles,
|
||||
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||
localStorageOptions: .recreateStoreOnModelMismatch
|
||||
)
|
||||
XCTAssertEqual(store.dynamicType.storeType, NSSQLiteStoreType)
|
||||
XCTAssertEqual(store.configuration, "config1")
|
||||
@@ -133,7 +132,7 @@ final class StorageInterfaceTests: XCTestCase {
|
||||
XCTAssertEqual(store.fileURL.URLByDeletingLastPathComponent, SQLiteStore.defaultRootDirectory)
|
||||
XCTAssertEqual(store.fileURL.lastPathComponent, fileName)
|
||||
XCTAssertEqual(store.mappingModelBundles, bundles)
|
||||
XCTAssertEqual(store.localStorageOptions, [.RecreateStoreOnModelMismatch])
|
||||
XCTAssertEqual(store.localStorageOptions, [.recreateStoreOnModelMismatch])
|
||||
}
|
||||
|
||||
@objc
|
||||
@@ -142,12 +141,12 @@ final class StorageInterfaceTests: XCTestCase {
|
||||
#if os(tvOS)
|
||||
let systemDirectorySearchPath = NSSearchPathDirectory.CachesDirectory
|
||||
#else
|
||||
let systemDirectorySearchPath = NSSearchPathDirectory.ApplicationSupportDirectory
|
||||
let systemDirectorySearchPath = FileManager.SearchPathDirectory.applicationSupportDirectory
|
||||
#endif
|
||||
|
||||
let legacyDefaultRootDirectory = NSFileManager.defaultManager().URLsForDirectory(
|
||||
let legacyDefaultRootDirectory = FileManager.default.urlsForDirectory(
|
||||
systemDirectorySearchPath,
|
||||
inDomains: .UserDomainMask
|
||||
inDomains: .userDomainMask
|
||||
).first!
|
||||
|
||||
let legacyDefaultFileURL = legacyDefaultRootDirectory
|
||||
@@ -167,23 +166,23 @@ final class StorageInterfaceTests: XCTestCase {
|
||||
XCTAssertEqual(store.storeOptions, [NSSQLitePragmasOption: ["journal_mode": "WAL"]] as NSDictionary)
|
||||
|
||||
XCTAssertEqual(store.fileURL, LegacySQLiteStore.defaultFileURL)
|
||||
XCTAssertEqual(store.mappingModelBundles, NSBundle.allBundles())
|
||||
XCTAssertEqual(store.mappingModelBundles, Bundle.allBundles())
|
||||
XCTAssertEqual(store.localStorageOptions, [.None])
|
||||
}
|
||||
|
||||
@objc
|
||||
dynamic func test_ThatFileURLLegacySQLiteStores_ConfigureCorrectly() {
|
||||
|
||||
let fileURL = NSURL(fileURLWithPath: NSTemporaryDirectory())
|
||||
.URLByAppendingPathComponent(NSUUID().UUIDString, isDirectory: false)
|
||||
.URLByAppendingPathExtension("db")
|
||||
let bundles = [NSBundle(forClass: self.dynamicType)]
|
||||
let fileURL = try! URL(fileURLWithPath: NSTemporaryDirectory())
|
||||
.appendingPathComponent(UUID().uuidString, isDirectory: false)
|
||||
.appendingPathExtension("db")
|
||||
let bundles = [Bundle(for: self.dynamicType)]
|
||||
|
||||
let store = LegacySQLiteStore(
|
||||
fileURL: fileURL,
|
||||
configuration: "config1",
|
||||
mappingModelBundles: bundles,
|
||||
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||
localStorageOptions: .recreateStoreOnModelMismatch
|
||||
)
|
||||
XCTAssertEqual(store.dynamicType.storeType, NSSQLiteStoreType)
|
||||
XCTAssertEqual(store.configuration, "config1")
|
||||
@@ -191,20 +190,20 @@ final class StorageInterfaceTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(store.fileURL, fileURL)
|
||||
XCTAssertEqual(store.mappingModelBundles, bundles)
|
||||
XCTAssertEqual(store.localStorageOptions, [.RecreateStoreOnModelMismatch])
|
||||
XCTAssertEqual(store.localStorageOptions, [.recreateStoreOnModelMismatch])
|
||||
}
|
||||
|
||||
@objc
|
||||
dynamic func test_ThatFileNameLegacySQLiteStores_ConfigureCorrectly() {
|
||||
|
||||
let fileName = NSUUID().UUIDString + ".db"
|
||||
let bundles = [NSBundle(forClass: self.dynamicType)]
|
||||
let fileName = UUID().uuidString + ".db"
|
||||
let bundles = [Bundle(for: self.dynamicType)]
|
||||
|
||||
let store = LegacySQLiteStore(
|
||||
fileName: fileName,
|
||||
configuration: "config1",
|
||||
mappingModelBundles: bundles,
|
||||
localStorageOptions: .RecreateStoreOnModelMismatch
|
||||
localStorageOptions: .recreateStoreOnModelMismatch
|
||||
)
|
||||
XCTAssertEqual(store.dynamicType.storeType, NSSQLiteStoreType)
|
||||
XCTAssertEqual(store.configuration, "config1")
|
||||
@@ -213,6 +212,6 @@ final class StorageInterfaceTests: XCTestCase {
|
||||
XCTAssertEqual(store.fileURL.URLByDeletingLastPathComponent, LegacySQLiteStore.defaultRootDirectory)
|
||||
XCTAssertEqual(store.fileURL.lastPathComponent, fileName)
|
||||
XCTAssertEqual(store.mappingModelBundles, bundles)
|
||||
XCTAssertEqual(store.localStorageOptions, [.RecreateStoreOnModelMismatch])
|
||||
XCTAssertEqual(store.localStorageOptions, [.recreateStoreOnModelMismatch])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ class TestEntity1: NSManagedObject {
|
||||
@NSManaged var testEntityID: NSNumber?
|
||||
@NSManaged var testString: String?
|
||||
@NSManaged var testNumber: NSNumber?
|
||||
@NSManaged var testDate: NSDate?
|
||||
@NSManaged var testDate: Date?
|
||||
@NSManaged var testBoolean: NSNumber?
|
||||
@NSManaged var testDecimal: NSDecimalNumber?
|
||||
@NSManaged var testData: NSData?
|
||||
@NSManaged var testData: Data?
|
||||
@NSManaged var testNil: String?
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ class TestEntity2: NSManagedObject {
|
||||
@NSManaged var testEntityID: NSNumber?
|
||||
@NSManaged var testString: String?
|
||||
@NSManaged var testNumber: NSNumber?
|
||||
@NSManaged var testDate: NSDate?
|
||||
@NSManaged var testDate: Date?
|
||||
@NSManaged var testBoolean: NSNumber?
|
||||
@NSManaged var testDecimal: NSDecimalNumber?
|
||||
@NSManaged var testData: NSData?
|
||||
@NSManaged var testData: Data?
|
||||
@NSManaged var testNil: String?
|
||||
}
|
||||
|
||||
@@ -651,7 +651,7 @@ final class TransactionTests: BaseTestCase {
|
||||
|
||||
transaction.delete(object)
|
||||
|
||||
GCDQueue.Main.async {
|
||||
GCDQueue.main.async {
|
||||
|
||||
XCTAssertEqual(stack.fetchCount(From(TestEntity1)), 1)
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ final class TweakTests: XCTestCase {
|
||||
@objc
|
||||
dynamic func test_ThatTweakClauses_ApplyToFetchRequestsCorrectly() {
|
||||
|
||||
let predicate = NSPredicate(format: "%K == %@", "key", "value")
|
||||
let predicate = Predicate(format: "%K == %@", "key", "value")
|
||||
let tweak = Tweak {
|
||||
|
||||
$0.fetchOffset = 100
|
||||
|
||||
@@ -41,18 +41,18 @@ final class WhereTests: XCTestCase {
|
||||
let whereClause = Where()
|
||||
XCTAssertEqual(whereClause, Where(true))
|
||||
XCTAssertNotEqual(whereClause, Where(false))
|
||||
XCTAssertEqual(whereClause.predicate, NSPredicate(value: true))
|
||||
XCTAssertEqual(whereClause.predicate, Predicate(value: true))
|
||||
}
|
||||
do {
|
||||
|
||||
let whereClause = Where(true)
|
||||
XCTAssertEqual(whereClause, Where())
|
||||
XCTAssertNotEqual(whereClause, Where(false))
|
||||
XCTAssertEqual(whereClause.predicate, NSPredicate(value: true))
|
||||
XCTAssertEqual(whereClause.predicate, Predicate(value: true))
|
||||
}
|
||||
do {
|
||||
|
||||
let predicate = NSPredicate(format: "%K == %@", "key", "value")
|
||||
let predicate = Predicate(format: "%K == %@", "key", "value")
|
||||
let whereClause = Where(predicate)
|
||||
XCTAssertEqual(whereClause, Where(predicate))
|
||||
XCTAssertEqual(whereClause.predicate, predicate)
|
||||
@@ -60,28 +60,28 @@ final class WhereTests: XCTestCase {
|
||||
do {
|
||||
|
||||
let whereClause = Where("%K == %@", "key", "value")
|
||||
let predicate = NSPredicate(format: "%K == %@", "key", "value")
|
||||
let predicate = Predicate(format: "%K == %@", "key", "value")
|
||||
XCTAssertEqual(whereClause, Where(predicate))
|
||||
XCTAssertEqual(whereClause.predicate, predicate)
|
||||
}
|
||||
do {
|
||||
|
||||
let whereClause = Where("%K == %@", argumentArray: ["key", "value"])
|
||||
let predicate = NSPredicate(format: "%K == %@", "key", "value")
|
||||
let predicate = Predicate(format: "%K == %@", "key", "value")
|
||||
XCTAssertEqual(whereClause, Where(predicate))
|
||||
XCTAssertEqual(whereClause.predicate, predicate)
|
||||
}
|
||||
do {
|
||||
|
||||
let whereClause = Where("key", isEqualTo: "value")
|
||||
let predicate = NSPredicate(format: "%K == %@", "key", "value")
|
||||
let predicate = Predicate(format: "%K == %@", "key", "value")
|
||||
XCTAssertEqual(whereClause, Where(predicate))
|
||||
XCTAssertEqual(whereClause.predicate, predicate)
|
||||
}
|
||||
do {
|
||||
|
||||
let whereClause = Where("key", isMemberOf: ["value1", "value2", "value3"])
|
||||
let predicate = NSPredicate(format: "%K IN %@", "key", ["value1", "value2", "value3"])
|
||||
let predicate = Predicate(format: "%K IN %@", "key", ["value1", "value2", "value3"])
|
||||
XCTAssertEqual(whereClause, Where(predicate))
|
||||
XCTAssertEqual(whereClause.predicate, predicate)
|
||||
}
|
||||
@@ -97,7 +97,7 @@ final class WhereTests: XCTestCase {
|
||||
do {
|
||||
|
||||
let notWhere = !whereClause1
|
||||
let notPredicate = NSCompoundPredicate(
|
||||
let notPredicate = CompoundPredicate(
|
||||
type: .NotPredicateType,
|
||||
subpredicates: [whereClause1.predicate]
|
||||
)
|
||||
@@ -107,10 +107,10 @@ final class WhereTests: XCTestCase {
|
||||
do {
|
||||
|
||||
let andWhere = whereClause1 && whereClause2 && whereClause3
|
||||
let andPredicate = NSCompoundPredicate(
|
||||
let andPredicate = CompoundPredicate(
|
||||
type: .AndPredicateType,
|
||||
subpredicates: [
|
||||
NSCompoundPredicate(
|
||||
CompoundPredicate(
|
||||
type: .AndPredicateType,
|
||||
subpredicates: [whereClause1.predicate, whereClause2.predicate]
|
||||
),
|
||||
@@ -123,10 +123,10 @@ final class WhereTests: XCTestCase {
|
||||
do {
|
||||
|
||||
let orWhere = whereClause1 || whereClause2 || whereClause3
|
||||
let orPredicate = NSCompoundPredicate(
|
||||
let orPredicate = CompoundPredicate(
|
||||
type: .OrPredicateType,
|
||||
subpredicates: [
|
||||
NSCompoundPredicate(
|
||||
CompoundPredicate(
|
||||
type: .OrPredicateType,
|
||||
subpredicates: [whereClause1.predicate, whereClause2.predicate]
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user