mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-22 20:41:18 +00:00
Merge pull request #114 from realm/al-undefined
Allow setting nullable properties to undefined
This commit is contained in:
commit
a84eecb17a
@ -86,7 +86,7 @@ template<> JSValueRef RJSAccessor::default_value_for_property(JSContextRef ctx,
|
||||
}
|
||||
|
||||
template<> bool RJSAccessor::is_null(JSContextRef ctx, JSValueRef &val) {
|
||||
return JSValueIsNull(ctx, val);
|
||||
return JSValueIsNull(ctx, val) || JSValueIsUndefined(ctx, val);
|
||||
}
|
||||
template<> JSValueRef RJSAccessor::null_value(JSContextRef ctx) {
|
||||
return JSValueMakeNull(ctx);
|
||||
|
@ -146,17 +146,20 @@ module.exports = BaseTest.extend({
|
||||
testNullableBasicTypesPropertySetters: function() {
|
||||
var basicTypesValues = [true, 1, 1.1, 1.11, 'string', new Date(1), 'DATA'];
|
||||
var realm = new Realm({schema: [schemas.NullableBasicTypes]});
|
||||
var obj = null;
|
||||
var obj, obj1;
|
||||
|
||||
realm.write(function() {
|
||||
obj = realm.create('NullableBasicTypesObject', basicTypesValues);
|
||||
obj1 = realm.create('NullableBasicTypesObject', basicTypesValues);
|
||||
for (var prop of schemas.NullableBasicTypes.properties) {
|
||||
obj[prop.name] = null;
|
||||
obj1[prop.name] = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
for (var prop of schemas.NullableBasicTypes.properties) {
|
||||
TestCase.assertEqual(obj[prop.name], null);
|
||||
TestCase.assertEqual(obj1[prop.name], null);
|
||||
}
|
||||
|
||||
realm.write(function() {
|
||||
@ -166,28 +169,6 @@ module.exports = BaseTest.extend({
|
||||
TestCase.assertThrows(function() {
|
||||
obj.intCol = 'dog';
|
||||
});
|
||||
|
||||
TestCase.assertThrows(function() {
|
||||
obj.boolCol = undefined;
|
||||
});
|
||||
TestCase.assertThrows(function() {
|
||||
obj.intCol = undefined;
|
||||
});
|
||||
TestCase.assertThrows(function() {
|
||||
obj.floatCol = undefined;
|
||||
});
|
||||
TestCase.assertThrows(function() {
|
||||
obj.doubleCol = undefined;
|
||||
});
|
||||
TestCase.assertThrows(function() {
|
||||
obj.stringCol = undefined;
|
||||
});
|
||||
TestCase.assertThrows(function() {
|
||||
obj.dateCol = undefined;
|
||||
});
|
||||
TestCase.assertThrows(function() {
|
||||
obj.dataCol = undefined;
|
||||
});
|
||||
});
|
||||
|
||||
TestCase.assertThrows(function() {
|
||||
|
@ -118,7 +118,7 @@ module.exports = BaseTest.extend({
|
||||
TestCase.assertThrows(function() {
|
||||
realm.create('AllTypesObject', values);
|
||||
});
|
||||
realm.create('AllTypesObject', ['1', false, 2, 2.2, 2.11, '2', new Date(2), '2', null, [[2]]], true);
|
||||
var obj1 = realm.create('AllTypesObject', ['1', false, 2, 2.2, 2.11, '2', new Date(2), '2', [0], [[2]]], true);
|
||||
var objects = realm.objects('AllTypesObject');
|
||||
TestCase.assertEqual(objects.length, 2);
|
||||
|
||||
@ -135,7 +135,10 @@ module.exports = BaseTest.extend({
|
||||
TestCase.assertEqual(obj0.arrayCol.length, 1);
|
||||
|
||||
realm.create('AllTypesObject', { primaryCol: '0' }, true);
|
||||
realm.create('AllTypesObject', { primaryCol: '1' }, true);
|
||||
TestCase.assertEqual(obj0.stringCol, '2');
|
||||
TestCase.assertEqual(obj0.objectCol, null);
|
||||
TestCase.assertEqual(obj1.objectCol.doubleCol, 0);
|
||||
|
||||
realm.create('AllTypesObject', { primaryCol: '0', stringCol: '3', objectCol: [0] }, true);
|
||||
TestCase.assertEqual(obj0.stringCol, '3');
|
||||
@ -147,6 +150,11 @@ module.exports = BaseTest.extend({
|
||||
TestCase.assertEqual(obj0.dataCol, '2');
|
||||
TestCase.assertEqual(obj0.objectCol.doubleCol, 0);
|
||||
TestCase.assertEqual(obj0.arrayCol.length, 1);
|
||||
|
||||
realm.create('AllTypesObject', { primaryCol: '0', objectCol: undefined }, true);
|
||||
realm.create('AllTypesObject', { primaryCol: '1', objectCol: null }, true);
|
||||
TestCase.assertEqual(obj0.objectCol, null);
|
||||
TestCase.assertEqual(obj1.objectCol, null);
|
||||
});
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user