more extensive upsert tests

This commit is contained in:
Ari Lazier 2015-09-04 12:41:17 -07:00
parent e9aa46a8f7
commit dcc159365e
3 changed files with 24 additions and 15 deletions

View File

@ -275,6 +275,7 @@ bool ObjectStore::create_tables(Group *group, Schema &target_schema, bool update
case PropertyTypeObject:
case PropertyTypeArray: {
TableRef link_table = ObjectStore::table_for_object_type(group, target_prop.object_type);
REALM_ASSERT(link_table);
target_prop.table_column = table->add_column_link(DataType(target_prop.type), target_prop.name, *link_table);
break;
}

View File

@ -72,7 +72,7 @@ var RealmTests = {
},
testRealmCreate: function() {
var realm = new Realm({schema: [TestObjectSchema]});
var realm = new Realm({schema: [IntPrimaryObjectSchema, AllTypesObjectSchema, TestObjectSchema]});
realm.write(function() {
realm.create('TestObject', [1]);
realm.create('TestObject', {'doubleCol': 2});
@ -83,8 +83,7 @@ var RealmTests = {
TestCase.assertEqual(objects[0].doubleCol, 1, 'wrong object property value');
TestCase.assertEqual(objects[1].doubleCol, 2, 'wrong object property value');
// test primary object
realm = new Realm({path: TestUtil.realmPathForFile('intPrimary.realm'), schema: [IntPrimaryObjectSchema, StringPrimaryObjectSchema]});
// test int primary object
realm.write(function() {
var obj0 = realm.create('IntPrimaryObject', [0, 'val0']);
@ -103,17 +102,19 @@ var RealmTests = {
TestCase.assertEqual(obj0.valueCol, 'newVal0');
});
// test upsert with all type and string primary object
realm.write(function() {
var obj0 = realm.create('StringPrimaryObject', ['0', true, 1, 1.1, 1.11, '1', new Date(1), '1']);
var values = ['0', true, 1, 1.1, 1.11, '1', new Date(1), '1', [1], []];
var obj0 = realm.create('AllTypesObject', values);
TestCase.assertThrows(function() {
realm.create('StringPrimaryObject', ['0', true, 1, 1.1, 1.11, '1', new Date(1), '1']);
realm.create('AllTypesObject', values);
});
realm.create('StringPrimaryObject', ['1', true, 2, 2.2, 2.11, '2', new Date(2), '2'], true);
var objects = realm.objects('StringPrimaryObject');
realm.create('AllTypesObject', ['1', false, 2, 2.2, 2.11, '2', new Date(2), '2', null, [[2]]], true);
var objects = realm.objects('AllTypesObject');
TestCase.assertEqual(objects.length, 2);
realm.create('StringPrimaryObject', ['0', false, 2, 2.2, 2.22, '2', new Date(2), '2'], true);
realm.create('AllTypesObject', ['0', false, 2, 2.2, 2.22, '2', new Date(2), '2', null, [[2]]], true);
TestCase.assertEqual(objects.length, 2);
TestCase.assertEqual(obj0.stringCol, '2');
TestCase.assertEqual(obj0.boolCol, false);
@ -122,11 +123,13 @@ var RealmTests = {
TestCase.assertEqual(obj0.doubleCol, 2.22);
TestCase.assertEqual(obj0.dateCol.getTime(), 2);
TestCase.assertEqual(obj0.dataCol, '2');
TestCase.assertEqual(obj0.objectCol, null);
TestCase.assertEqual(obj0.arrayCol.length, 1);
realm.create('StringPrimaryObject', { primaryCol: '0' }, true);
realm.create('AllTypesObject', { primaryCol: '0' }, true);
TestCase.assertEqual(obj0.stringCol, '2');
realm.create('StringPrimaryObject', { primaryCol: '0', stringCol: '3' }, true);
realm.create('AllTypesObject', { primaryCol: '0', stringCol: '3', objectCol: [0] }, true);
TestCase.assertEqual(obj0.stringCol, '3');
TestCase.assertEqual(obj0.boolCol, false);
TestCase.assertEqual(obj0.intCol, 2);
@ -134,6 +137,8 @@ var RealmTests = {
TestCase.assertEqual(obj0.doubleCol, 2.22);
TestCase.assertEqual(obj0.dateCol.getTime(), 2);
TestCase.assertEqual(obj0.dataCol, '2');
TestCase.assertEqual(obj0.objectCol.doubleCol, 0);
TestCase.assertEqual(obj0.arrayCol.length, 1);
});
},

View File

@ -68,17 +68,20 @@ var IntPrimaryObjectSchema = {
]
};
var StringPrimaryObjectSchema = {
name: 'StringPrimaryObject',
var AllTypesObjectSchema = {
name: 'AllTypesObject',
primaryKey: 'primaryCol',
properties: [
{name: 'primaryCol', type: RealmType.String},
{name: 'primaryCol',type: RealmType.String},
{name: 'boolCol', type: RealmType.Bool},
{name: 'intCol', type: RealmType.Int},
{name: 'floatCol', type: RealmType.Float},
{name: 'doubleCol', type: RealmType.Double},
{name: 'stringCol', type: RealmType.String},
{name: 'dateCol', type: RealmType.Date},
{name: 'dataCol', type: RealmType.Data},
{name: 'dataCol', type: RealmType.Data},
{name: 'objectCol', type: 'TestObject'},
{name: 'arrayCol', type: RealmType.Array, objectType: 'TestObject'},
]
};
};