Skip to content

Commit 93031be

Browse files
committed
Expand tests, update Travis build settings
1 parent cb97cf8 commit 93031be

File tree

7 files changed

+118
-29
lines changed

7 files changed

+118
-29
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
language: objective-c
2-
osx_image: xcode6.4
2+
osx_image: xcode7
33
script:
4-
- xcodebuild -project ModelRocket.xcodeproj -scheme ModelRocket -sdk iphonesimulator8.4 test
4+
- xcodebuild -project ModelRocket.xcodeproj -scheme ModelRocket -sdk iphonesimulator9.0 test

ModelRocket.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "ModelRocket"
3-
s.version = "1.0"
3+
s.version = "1.1"
44
s.license = "MIT"
55
s.summary = "An iOS framework for creating JSON-based models. Written in Swift."
66
s.homepage = "https://github.com/ovenbits/ModelRocket"

ModelRocket.xcodeproj/xcshareddata/xcschemes/ModelRocket.xcscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
buildConfiguration = "Debug"
4141
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4242
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
43-
shouldUseLaunchSchemeArgsEnv = "YES">
43+
shouldUseLaunchSchemeArgsEnv = "YES"
44+
codeCoverageEnabled = "YES">
4445
<Testables>
4546
<TestableReference
4647
skipped = "NO">

ModelRocket/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0</string>
18+
<string>1.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

ModelRocketTests/JSONTests.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class JSONTests: XCTestCase {
5353
let data = NSData(contentsOfFile: path)
5454
let vehicleJSON = JSON(data: data)
5555

56+
// No data
57+
let emptyJSON = JSON(data: nil)
58+
XCTAssertTrue(emptyJSON.isNil, "JSON not nil")
59+
5660
// String
5761
XCTAssertEqual(vehicleJSON["make"].stringValue, "BMW")
5862
XCTAssertEqual(vehicleJSON["manufacturer"]["company_name"].stringValue, "Bayerische Motoren Werke AG")
@@ -110,13 +114,15 @@ class JSONTests: XCTestCase {
110114
var json = JSON()
111115
json["string"] = "Test String"
112116
json["int"] = 2
117+
json["uInt"] = 4
113118
json["float"] = 5.5
114119
json["bool"] = true
115120
json["array"] = [1, 2, 3, 4, 5]
116121
json["dictionary"] = ["string1" : "String 1", "string2" : "String 2", "string3" : "String 3"]
117122

118123
XCTAssertEqual(json["string"].string!, "Test String")
119124
XCTAssertEqual(json["int"].int!, 2)
125+
XCTAssertEqual(json["uInt"].uInt!, 4)
120126
XCTAssertEqual(json["float"].float!, 5.5)
121127
XCTAssertEqual(json["bool"].bool!, true)
122128
XCTAssertEqual(json["array"].array!.map { $0.intValue }, [1, 2, 3, 4, 5])
@@ -177,6 +183,7 @@ class JSONTests: XCTestCase {
177183
"int" : 2,
178184
"float" : 5.5,
179185
"bool" : true,
186+
"url" : "http://ovenbits.com",
180187
"array" : [1, 2, 3, 4, 5],
181188
"dictionary" : [
182189
"string1" : "String 1",
@@ -190,6 +197,7 @@ class JSONTests: XCTestCase {
190197
"int" : 2,
191198
"float" : 5.5,
192199
"bool" : true,
200+
"url" : "http://ovenbits.com",
193201
"array" : [1, 2, 3, 4, 5],
194202
"dictionary" : [
195203
"string1" : "String 1",
@@ -198,13 +206,14 @@ class JSONTests: XCTestCase {
198206
]
199207
]
200208

201-
XCTAssertEqual(lhs["string"], rhs["string"])
202-
XCTAssertEqual(lhs["int"], rhs["int"])
203-
XCTAssertEqual(lhs["float"], rhs["float"])
204-
XCTAssertEqual(lhs["bool"], rhs["bool"])
205-
XCTAssertEqual(lhs["array"], rhs["array"])
206-
XCTAssertEqual(lhs["dictionary"], rhs["dictionary"])
207-
XCTAssertEqual(lhs, rhs)
209+
XCTAssertTrue(lhs["string"] == rhs["string"])
210+
XCTAssertTrue(lhs["int"] == rhs["int"])
211+
XCTAssertTrue(lhs["float"] == rhs["float"])
212+
XCTAssertTrue(lhs["bool"] == rhs["bool"])
213+
XCTAssertTrue(lhs["url"].URL == rhs["url"].URL)
214+
XCTAssertTrue(lhs["array"] == rhs["array"])
215+
XCTAssertTrue(lhs["dictionary"] == rhs["dictionary"])
216+
XCTAssertTrue(lhs == rhs)
208217
}
209218

210219
// MARK: - String

ModelRocketTests/ModelRocketTests.swift

Lines changed: 96 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ModelRocketTests: XCTestCase {
4040
// Put setup code here. This method is called before the invocation of each test method in the class.
4141

4242
// Setup test model
43-
var jsonString = "{\"string\" : \"Test string\", \"date\" : \"2015-02-04T18:30:15.000Z\", \"color\" : \"#00FF00\", \"bool\" : true, \"url\" : \"http://ovenbits.com\", \"number\": 3, \"double\" : 7.5, \"float\" : 4.75, \"int\" : -23, \"u_int\" : 25}"
43+
var jsonString = "{\"string\" : \"Test string\", \"date\" : \"2015-02-04T18:30:15.000Z\", \"color\" : \"#00FF00\", \"bool\" : true, \"url\" : \"http://ovenbits.com\", \"number\": 3, \"double\" : 7.5, \"float\" : 4.75, \"int\" : -23, \"u_int\" : 25, \"string_enum\" : \"String1\", \"int_enum\" : 0}"
4444
var jsonData = jsonString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
4545
var json = JSON(data: jsonData!)
4646
testModel = TestModel(json: json)
@@ -93,6 +93,32 @@ class ModelRocketTests: XCTestCase {
9393
super.tearDown()
9494
}
9595

96+
func testProperty() {
97+
XCTAssertEqual(testModel.string.type, "String", "Types not equal")
98+
XCTAssertEqual(testModel.string[], "Test string")
99+
XCTAssertEqual(testModel.string.hashValue, "string".hashValue, "Hash values not equal")
100+
}
101+
102+
func testEquatableProperty() {
103+
let dateFormatter = NSDateFormatter()
104+
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
105+
let date = dateFormatter.dateFromString("2015-02-04T18:30:15.000Z")
106+
107+
XCTAssertTrue(testModel.string == Property<String>(key: "string", defaultValue: "Test string"), "Properties not equal")
108+
XCTAssertTrue(testModel.date == Property<NSDate>(key: "date", defaultValue: date), "Properties not equal")
109+
XCTAssertTrue(testModel.color == Property<UIColor>(key: "color", defaultValue: .greenColor()), "Properties not equal")
110+
XCTAssertTrue(testModel.bool == Property<Bool>(key: "bool", defaultValue: true), "Properties not equal")
111+
XCTAssertTrue(testModel.url == Property<NSURL>(key: "url", defaultValue: NSURL(string: "http://ovenbits.com")), "Properties not equal")
112+
XCTAssertTrue(testModel.number == Property<NSNumber>(key: "number", defaultValue: NSNumber(int: 3)), "Properties not equal")
113+
XCTAssertTrue(testModel.double == Property<Double>(key: "double", defaultValue: 7.5), "Properties not equal")
114+
XCTAssertTrue(testModel.float == Property<Float>(key: "float", defaultValue: 4.75), "Properties not equal")
115+
XCTAssertTrue(testModel.int == Property<Int>(key: "int", defaultValue: -23), "Properties not equal")
116+
XCTAssertTrue(testModel.uInt == Property<UInt>(key: "u_int", defaultValue: 25), "Properties not equal")
117+
XCTAssertTrue(testModel.stringEnum == Property<TestStringEnum>(key: "string_enum", defaultValue: .String1), "Properties not equal")
118+
XCTAssertTrue(testModel.intEnum == Property<TestIntEnum>(key: "int_enum", defaultValue: .Int1), "Properties not equal")
119+
XCTAssertFalse(testModel.string == Property<String>(key: "string", defaultValue: "Test string here"), "Properties shouldn't be equal")
120+
}
121+
96122
func testString() {
97123
if let string = testModel.string.value {
98124
XCTAssertEqual(string, "Test string", "Strings not equal")
@@ -141,7 +167,7 @@ class ModelRocketTests: XCTestCase {
141167

142168
func testURL() {
143169
if let url = testModel.url.value {
144-
XCTAssertEqual(url, NSURL(string: "http://ovenbits.com")!, "URLs not equal")
170+
XCTAssertEqual(url, NSURL(string: "http://ovenbits.com"), "URLs not equal")
145171
}
146172
else {
147173
XCTAssert(false, "Test URL should not be nil")
@@ -201,7 +227,7 @@ class ModelRocketTests: XCTestCase {
201227
XCTAssertEqual(json["bool"].boolValue, true, "Bools not equal")
202228

203229
if let url = json["url"].URL {
204-
XCTAssertEqual(url, NSURL(string: "http://ovenbits.com")!, "URLs not equal")
230+
XCTAssertEqual(url, NSURL(string: "http://ovenbits.com"), "URLs not equal")
205231
}
206232
else {
207233
XCTAssert(false, "URL should not be nil")
@@ -248,7 +274,7 @@ class ModelRocketTests: XCTestCase {
248274
if let bool = unarchived.bool.value { XCTAssertEqual(bool, true, "Bools not equal") }
249275
else { XCTAssert(false, "Coding: bool should not be nil") }
250276

251-
if let url = unarchived.url.value { XCTAssertEqual(url, NSURL(string: "http://ovenbits.com")!, "URLs not equal") }
277+
if let url = unarchived.url.value { XCTAssertEqual(url, NSURL(string: "http://ovenbits.com"), "URLs not equal") }
252278
else { XCTAssert(false, "Coding: url should not be nil") }
253279

254280
if let number = unarchived.number.value { XCTAssertEqual(number, NSNumber(int: 3), "Numbers not equal") }
@@ -277,6 +303,19 @@ class ModelRocketTests: XCTestCase {
277303
XCTAssertEqual(testArrayModel.strings.values[1], "string2", "Strings not equal")
278304
XCTAssertEqual(testArrayModel.strings.values[2], "string3", "Strings not equal")
279305
XCTAssertEqual(testArrayModel.strings.values[3], "string4", "Strings not equal")
306+
307+
XCTAssertEqual(testArrayModel.strings.type, "String", "Types not equal")
308+
XCTAssertEqual(testArrayModel.strings.count, 4, "Counts not equal")
309+
XCTAssertEqual(testArrayModel.strings[0], "string1", "Strings not equal")
310+
XCTAssertEqual(testArrayModel.strings.first, "string1", "Strings not equal")
311+
XCTAssertEqual(testArrayModel.strings.last, "string4", "Strings not equal")
312+
XCTAssertEqual(testArrayModel.strings.hashValue, "strings".hashValue, "Hash values not equal")
313+
314+
let property = PropertyArray<String>(key: "strings", defaultValues: ["string1", "string2", "string3", "string4"])
315+
XCTAssertTrue(testArrayModel.strings == property, "Properties not equal")
316+
317+
property.values = ["string1"]
318+
XCTAssertFalse(testArrayModel.strings == property, "Properties shouldn't be equal")
280319
}
281320

282321
func testArrayJSON() {
@@ -341,6 +380,17 @@ class ModelRocketTests: XCTestCase {
341380

342381
if let int3 = testDictionaryModel.ints.values["int3"] { XCTAssertEqual(int3, 3, "Ints not equal") }
343382
else { XCTAssert(false, "Dictionary: int1 should not be nil") }
383+
384+
XCTAssertEqual(testDictionaryModel.ints.type, "Int", "Type not equal")
385+
XCTAssertEqual(testDictionaryModel.ints.count, 3, "Counts not equal")
386+
XCTAssertEqual(testDictionaryModel.ints["int1"], 1, "Ints not equal")
387+
XCTAssertEqual(testDictionaryModel.ints.hashValue, "ints".hashValue, "Hash values not equal")
388+
389+
let property = PropertyDictionary<Int>(key: "ints", defaultValues: ["int1" : 1, "int2" : 2, "int3" : 3])
390+
XCTAssertTrue(testDictionaryModel.ints == property, "Properties not equal")
391+
392+
property.values = ["int1" : 1]
393+
XCTAssertFalse(testDictionaryModel.ints == property, "Properties shouldn't be equal")
344394
}
345395

346396
func testDictionaryJSON() {
@@ -430,7 +480,7 @@ class ModelRocketTests: XCTestCase {
430480
XCTAssertEqual(json["bool"].boolValue, true, "Bools not equal")
431481

432482
if let jsonURL = json["url"].URL {
433-
XCTAssertEqual(jsonURL, NSURL(string: "http://ovenbits.com")!, "URLs not equal")
483+
XCTAssertEqual(jsonURL, NSURL(string: "http://ovenbits.com"), "URLs not equal")
434484
}
435485
else {
436486
XCTAssert(false, "URL should not be nil")
@@ -488,21 +538,44 @@ class ModelRocketTests: XCTestCase {
488538
}
489539
}
490540

541+
func testStringEnumTransformable() {
542+
XCTAssertEqual(TestStringEnum.fromJSON("String1"), TestStringEnum.String1)
543+
XCTAssertEqual(TestStringEnum.fromJSON("String2"), TestStringEnum.String2)
544+
545+
let string1 = TestStringEnum.String1.toJSON() as! String
546+
XCTAssertEqual(string1, "String1")
547+
548+
let string2 = TestStringEnum.String2.toJSON() as! String
549+
XCTAssertEqual(string2, "String2")
550+
}
551+
552+
func testIntEnumTransformable() {
553+
XCTAssertEqual(TestIntEnum.fromJSON(0), TestIntEnum.Int1)
554+
XCTAssertEqual(TestIntEnum.fromJSON(1), TestIntEnum.Int2)
555+
556+
let int1 = TestIntEnum.Int1.toJSON() as! Int
557+
XCTAssertEqual(int1, 0)
558+
559+
let int2 = TestIntEnum.Int2.toJSON() as! Int
560+
XCTAssertEqual(int2, 1)
561+
}
491562
}
492563

493564
// MARK: - Models
494565

495566
class TestModel: Model {
496-
let string = Property<String>(key: "string")
497-
let date = Property<NSDate>(key: "date")
498-
let color = Property<UIColor>(key: "color")
499-
let bool = Property<Bool>(key: "bool")
500-
let url = Property<NSURL>(key: "url")
501-
let number = Property<NSNumber>(key: "number")
502-
let double = Property<Double>(key: "double")
503-
let float = Property<Float>(key: "float")
504-
let int = Property<Int>(key: "int")
505-
let uInt = Property<UInt>(key: "u_int")
567+
let string = Property<String>(key: "string")
568+
let date = Property<NSDate>(key: "date")
569+
let color = Property<UIColor>(key: "color")
570+
let bool = Property<Bool>(key: "bool")
571+
let url = Property<NSURL>(key: "url")
572+
let number = Property<NSNumber>(key: "number")
573+
let double = Property<Double>(key: "double")
574+
let float = Property<Float>(key: "float")
575+
let int = Property<Int>(key: "int")
576+
let uInt = Property<UInt>(key: "u_int")
577+
let stringEnum = Property<TestStringEnum>(key: "string_enum")
578+
let intEnum = Property<TestIntEnum>(key: "int_enum")
506579
}
507580

508581
class TestArrayModel: Model {
@@ -540,3 +613,11 @@ class TestRequiredModel: Model {
540613
let requiredString = Property<String>(key: "required_string", required: true)
541614
let unrequiredInt = Property<Int>(key: "unrequired_int")
542615
}
616+
617+
enum TestStringEnum: String, JSONTransformable {
618+
case String1, String2
619+
}
620+
621+
enum TestIntEnum: Int, JSONTransformable {
622+
case Int1, Int2
623+
}

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ Then, run `pod install`.
6565

6666
### Creating a custom object
6767

68-
> NOTE: Due to a namespacing issue in v1.0 with the framework and the base model class (`ModelRocket`) having the same name, we decided to rename the `ModelRocket` class to simply `Model`. This change will be effective in the v1.1 release when Swift 2 is officially released. Hooray namespacing!
69-
7068
```swift
7169
class Vehicle: Model {
7270
let make = Property<String>(key: "make")

0 commit comments

Comments
 (0)