From 8f50058d213ab20e5dfb8bd8e50cfecf42601e1b Mon Sep 17 00:00:00 2001 From: Reed Es Date: Sat, 1 Apr 2023 17:15:14 -0600 Subject: [PATCH] Improvement in fetch by UUID --- Sources/Entities/MCategory-fetch.swift | 2 +- Sources/Entities/MFoodGroup-fetch.swift | 2 +- Sources/Entities/MServing-fetch.swift | 2 +- Sources/Entities/ZCategory-fetch.swift | 2 +- Sources/Entities/ZServing-fetch.swift | 4 +-- Sources/Entities/ZServingRun-fetch.swift | 2 +- Tests/FetchByUuidTests.swift | 35 ++++++++++++++++++++++++ 7 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 Tests/FetchByUuidTests.swift diff --git a/Sources/Entities/MCategory-fetch.swift b/Sources/Entities/MCategory-fetch.swift index a63fe96..8a50bb8 100644 --- a/Sources/Entities/MCategory-fetch.swift +++ b/Sources/Entities/MCategory-fetch.swift @@ -15,7 +15,7 @@ import TrackerLib internal extension MCategory { static func getPredicate(archiveID: UUID) -> NSPredicate { - NSPredicate(format: "archiveID == %@", archiveID.uuidString) + NSPredicate(format: "archiveID == %@", archiveID as NSUUID) } } diff --git a/Sources/Entities/MFoodGroup-fetch.swift b/Sources/Entities/MFoodGroup-fetch.swift index a352950..0b1ccb0 100644 --- a/Sources/Entities/MFoodGroup-fetch.swift +++ b/Sources/Entities/MFoodGroup-fetch.swift @@ -19,7 +19,7 @@ public extension MFoodGroup { } static func getPredicate(categoryArchiveID: UUID, groupRaw: Int16) -> NSPredicate { - NSPredicate(format: "category.archiveID == %@ AND groupRaw == %i", categoryArchiveID.uuidString, groupRaw) + NSPredicate(format: "category.archiveID == %@ AND groupRaw == %i", categoryArchiveID as NSUUID, groupRaw) } } diff --git a/Sources/Entities/MServing-fetch.swift b/Sources/Entities/MServing-fetch.swift index 16d8436..e659646 100644 --- a/Sources/Entities/MServing-fetch.swift +++ b/Sources/Entities/MServing-fetch.swift @@ -19,7 +19,7 @@ public extension MServing { } static func getPredicate(categoryArchiveID: UUID, servingArchiveID: UUID) -> NSPredicate { - NSPredicate(format: "category.archiveID == %@ AND archiveID == %@", categoryArchiveID.uuidString, servingArchiveID.uuidString) + NSPredicate(format: "category.archiveID == %@ AND archiveID == %@", categoryArchiveID as NSUUID, servingArchiveID as NSUUID) } } diff --git a/Sources/Entities/ZCategory-fetch.swift b/Sources/Entities/ZCategory-fetch.swift index fd3ffe8..dab73bf 100644 --- a/Sources/Entities/ZCategory-fetch.swift +++ b/Sources/Entities/ZCategory-fetch.swift @@ -14,7 +14,7 @@ import TrackerLib internal extension ZCategory { static func getPredicate(categoryArchiveID: UUID) -> NSPredicate { - NSPredicate(format: "categoryArchiveID == %@", categoryArchiveID.uuidString) + NSPredicate(format: "categoryArchiveID == %@", categoryArchiveID as NSUUID) } } diff --git a/Sources/Entities/ZServing-fetch.swift b/Sources/Entities/ZServing-fetch.swift index b804c9a..d1fdd46 100644 --- a/Sources/Entities/ZServing-fetch.swift +++ b/Sources/Entities/ZServing-fetch.swift @@ -21,8 +21,8 @@ public extension ZServing { servingArchiveID: UUID) -> NSPredicate { NSPredicate(format: "zCategory.categoryArchiveID == %@ AND servingArchiveID == %@", - categoryArchiveID.uuidString, - servingArchiveID.uuidString) + categoryArchiveID as NSUUID, + servingArchiveID as NSUUID) } } diff --git a/Sources/Entities/ZServingRun-fetch.swift b/Sources/Entities/ZServingRun-fetch.swift index dea773d..d100c85 100644 --- a/Sources/Entities/ZServingRun-fetch.swift +++ b/Sources/Entities/ZServingRun-fetch.swift @@ -30,7 +30,7 @@ public extension ZServingRun { consumedTime: String) -> NSPredicate { NSPredicate(format: "zServing.servingArchiveID == %@ AND zDayRun.consumedDay == %@ AND consumedTime == %@", - servingArchiveID.uuidString, + servingArchiveID as NSUUID, consumedDay, consumedTime) } } diff --git a/Tests/FetchByUuidTests.swift b/Tests/FetchByUuidTests.swift new file mode 100644 index 0000000..0129dc6 --- /dev/null +++ b/Tests/FetchByUuidTests.swift @@ -0,0 +1,35 @@ +// +// FetchByUuidTests.swift +// +// Copyright 2023 OpenAlloc LLC +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. +// + +import CoreData + +import TrackerLib + +@testable import DcaltLib +import XCTest + +final class FetchByUuidTests: TestBase { + let categoryArchiveID = UUID() + + func testArchiveIdCaseDoesNotMatter() throws { + _ = MCategory.create(testContext, name: "blah", userOrder: 0, lastCalories: 0, archiveID: categoryArchiveID) + try testContext.save() + + XCTAssertNotNil(try MCategory.get(testContext, archiveID: categoryArchiveID)) + + let low = categoryArchiveID.uuidString.lowercased() + + XCTAssertNotNil(try MCategory.get(testContext, archiveID: UUID(uuidString: low)!)) + + let up = categoryArchiveID.uuidString.uppercased() + + XCTAssertNotNil(try MCategory.get(testContext, archiveID: UUID(uuidString: up)!)) + } +}