minimal tests for migrations

This commit is contained in:
Ari Lazier 2015-10-12 17:01:51 -07:00
parent aa035717a5
commit 8ad1b0907d
3 changed files with 31 additions and 1 deletions

View File

@ -403,6 +403,21 @@ JSValueRef RealmAddNotification(JSContextRef ctx, JSObjectRef function, JSObject
}
}
JSValueRef RealmClose(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) {
try {
RJSValidateArgumentCount(argumentCount, 0);
SharedRealm realm = *RJSGetInternal<SharedRealm *>(thisObject);
realm->invalidate();
realm::Realm::s_global_cache.remove(realm->config().path, realm->thread_id());
}
catch (std::exception &exp) {
if (jsException) {
*jsException = RJSMakeError(ctx, exp);
}
}
return NULL;
}
void RJSNotificationFinalize(JSObjectRef object) {
Notification *notification = RJSGetInternal<Notification *>(object);
JSGlobalContextRelease(notification->ctx);
@ -416,6 +431,7 @@ const JSStaticFunction RJSRealmFuncs[] = {
{"deleteAll", RealmDeleteAll, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"write", RealmWrite, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"addNotification", RealmAddNotification, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{"close", RealmClose, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete},
{NULL, NULL},
};

View File

@ -92,7 +92,9 @@ static JSClassRef s_globalClass;
realm::Realm::s_global_cache.invalidate_all();
realm::Realm::s_global_cache.clear();
DeleteRealmFilesAtPath(TestRealmPath());
DeleteRealmFilesAtPath(RealmPathForFile(@"test.realm"));
DeleteRealmFilesAtPath(RealmPathForFile(@"test1.realm"));
DeleteRealmFilesAtPath(RealmPathForFile(@"test2.realm"));
DeleteRealmFilesAtPath(@(RJSDefaultPath().c_str()));
[super tearDown];

View File

@ -54,6 +54,18 @@ var RealmTests = {
var testPath = TestUtil.realmPathForFile('test1.realm');
var realm = new Realm({path: testPath, schema: [], schemaVersion: 1});
TestCase.assertEqual(realm.schemaVersion, 1);
//TestCase.assertEqual(realm.schema.length, 0);
realm.close();
// TestCase.assertThrows(function() {
// realm = new Realm({path: testPath, schema: [TestObjectSchema], schemaVersion: 1});
// }, "schema changes require updating the schema version");
realm = new Realm({path: testPath, schema: [TestObjectSchema], schemaVersion: 2});
realm.write(function() {
realm.create('TestObject', [1]);
});
TestCase.assertEqual(realm.objects('TestObject')[0].doubleCol, 1)
//realm = undefined;
//realm = new Realm({path: testPath, schema: [], schemaVersion: 2});