Skip to content

Commit

Permalink
Merge pull request #20 from hyperoslo/rename/view-model-to-item
Browse files Browse the repository at this point in the history
Rename all references from ViewModel to Item
  • Loading branch information
vadymmarkov authored Sep 26, 2016
2 parents dbe8f2c + 15a7c82 commit 6214ed9
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 315 deletions.
48 changes: 24 additions & 24 deletions Brick.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
BD8070D71D9448830082800B /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BD8070D41D9448830082800B /* Nimble.framework */; };
BD8070D91D94488E0082800B /* Fakery.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BD8070D81D94488E0082800B /* Fakery.framework */; };
BDBA5F221D940F09003A5C6B /* Brick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BDFD54221D940EDC003CB98B /* Brick.framework */; };
BDDA5FEB1CBBCF45000FD5A6 /* ViewConfigurable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA5FEA1CBBCF45000FD5A6 /* ViewConfigurable.swift */; };
BDDA5FEC1CBBCF45000FD5A6 /* ViewConfigurable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA5FEA1CBBCF45000FD5A6 /* ViewConfigurable.swift */; };
BDE7D2171D940FC300027CE4 /* ViewModelSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C629971C3A8BDA007F7B7C /* ViewModelSpec.swift */; };
BDDA5FEB1CBBCF45000FD5A6 /* ItemConfigurable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA5FEA1CBBCF45000FD5A6 /* ItemConfigurable.swift */; };
BDDA5FEC1CBBCF45000FD5A6 /* ItemConfigurable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA5FEA1CBBCF45000FD5A6 /* ItemConfigurable.swift */; };
BDE7D2171D940FC300027CE4 /* ItemSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C629971C3A8BDA007F7B7C /* ItemSpec.swift */; };
BDE7D2181D940FC300027CE4 /* ExtensionsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5ACAC9C1CCE449A00567809 /* ExtensionsSpec.swift */; };
BDE7D2191D940FC300027CE4 /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57832961CE142C8005ED144 /* Helpers.swift */; };
BDE7D21A1D940FCD00027CE4 /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C629861C3A89A8007F7B7C /* ViewModel.swift */; };
BDE7D21B1D940FCD00027CE4 /* ViewConfigurable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA5FEA1CBBCF45000FD5A6 /* ViewConfigurable.swift */; };
BDE7D21A1D940FCD00027CE4 /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C629861C3A89A8007F7B7C /* Item.swift */; };
BDE7D21B1D940FCD00027CE4 /* ItemConfigurable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDA5FEA1CBBCF45000FD5A6 /* ItemConfigurable.swift */; };
BDE7D21C1D940FCD00027CE4 /* StringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAA38AA41CBEEAD900D48603 /* StringConvertible.swift */; };
BDE7D21D1D940FCD00027CE4 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5ACAC991CCE439F00567809 /* Extensions.swift */; };
D57832991CE142DE005ED144 /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D57832961CE142C8005ED144 /* Helpers.swift */; };
Expand All @@ -37,10 +37,10 @@
D5C629781C3A878E007F7B7C /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5C629761C3A878E007F7B7C /* Nimble.framework */; };
D5C6297B1C3A879F007F7B7C /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5C629791C3A879F007F7B7C /* Quick.framework */; };
D5C6297C1C3A879F007F7B7C /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5C6297A1C3A879F007F7B7C /* Nimble.framework */; };
D5C629871C3A89A8007F7B7C /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C629861C3A89A8007F7B7C /* ViewModel.swift */; };
D5C629881C3A89A8007F7B7C /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C629861C3A89A8007F7B7C /* ViewModel.swift */; };
D5C6299C1C3A8BDA007F7B7C /* ViewModelSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C629971C3A8BDA007F7B7C /* ViewModelSpec.swift */; };
D5C6299E1C3A8C75007F7B7C /* ViewModelSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C629971C3A8BDA007F7B7C /* ViewModelSpec.swift */; };
D5C629871C3A89A8007F7B7C /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C629861C3A89A8007F7B7C /* Item.swift */; };
D5C629881C3A89A8007F7B7C /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C629861C3A89A8007F7B7C /* Item.swift */; };
D5C6299C1C3A8BDA007F7B7C /* ItemSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C629971C3A8BDA007F7B7C /* ItemSpec.swift */; };
D5C6299E1C3A8C75007F7B7C /* ItemSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C629971C3A8BDA007F7B7C /* ItemSpec.swift */; };
DAA38AA51CBEEAD900D48603 /* StringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAA38AA41CBEEAD900D48603 /* StringConvertible.swift */; };
DAA38AA61CBEEAD900D48603 /* StringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAA38AA41CBEEAD900D48603 /* StringConvertible.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -80,7 +80,7 @@
BD8070D41D9448830082800B /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/tvOS/Nimble.framework; sourceTree = "<group>"; };
BD8070D81D94488E0082800B /* Fakery.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Fakery.framework; path = Carthage/Build/tvOS/Fakery.framework; sourceTree = "<group>"; };
BDBA5F1D1D940F09003A5C6B /* Brick-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Brick-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
BDDA5FEA1CBBCF45000FD5A6 /* ViewConfigurable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewConfigurable.swift; sourceTree = "<group>"; };
BDDA5FEA1CBBCF45000FD5A6 /* ItemConfigurable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemConfigurable.swift; sourceTree = "<group>"; };
BDE7D2151D940F7800027CE4 /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = "<group>"; };
BDE7D2161D940FAA00027CE4 /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = "<group>"; };
BDFD54221D940EDC003CB98B /* Brick.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Brick.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -97,12 +97,12 @@
D5C629761C3A878E007F7B7C /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/iOS/Nimble.framework; sourceTree = "<group>"; };
D5C629791C3A879F007F7B7C /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = "<group>"; };
D5C6297A1C3A879F007F7B7C /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = "<group>"; };
D5C629861C3A89A8007F7B7C /* ViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewModel.swift; sourceTree = "<group>"; };
D5C629861C3A89A8007F7B7C /* Item.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Item.swift; sourceTree = "<group>"; };
D5C6298B1C3A8BBD007F7B7C /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = "<group>"; };
D5C6298C1C3A8BBD007F7B7C /* Info-Mac.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Mac.plist"; sourceTree = "<group>"; };
D5C629901C3A8BDA007F7B7C /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = "<group>"; };
D5C629911C3A8BDA007F7B7C /* Info-Mac.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-Mac.plist"; sourceTree = "<group>"; };
D5C629971C3A8BDA007F7B7C /* ViewModelSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewModelSpec.swift; sourceTree = "<group>"; };
D5C629971C3A8BDA007F7B7C /* ItemSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemSpec.swift; sourceTree = "<group>"; };
DAA38AA41CBEEAD900D48603 /* StringConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringConvertible.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -214,8 +214,8 @@
D5C6296E1C3A809D007F7B7C /* Shared */ = {
isa = PBXGroup;
children = (
D5C629861C3A89A8007F7B7C /* ViewModel.swift */,
BDDA5FEA1CBBCF45000FD5A6 /* ViewConfigurable.swift */,
D5C629861C3A89A8007F7B7C /* Item.swift */,
BDDA5FEA1CBBCF45000FD5A6 /* ItemConfigurable.swift */,
DAA38AA41CBEEAD900D48603 /* StringConvertible.swift */,
D5ACAC991CCE439F00567809 /* Extensions.swift */,
);
Expand Down Expand Up @@ -252,7 +252,7 @@
D5C629961C3A8BDA007F7B7C /* Shared */ = {
isa = PBXGroup;
children = (
D5C629971C3A8BDA007F7B7C /* ViewModelSpec.swift */,
D5C629971C3A8BDA007F7B7C /* ItemSpec.swift */,
D5ACAC9C1CCE449A00567809 /* ExtensionsSpec.swift */,
D57832961CE142C8005ED144 /* Helpers.swift */,
);
Expand Down Expand Up @@ -618,7 +618,7 @@
buildActionMask = 2147483647;
files = (
BDE7D2181D940FC300027CE4 /* ExtensionsSpec.swift in Sources */,
BDE7D2171D940FC300027CE4 /* ViewModelSpec.swift in Sources */,
BDE7D2171D940FC300027CE4 /* ItemSpec.swift in Sources */,
BDE7D2191D940FC300027CE4 /* Helpers.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -627,8 +627,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BDE7D21A1D940FCD00027CE4 /* ViewModel.swift in Sources */,
BDE7D21B1D940FCD00027CE4 /* ViewConfigurable.swift in Sources */,
BDE7D21A1D940FCD00027CE4 /* Item.swift in Sources */,
BDE7D21B1D940FCD00027CE4 /* ItemConfigurable.swift in Sources */,
BDE7D21C1D940FCD00027CE4 /* StringConvertible.swift in Sources */,
BDE7D21D1D940FCD00027CE4 /* Extensions.swift in Sources */,
);
Expand All @@ -638,9 +638,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D5C629871C3A89A8007F7B7C /* ViewModel.swift in Sources */,
D5C629871C3A89A8007F7B7C /* Item.swift in Sources */,
D5ACAC9A1CCE439F00567809 /* Extensions.swift in Sources */,
BDDA5FEB1CBBCF45000FD5A6 /* ViewConfigurable.swift in Sources */,
BDDA5FEB1CBBCF45000FD5A6 /* ItemConfigurable.swift in Sources */,
DAA38AA51CBEEAD900D48603 /* StringConvertible.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -651,7 +651,7 @@
files = (
D5ACAC9F1CCE45CE00567809 /* ExtensionsSpec.swift in Sources */,
D57832991CE142DE005ED144 /* Helpers.swift in Sources */,
D5C6299E1C3A8C75007F7B7C /* ViewModelSpec.swift in Sources */,
D5C6299E1C3A8C75007F7B7C /* ItemSpec.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -661,8 +661,8 @@
files = (
DAA38AA61CBEEAD900D48603 /* StringConvertible.swift in Sources */,
D5ACAC9B1CCE439F00567809 /* Extensions.swift in Sources */,
D5C629881C3A89A8007F7B7C /* ViewModel.swift in Sources */,
BDDA5FEC1CBBCF45000FD5A6 /* ViewConfigurable.swift in Sources */,
D5C629881C3A89A8007F7B7C /* Item.swift in Sources */,
BDDA5FEC1CBBCF45000FD5A6 /* ItemConfigurable.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -672,7 +672,7 @@
files = (
D5ACACA01CCE45CF00567809 /* ExtensionsSpec.swift in Sources */,
D578329A1CE142DF005ED144 /* Helpers.swift in Sources */,
D5C6299C1C3A8BDA007F7B7C /* ViewModelSpec.swift in Sources */,
D5C6299C1C3A8BDA007F7B7C /* ItemSpec.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions BrickTests/Shared/ExtensionsSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class ExtensionsSpec: QuickSpec {

override func spec() {
describe("Array+Brick") {
var items = [ViewModel]()
var items = [Item]()

beforeEach {
for index in 0..<10 {
var item = ViewModel(title: "Test")
var item = Item(title: "Test")
item.index = 9 - index

items.append(item)
Expand Down
203 changes: 203 additions & 0 deletions BrickTests/Shared/ItemSpec.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
@testable import Brick
import Quick
import Nimble
import Fakery

class ItemSpec: QuickSpec {

override func spec() {
describe("Item") {
var item: Item!
var data: [String : AnyObject]!
let faker = Faker()

beforeEach {
data = [
"title": faker.lorem.paragraph(),
"subtitle": faker.lorem.paragraph(),
"image" : faker.internet.image(),
"kind" : faker.team.name(),
"action" : faker.internet.ipV6Address(),
"meta" : [
"domain" : faker.internet.domainName()
]
]
}

describe("#mapping") {
beforeEach {
item = Item(data)
}

it("it creates an instance") {
expect(item).notTo(beNil())
}

it("sets values") {
expect(item.title).to(equal(data["title"] as? String))
expect(item.subtitle).to(equal(data["subtitle"] as? String))
expect(item.image).to(equal(data["image"] as? String))
expect(item.kind).to(equal(data["kind"] as? String))
expect(item.action).to(equal(data["action"] as? String))
expect(item.meta("domain", "")).to(equal(data["meta"]!["domain"]))
}
}

describe("#relations") {
it("sets relations") {
data["relations"] = ["Items" : [data, data, data]]
item = Item(data)

expect(item.relations["Items"]!.count).to(equal(3))
expect(item.relations["Items"]!.first!.title).to(equal(data["title"] as? String))
expect(item.relations["Items"]!.first!.subtitle).to(equal(data["subtitle"] as? String))
expect(item.relations["Items"]!.first!.image).to(equal(data["image"] as? String))
expect(item.relations["Items"]!.first!.kind).to(equal(data["kind"] as? String))
expect(item.relations["Items"]!.first!.action).to(equal(data["action"] as? String))

expect(item.relations["Items"]!.last!.title).to(equal(data["title"] as? String))
expect(item.relations["Items"]!.last!.subtitle).to(equal(data["subtitle"] as? String))
expect(item.relations["Items"]!.last!.image).to(equal(data["image"] as? String))
expect(item.relations["Items"]!.last!.kind).to(equal(data["kind"] as? String))
expect(item.relations["Items"]!.last!.action).to(equal(data["action"] as? String))

let Item2 = item
expect(item == Item2).to(beTrue())

item.relations["Items"]![2].title = "new"
expect(item == Item2).to(beFalse())
}
}

describe("#meta") {
it("resolves meta data created from JSON") {
item = Item(data)
expect(item.meta("domain", "")).to(equal(data["meta"]!["domain"]))
}

it("resolves meta data created from object") {
var data = ["id": 11, "name": "Name"]

item = Item(meta: Meta(data))
expect(item.meta("id", 0)).to(equal(data["id"]))
expect(item.meta("name", "")).to(equal(data["name"]))
}
}

describe("#metaInstance") {
it("resolves meta data created from object") {
var data = ["id": 11, "name": "Name"]
item = Item(meta: Meta(data))
let result: Meta = item.metaInstance()

expect(result.id).to(equal(data["id"]))
expect(result.name).to(equal(data["name"]))
}
}

describe("#equality") {
it("compares two view models that are equal using identifier") {
let left = Item(identifier: "foo".hashValue)
let right = Item(identifier: "foo".hashValue)

expect(left === right).to(beTrue())
}

it("compares two view models that are not equal using identifier") {
let left = Item(identifier: "foo".hashValue)
let right = Item(identifier: "bar".hashValue)

expect(left === right).to(beFalse())
}

it("compares two view models that are equal") {
let left = Item(title: "foo", size: CGSize(width: 40, height: 40))
let right = Item(title: "foo", size: CGSize(width: 40, height: 40))

expect(left === right).to(beTrue())
}

it("compares two unequal view model") {
let left = Item(title: "foo", size: CGSize(width: 40, height: 40))
let right = Item(title: "foo", size: CGSize(width: 60, height: 60))

expect(left === right).to(beFalse())
}

it("compares a collection of view models that are equal") {
let left = [
Item(title: "foo", size: CGSize(width: 40, height: 40)),
Item(title: "foo", size: CGSize(width: 40, height: 40))
]
let right = [
Item(title: "foo", size: CGSize(width: 40, height: 40)),
Item(title: "foo", size: CGSize(width: 40, height: 40))
]

expect(left === right).to(beTrue())
}

it("compares a collection of view models that are not equal") {
let left = [
Item(title: "foo", size: CGSize(width: 40, height: 40)),
Item(title: "foo", size: CGSize(width: 60, height: 40))
]
let right = [
Item(title: "foo", size: CGSize(width: 40, height: 40)),
Item(title: "foo", size: CGSize(width: 40, height: 40))
]

expect(left === right).to(beFalse())
}
}

describe("#dictionary") {
beforeEach {
data["relations"] = ["Items" : [data, data]]
item = Item(data)
}

it("returns a dictionary representation of the view model") {
let newItem = Item(item.dictionary)

expect(newItem == item).to(beTrue())
expect(newItem.relations["Items"]!.count).to(equal(item.relations["Items"]!.count))
expect(newItem.relations["Items"]!.first!
== item.relations["Items"]!.first!).to(beTrue())
expect(newItem.relations["Items"]!.last!
== item.relations["Items"]!.last!).to(beTrue())
}
}

describe("#update:kind") {
beforeEach {
item = Item(data)
}

it("updates kind") {
item.update(kind: "test")
expect(item.kind).to(equal("test"))
}
}

describe("#compareRelations") {
beforeEach {
data["relations"] = ["Items" : [data, data, data]]
item = Item(data)
}

it("compare relations properly") {
var Item2 = Item(data)
expect(compareRelations(item, Item2)).to(beTrue())

Item2.relations["Items"]![2].title = "new"
expect(compareRelations(item, Item2)).to(beFalse())

data["relations"] = ["Items" : [data, data]]
Item2 = Item(data)
expect(compareRelations(item, Item2)).to(beFalse())
}
}
}
}
}
Loading

0 comments on commit 6214ed9

Please sign in to comment.