From c42692ca1f49dd905ed4777a34a589336659c1dc Mon Sep 17 00:00:00 2001 From: "cramsden@thoughtworks.com" Date: Thu, 30 Jun 2016 21:21:07 -0500 Subject: [PATCH 1/2] this is the branch with the first step of the solutions --- .../HelloRest.xcodeproj/project.pbxproj | 32 ++++++++++++++++ .../PeopleList/PeopleListViewController.swift | 5 ++- .../PeopleList/PeopleListViewModel.swift | 2 +- .../HelloRest/Services/PeopleService.swift | 13 +++++++ .../HelloRestSpecs/PeopleServiceMock.swift | 6 +++ .../HelloRestSpecs/PeopleServiceTests.swift | 38 +++++++++++++++++++ 6 files changed, 93 insertions(+), 3 deletions(-) diff --git a/RestExample/HelloRest/HelloRest.xcodeproj/project.pbxproj b/RestExample/HelloRest/HelloRest.xcodeproj/project.pbxproj index 5f2eb0f..581ce8c 100644 --- a/RestExample/HelloRest/HelloRest.xcodeproj/project.pbxproj +++ b/RestExample/HelloRest/HelloRest.xcodeproj/project.pbxproj @@ -213,6 +213,7 @@ isa = PBXNativeTarget; buildConfigurationList = AD72BAE81D1CA73B00C230B9 /* Build configuration list for PBXNativeTarget "HelloRestSpecs" */; buildPhases = ( + 99F73E9884FFFC5AB76BBC29 /* [CP] Check Pods Manifest.lock */, EAE3D014E57140C65E5C3643 /* [CP] Check Pods Manifest.lock */, AAF4A4CFC64D12F3060EC27D /* [CP] Check Pods Manifest.lock */, AD72BADB1D1CA73B00C230B9 /* Sources */, @@ -237,6 +238,7 @@ isa = PBXNativeTarget; buildConfigurationList = AD86367B1D1CA38000792EDC /* Build configuration list for PBXNativeTarget "HelloRest" */; buildPhases = ( + C58B037D40F413D99A37FDBB /* [CP] Check Pods Manifest.lock */, 68E8A2EC53524B779E21F046 /* [CP] Check Pods Manifest.lock */, 054A7AC6CC5D8E9D0785E5C3 /* [CP] Check Pods Manifest.lock */, AD8636651D1CA38000792EDC /* Sources */, @@ -376,6 +378,21 @@ shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-HelloRestSpecs/Pods-HelloRestSpecs-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; + 99F73E9884FFFC5AB76BBC29 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; 9B5FEDA850D40C4E8FB38ABE /* 📦 Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -436,6 +453,21 @@ shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-HelloRest/Pods-HelloRest-resources.sh\"\n"; showEnvVarsInLog = 0; }; + C58B037D40F413D99A37FDBB /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; E2FC52759A204C528D5D5B90 /* 📦 Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/RestExample/HelloRest/HelloRest/PeopleList/PeopleListViewController.swift b/RestExample/HelloRest/HelloRest/PeopleList/PeopleListViewController.swift index 7472b74..1769d1e 100644 --- a/RestExample/HelloRest/HelloRest/PeopleList/PeopleListViewController.swift +++ b/RestExample/HelloRest/HelloRest/PeopleList/PeopleListViewController.swift @@ -31,10 +31,11 @@ extension PeopleListViewController : UITableViewDataSource { func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let personForIndex = viewModel.getPersonAtIndex(indexPath.row) - let cellIdentifier = "\(personForIndex.id)" - let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) ?? UITableViewCell(style: .Default, reuseIdentifier: cellIdentifier) + let cellIdentifier = "cell" + let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) ?? UITableViewCell(style: .Subtitle, reuseIdentifier: cellIdentifier) cell.textLabel?.text = personForIndex.name + cell.detailTextLabel?.text = personForIndex.phone ?? "" return cell } diff --git a/RestExample/HelloRest/HelloRest/PeopleList/PeopleListViewModel.swift b/RestExample/HelloRest/HelloRest/PeopleList/PeopleListViewModel.swift index 50d7b04..344ce26 100644 --- a/RestExample/HelloRest/HelloRest/PeopleList/PeopleListViewModel.swift +++ b/RestExample/HelloRest/HelloRest/PeopleList/PeopleListViewModel.swift @@ -8,7 +8,7 @@ struct PeopleListViewModel { init(peopleService: PeopleServiceType) { self.peopleService = peopleService - peopleService.getAllPeople() { people in + peopleService.getAllPeopleWithDetails { people in self.people.value = people } } diff --git a/RestExample/HelloRest/HelloRest/Services/PeopleService.swift b/RestExample/HelloRest/HelloRest/Services/PeopleService.swift index 48df4d8..4ad6fe0 100644 --- a/RestExample/HelloRest/HelloRest/Services/PeopleService.swift +++ b/RestExample/HelloRest/HelloRest/Services/PeopleService.swift @@ -4,6 +4,7 @@ import SwiftyJSON protocol PeopleServiceType { func getAllPeople(onCompletion: ([Person]) -> Void) + func getAllPeopleWithDetails(onCompletion:([Person])-> Void) } class PeopleService : PeopleServiceType { @@ -21,4 +22,16 @@ class PeopleService : PeopleServiceType { } } + func getAllPeopleWithDetails(onCompletion:([Person])-> Void) { + Alamofire + .request(.GET, "http://localhost:8000/listAll") + .validate(statusCode: 200..<400) + .responseJSON { response in + if let value = response.result.value { + let json = JSON(value) + let people = PeopleTransformer.transformListOfPeople(json) + onCompletion(people) + } + } + } } \ No newline at end of file diff --git a/RestExample/HelloRest/HelloRestSpecs/PeopleServiceMock.swift b/RestExample/HelloRest/HelloRestSpecs/PeopleServiceMock.swift index 8a302df..13a8078 100644 --- a/RestExample/HelloRest/HelloRestSpecs/PeopleServiceMock.swift +++ b/RestExample/HelloRest/HelloRestSpecs/PeopleServiceMock.swift @@ -4,10 +4,16 @@ import Foundation class PeopleServiceMock: PeopleServiceType { var getAllPeopleCalled = false + var getAllPeopleWithDetailsCalled = false var stubbedPeopleWithoutDetail = [Person(id: 1, name: "someName")] func getAllPeople(onCompletion: ([Person]) -> Void){ getAllPeopleCalled = true onCompletion(stubbedPeopleWithoutDetail) } + + func getAllPeopleWithDetails(onCompletion:([Person])-> Void) { + getAllPeopleWithDetailsCalled = true + onCompletion(stubbedPeopleWithoutDetail) + } } \ No newline at end of file diff --git a/RestExample/HelloRest/HelloRestSpecs/PeopleServiceTests.swift b/RestExample/HelloRest/HelloRestSpecs/PeopleServiceTests.swift index d16f759..2273f5d 100644 --- a/RestExample/HelloRest/HelloRestSpecs/PeopleServiceTests.swift +++ b/RestExample/HelloRest/HelloRestSpecs/PeopleServiceTests.swift @@ -23,6 +23,25 @@ class PeopleServiceTests: QuickSpec { return OHHTTPStubsResponse(JSONObject: obj, statusCode: 200, headers: nil).responseTime(OHHTTPStubsDownloadSpeed3G) } + + stub(isHost("localhost") && isPath("/listAll") && isMethodGET()) { request in + + let obj = [[ + "id": 7, + "name": "Ballard Craig", + "age": 19, + "phone": "somePhone" + ], + [ + "id": 8, + "name": "Brown Holt", + "age": 10, + "phone" : "somePhone" + ]] + + return OHHTTPStubsResponse(JSONObject: obj, statusCode: 200, headers: nil).responseTime(OHHTTPStubsDownloadSpeed3G) + + } } afterEach { @@ -51,6 +70,25 @@ class PeopleServiceTests: QuickSpec { } } + describe(".getAllPeopleWithDetails"){ + it("should get people with details from listAll endpoint") { + let peopleService = PeopleService() + var completionCalled = false + var actualPeople:[Person] = [] + + peopleService.getAllPeopleWithDetails { people in + completionCalled = true + actualPeople = people + } + + expect(completionCalled).toEventually(beTrue()) + expect(actualPeople).toEventually(haveCount(2)) + + let firstPerson = actualPeople.first + expect(firstPerson?.phone).toNot(beNil()) + + } + } } } \ No newline at end of file From ed4edbde0a08bdce5758b38c44e2fe45d452ba42 Mon Sep 17 00:00:00 2001 From: Shea Clark-Tieche Date: Sun, 10 Jul 2016 23:06:56 -0500 Subject: [PATCH 2/2] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6c34e43..ce00bd9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# iOS Workshop Part II (Starting Point) +# iOS Workshop Part II (Step 2 Complete) ## Prerequisites * A basic understanding of Swift * Ability to create a basic, single-view app @@ -48,6 +48,6 @@ ### Reactive Cocoa * http://ifnotapps.com/2013/07/25/reactivecocoa-from-the-ground-floor-part1/ -# Next Branch: `listWithDetails` +# Next Branch: `transition_to_new_view`