diff --git a/CHANGELOG.md b/CHANGELOG.md index 11ef4605..5bfc4714 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file. * Support for fine-grained notifications in Realm * Update to Realm 0.103.1 and higher. +### Fixed + +* Fixed https://github.com/DenHeadless/DTTableViewManager/issues/34, thanks @orkenstein, @andrewSvsg + ## [2.5.1](https://github.com/DenHeadless/DTModelStorage/releases/tag/2.5.1) ## Changed diff --git a/Source/Core/UIReactions.swift b/Source/Core/UIReactions.swift index dd1414f9..8f3b9778 100644 --- a/Source/Core/UIReactions.swift +++ b/Source/Core/UIReactions.swift @@ -82,7 +82,7 @@ public extension RangeReplaceableCollectionType where Self.Generator.Element == func reactionsOfType(type: UIReactionType, forView view: Any) -> [UIReaction] { return self.filter({ reaction -> Bool in guard let unwrappedView = RuntimeHelper.recursivelyUnwrapAnyValue(view) else { return false } - return reaction.reactionType == type && reaction.viewClass == unwrappedView.dynamicType + return reaction.reactionType == type && String(reaction.viewClass) == String(unwrappedView.dynamicType) }) } } diff --git a/Tests/Realm/RealmStorageTestCase.swift b/Tests/Realm/RealmStorageTestCase.swift index 43f8d021..69217bf4 100644 --- a/Tests/Realm/RealmStorageTestCase.swift +++ b/Tests/Realm/RealmStorageTestCase.swift @@ -23,7 +23,10 @@ func delay(delay:Double, _ closure:()->()) { class RealmStorageTestCase: XCTestCase { - let realm = try! Realm() + let realm = { Void -> Realm in + let configuration = Realm.Configuration(fileURL: nil, inMemoryIdentifier: "foo") + return try! Realm(configuration: configuration) + }() var storage: RealmStorage! override func setUp() { @@ -63,66 +66,66 @@ class RealmStorageTestCase: XCTestCase { expect(storageObserver.storageNeedsReloadingFlag) == true } -// func testInsertNotificationIsHandled() { -// let updateObserver = StorageUpdatesObserver() -// storage.delegate = updateObserver -// let results = realm.objects(Dog) -// storage.addSectionWithResults(results) -// -// addDogNamed("Rex") -// -// expect((self.storage.itemAtIndexPath(indexPath(0, 0)) as? Dog)?.name) == "Rex" -// -// try! realm.write { -// let dog = Dog() -// dog.name = "Rexxar" -// realm.add(dog) -// } -// expect(updateObserver.update?.insertedRowIndexPaths).toEventually(equal(Set([indexPath(1, 0), indexPath(0, 0)]))) -// } - - // MARK: - TODO make these tests run somehow, right now they are both failing, however when run apart from entire test case - they are successful. - -// func testDeleteNotificationIsHandled() { -// let updateObserver = StorageUpdatesObserver() -// storage.delegate = updateObserver -// let results = realm.objects(Dog) -// storage.addSectionWithResults(results) -// -// var dog: Dog! -// try! realm.write { -// dog = Dog() -// dog.name = "Rexxar" -// realm.add(dog) -// } -// -// delay(0) { -// try! self.realm.write { -// self.realm.delete(dog) -// } -// } -// expect(updateObserver.update?.deletedRowIndexPaths).toEventually(equal(Set([indexPath(0, 0)]))) -// } -// -// func testUpdateNotificationIsHandled() { -// let updateObserver = StorageUpdatesObserver() -// storage.delegate = updateObserver -// let results = realm.objects(Dog) -// storage.addSectionWithResults(results) -// -// var dog: Dog! -// try! realm.write { -// dog = Dog() -// dog.name = "Rexxar" -// realm.add(dog) -// } -// delay(0) { -// try! self.realm.write { -// dog.name = "Rex" -// } -// } -// expect(updateObserver.update?.updatedRowIndexPaths).toEventually(equal(Set([indexPath(0, 0)]))) -// } + func testInsertNotificationIsHandled() { + let updateObserver = StorageUpdatesObserver() + storage.delegate = updateObserver + let results = realm.objects(Dog) + storage.addSectionWithResults(results) + + addDogNamed("Rex") + + expect((self.storage.itemAtIndexPath(indexPath(0, 0)) as? Dog)?.name) == "Rex" + + delay(0.1) { + try! self.realm.write { + let dog = Dog() + dog.name = "Rexxar" + self.realm.add(dog) + } + } + expect(updateObserver.update?.insertedRowIndexPaths).toEventually(equal(Set([indexPath(1, 0)]))) + } + + func testDeleteNotificationIsHandled() { + let updateObserver = StorageUpdatesObserver() + storage.delegate = updateObserver + let results = realm.objects(Dog) + storage.addSectionWithResults(results) + + var dog: Dog! + try! realm.write { + dog = Dog() + dog.name = "Rexxar" + realm.add(dog) + } + + delay(0.1) { + try! self.realm.write { + self.realm.delete(dog) + } + } + expect(updateObserver.update?.deletedRowIndexPaths).toEventually(equal(Set([indexPath(0, 0)]))) + } + + func testUpdateNotificationIsHandled() { + let updateObserver = StorageUpdatesObserver() + storage.delegate = updateObserver + let results = realm.objects(Dog) + storage.addSectionWithResults(results) + + var dog: Dog! + try! realm.write { + dog = Dog() + dog.name = "Rexxar" + realm.add(dog) + } + delay(0.1) { + try! self.realm.write { + dog.name = "Rex" + } + } + expect(updateObserver.update?.updatedRowIndexPaths).toEventually(equal(Set([indexPath(0, 0)]))) + } func testStorageHasSingleSection() { addDogNamed("Rex")