From b9e550df0c5f34399b9176f8cdfabc77ccded3ab Mon Sep 17 00:00:00 2001 From: Ben Kreeger Date: Fri, 22 Mar 2019 16:53:04 -0500 Subject: [PATCH] Fix issues with previous PR (#25) --- Example/AutomaticViewController.swift | 2 +- Flapjack/Core/DataSource.swift | 3 ++- Flapjack/CoreData/SingleCoreDataSource.swift | 2 +- Tests/CoreData/CoreDataSourceTests.swift | 22 +++++++++---------- .../CoreData/SingleCoreDataSourceTests.swift | 20 ++++++++--------- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Example/AutomaticViewController.swift b/Example/AutomaticViewController.swift index 441d644..c52d6a8 100644 --- a/Example/AutomaticViewController.swift +++ b/Example/AutomaticViewController.swift @@ -26,7 +26,7 @@ class AutomaticViewController: UIViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - dataSource.execute() + dataSource.startListening() } diff --git a/Flapjack/Core/DataSource.swift b/Flapjack/Core/DataSource.swift index 6137df4..6366c87 100644 --- a/Flapjack/Core/DataSource.swift +++ b/Flapjack/Core/DataSource.swift @@ -87,7 +87,8 @@ public protocol DataSource { /** This stub implementation of `DataSource` makes it relatively easy to build your own by only having to implement a few short properties/functions, especially if you're managing a non-grouped set of objects. Simply implement `allObjects` - and `execute()`, make sure you call `onChange` when the data set changes, and everything else should hinge on that. + and `startListening()`, make sure you call `onChange` when the data set changes, and everything else should hinge on + that. */ public extension DataSource { /// If not implemented, this returns the `count` of `allObjects`. diff --git a/Flapjack/CoreData/SingleCoreDataSource.swift b/Flapjack/CoreData/SingleCoreDataSource.swift index 63162c9..9312c2e 100644 --- a/Flapjack/CoreData/SingleCoreDataSource.swift +++ b/Flapjack/CoreData/SingleCoreDataSource.swift @@ -145,7 +145,7 @@ public class SingleCoreDataSource: NSObject, Si // Store our newly-minted context, and refetch. self.context = newContext - execute() + startListening() } @objc diff --git a/Tests/CoreData/CoreDataSourceTests.swift b/Tests/CoreData/CoreDataSourceTests.swift index 70237b5..4aaf57f 100644 --- a/Tests/CoreData/CoreDataSourceTests.swift +++ b/Tests/CoreData/CoreDataSourceTests.swift @@ -56,7 +56,7 @@ class CoreDataSourceTests: XCTestCase { func testObjectsArePopulatedAfterExecution() { let dataSource = CoreDataSource(dataAccess: dataAccess) - dataSource.execute() + dataSource.startListening() XCTAssertEqual(dataSource.numberOfObjects, 5) XCTAssertEqual(dataSource.allObjects.count, 5) XCTAssertEqual(dataSource.numberOfSections, 1) @@ -88,7 +88,7 @@ class CoreDataSourceTests: XCTestCase { XCTAssertEqual(items.count, 2) XCTAssertEqual(sections.count, 0) } - dataSource.execute() + dataSource.startListening() _ = dataAccess.mainContext.create(MockEntity.self, attributes: ["someProperty": "someValue alpha"]) dataAccess.mainContext.destroy(object: entityOne) dataAccess.mainContext.persist() @@ -100,7 +100,7 @@ class CoreDataSourceTests: XCTestCase { func testFilteredFetchOnlyReturnsThoseMatching() { let dataSource = CoreDataSource(dataAccess: dataAccess, attributes: ["someProperty": "someValue alpha"]) - dataSource.execute() + dataSource.startListening() XCTAssertEqual(dataSource.numberOfObjects, 2) XCTAssertEqual(dataSource.allObjects.count, 2) XCTAssertTrue(dataSource.allObjects.contains(entityOne)) @@ -111,7 +111,7 @@ class CoreDataSourceTests: XCTestCase { func testFilteredAutomaticallyUpdatesAllObjectsOnChange() { let dataSource = CoreDataSource(dataAccess: dataAccess, attributes: ["someProperty": "someValue alpha"]) - dataSource.execute() + dataSource.startListening() XCTAssertEqual(dataSource.numberOfObjects, 2) XCTAssertEqual(dataSource.allObjects.count, 2) @@ -123,7 +123,7 @@ class CoreDataSourceTests: XCTestCase { func testFilteredAutomaticallyUpdatesAllObjectsOnDestroy() { let dataSource = CoreDataSource(dataAccess: dataAccess, attributes: ["someProperty": "someValue alpha"]) - dataSource.execute() + dataSource.startListening() XCTAssertEqual(dataSource.numberOfObjects, 2) XCTAssertEqual(dataSource.allObjects.count, 2) dataAccess.mainContext.destroy(object: entityOne) @@ -134,7 +134,7 @@ class CoreDataSourceTests: XCTestCase { func testFilteredAutomaticallyIncludesNewMatchingObjects() { let dataSource = CoreDataSource(dataAccess: dataAccess, attributes: ["someProperty": "someValue alpha"]) - dataSource.execute() + dataSource.startListening() XCTAssertEqual(dataSource.numberOfObjects, 2) XCTAssertEqual(dataSource.allObjects.count, 2) @@ -150,7 +150,7 @@ class CoreDataSourceTests: XCTestCase { func testSortedReturnsObjectsInProperOrder() { let dataSource = CoreDataSource(dataAccess: dataAccess, sorters: [SortDescriptor("someProperty", ascending: false)]) - dataSource.execute() + dataSource.startListening() // entityOne and entityTwo could be in either position 1 or 2 XCTAssertEqual(dataSource.allObjects.first, entityFour) XCTAssertEqual(dataSource.allObjects.last, entityFive) @@ -158,7 +158,7 @@ class CoreDataSourceTests: XCTestCase { func testSortedReturnsObjectsInProperOrderEvenWithNewItemsOrChanges() { let dataSource = CoreDataSource(dataAccess: dataAccess, sorters: [SortDescriptor("someProperty", ascending: false)]) - dataSource.execute() + dataSource.startListening() XCTAssertEqual(dataSource.allObjects.first, entityFour) XCTAssertEqual(dataSource.allObjects.last, entityFive) @@ -184,7 +184,7 @@ class CoreDataSourceTests: XCTestCase { XCTAssertEqual(sections.count, 3) } - dataSource.execute() + dataSource.startListening() XCTAssertEqual(dataSource.numberOfObjects, 5) XCTAssertEqual(dataSource.numberOfSections, 4) @@ -207,7 +207,7 @@ class CoreDataSourceTests: XCTestCase { func testLimitedOnlyReturnsThoseFallingInUnderTheLimit() { let dataSource = CoreDataSource(dataAccess: dataAccess, sorters: [SortDescriptor("someProperty", ascending: false)], limit: 2) - dataSource.execute() + dataSource.startListening() XCTAssertEqual(dataSource.numberOfObjects, 2) XCTAssertEqual(dataSource.allObjects.count, 2) XCTAssertFalse(dataSource.allObjects.contains(entityOne)) @@ -219,7 +219,7 @@ class CoreDataSourceTests: XCTestCase { func testLimitedAutomaticallyUpdatesAllObjectsOnChange() { let dataSource = CoreDataSource(dataAccess: dataAccess, sorters: [SortDescriptor("someProperty", ascending: false)], limit: 2) - dataSource.execute() + dataSource.startListening() XCTAssertEqual(dataSource.numberOfObjects, 2) XCTAssertEqual(dataSource.allObjects.count, 2) diff --git a/Tests/CoreData/SingleCoreDataSourceTests.swift b/Tests/CoreData/SingleCoreDataSourceTests.swift index a9847bc..4481c09 100644 --- a/Tests/CoreData/SingleCoreDataSourceTests.swift +++ b/Tests/CoreData/SingleCoreDataSourceTests.swift @@ -46,11 +46,11 @@ class SingleCoreDataSourceTests: XCTestCase { func testExecutionFetchesRightAway() { XCTAssertNil(dataSource.object) - dataSource.execute() + dataSource.startListening() XCTAssertEqual(dataSource.object, entity) } - func testCoreDataNotificationNotPickedUpBeforeExecute() { + func testCoreDataNotificationNotPickedUpBeforestartListening() { let expect = expectation(description: "did change block") expect.isInverted = true dataSource.onChange = { object in @@ -68,7 +68,7 @@ class SingleCoreDataSourceTests: XCTestCase { dataSource.onChange = { object in expect.fulfill() } - dataSource.execute() + dataSource.startListening() waitForExpectations(timeout: 0.5) { XCTAssertNil($0) } } @@ -78,7 +78,7 @@ class SingleCoreDataSourceTests: XCTestCase { dataSource.onChange = { object in expect.fulfill() } - dataSource.execute() + dataSource.startListening() entity.someProperty = "some new value" dataAccess.mainContext.persist() waitForExpectations(timeout: 0.5) { XCTAssertNil($0) } @@ -90,7 +90,7 @@ class SingleCoreDataSourceTests: XCTestCase { dataSource.onChange = { object in expect.fulfill() } - dataSource.execute() + dataSource.startListening() entity.someProperty = "some new value" dataAccess.mainContext.processPendingChanges() waitForExpectations(timeout: 0.5) { XCTAssertNil($0) } @@ -105,7 +105,7 @@ class SingleCoreDataSourceTests: XCTestCase { dataSource.onChange = { object in expect.fulfill() } - dataSource.execute() + dataSource.startListening() entity.someProperty = "some new value" otherEntity.someProperty = "other other value" dataAccess.mainContext.persist() @@ -116,7 +116,7 @@ class SingleCoreDataSourceTests: XCTestCase { dataAccess.mainContext.destroy(object: entity) dataAccess.mainContext.persist() - dataSource.execute() + dataSource.startListening() XCTAssertNil(dataSource.object) } @@ -126,7 +126,7 @@ class SingleCoreDataSourceTests: XCTestCase { dataSource.onChange = { object in expect.fulfill() } - dataSource.execute() + dataSource.startListening() dataAccess.mainContext.destroy(object: entity) waitForExpectations(timeout: 0.5) { XCTAssertNil($0) } XCTAssertNil(dataSource.object) @@ -141,7 +141,7 @@ class SingleCoreDataSourceTests: XCTestCase { dataSource.onChange = { object in expect.fulfill() } - dataSource.execute() + dataSource.startListening() XCTAssertNil(dataSource.object) let newEntity = dataAccess.mainContext.create(MockEntity.self, attributes: attributes) @@ -159,7 +159,7 @@ class SingleCoreDataSourceTests: XCTestCase { dataSource.onChange = { object in expect.fulfill() } - dataSource.execute() + dataSource.startListening() entity.someProperty = "some new value" newEntity.someProperty = attributes["someProperty"]