Merge pull request #1454 from realm/kneth/create-object-during-migration

Adding test of creating objects during migration.
This commit is contained in:
Brian Munkholm 2017-11-02 04:46:17 -07:00 committed by GitHub
commit 75c383e05f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 54 additions and 0 deletions

View File

@ -119,6 +119,60 @@ module.exports = {
TestCase.assertEqual(objects[0].prop0, undefined);
},
testCreateObjectsDuringMigration: function() {
const FirstObjectType = {
name: 'FirstObjectType',
properties: {
prop0: 'string',
prop1: 'int',
}
};
const SecondObjectType = {
name: 'SecondObjectType',
properties: {
prop0: 'string',
prop1: 'int',
prop2: 'int',
}
};
var realm1 = new Realm({ schema: [FirstObjectType],
schemaVersion: 0,
});
realm1.write(function() {
realm1.create('FirstObjectType', ['stringValue', 1]);
});
realm1.close();
var realm2 = new Realm({schema: [FirstObjectType, SecondObjectType],
schemaVersion: 1,
migration: function(oldRealm, newRealm) {
var oldObjects_1 = oldRealm.objects('FirstObjectType');
var newObjects_1 = newRealm.objects('FirstObjectType');
var newObjects_2 = newRealm.objects('SecondObjectType');
TestCase.assertEqual(oldObjects_1.length, 1);
TestCase.assertEqual(newObjects_1.length, 1);
TestCase.assertEqual(newObjects_2.length, 0);
newRealm.create('SecondObjectType', {
prop0: oldObjects_1[0].prop0,
prop1: oldObjects_1[0].prop1,
prop2: 42,
});
}
});
var objects_1 = realm2.objects('FirstObjectType');
var objects_2 = realm2.objects('SecondObjectType');
TestCase.assertEqual(objects_1.length, 1);
TestCase.assertEqual(objects_1[0].prop1, 1);
TestCase.assertEqual(objects_2.length, 1);
TestCase.assertEqual(objects_2[0].prop1, 1);
TestCase.assertEqual(objects_2[0].prop2, 42);
},
testMigrationSchema: function() {
var realm = new Realm({schema: [{
name: 'TestObject',