Skip to content

Commit

Permalink
[primary-key-fix] another test
Browse files Browse the repository at this point in the history
  • Loading branch information
rexmas committed Feb 13, 2016
1 parent 8972549 commit f4268bb
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions RealmCrustTests/PrimaryKeyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,26 @@ class PrimaryKeyTests: RealmMappingTest {
XCTAssertEqual(object.uuid, "primary1")
XCTAssertEqual(object.class2s.count, 2)
}

func testMappingsWithPrimaryKeysForAlreadyPresentObject() {

let obj = PrimaryObj2()
obj.uuid = "primary2"
try! realm!.write {
realm!.add(obj)
}

let json2Dict = [ "data.more_data.uuid" : "primary2", "class1" : [ "data" : [ "uuid" : "primary1" ] ] ]

XCTAssertEqual(realm!.objects(PrimaryObj1).count, 0)
XCTAssertEqual(realm!.objects(PrimaryObj2).count, 1)

let json = try! JSONValue(object: json2Dict)
let mapper = CRMapper<PrimaryObj2, PrimaryObj2Mapping>()
let object = try! mapper.mapFromJSONToExistingObject(json, mapping: PrimaryObj2Mapping(adaptor: adaptor!))

XCTAssertEqual(realm!.objects(PrimaryObj2).count, 1)
XCTAssertEqual(realm!.objects(PrimaryObj2).count, 1)
XCTAssertEqual(object, obj)
}
}

0 comments on commit f4268bb

Please sign in to comment.