From f4268bb01e8443da6ba68c65787195e16dfcdab8 Mon Sep 17 00:00:00 2001 From: rexmas Date: Sat, 13 Feb 2016 15:38:42 -0800 Subject: [PATCH] [primary-key-fix] another test --- RealmCrustTests/PrimaryKeyTests.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/RealmCrustTests/PrimaryKeyTests.swift b/RealmCrustTests/PrimaryKeyTests.swift index a4dc01b..b2222e2 100644 --- a/RealmCrustTests/PrimaryKeyTests.swift +++ b/RealmCrustTests/PrimaryKeyTests.swift @@ -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() + 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) + } }