fix and tests for setting null properties

This commit is contained in:
Ari Lazier 2015-10-27 10:28:34 -07:00
parent ac1cdfdc8b
commit 18d65471be
2 changed files with 53 additions and 1 deletions

View File

@ -100,7 +100,7 @@ template<> JSValueRef RJSAccessor::default_value_for_property(JSContextRef ctx,
} }
template<> bool RJSAccessor::is_null(JSContextRef ctx, JSValueRef &val) { template<> bool RJSAccessor::is_null(JSContextRef ctx, JSValueRef &val) {
return JSValueIsUndefined(ctx, val) || JSValueIsNull(ctx, val); return JSValueIsNull(ctx, val);
} }
template<> JSValueRef RJSAccessor::null_value(JSContextRef ctx) { template<> JSValueRef RJSAccessor::null_value(JSContextRef ctx) {
return JSValueMakeNull(ctx); return JSValueMakeNull(ctx);

View File

@ -157,6 +157,58 @@ module.exports = BaseTest.extend({
TestCase.assertEqual(obj.boolCol, false, 'bool value changed outside transaction'); TestCase.assertEqual(obj.boolCol, false, 'bool value changed outside transaction');
}, },
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;
realm.write(function() {
obj = realm.create('NullableBasicTypesObject', basicTypesValues);
for (var prop of schemas.NullableBasicTypes.properties) {
obj[prop.name] = null;
}
});
for (var prop of schemas.NullableBasicTypes.properties) {
TestCase.assertEqual(obj[prop.name], null);
}
realm.write(function() {
TestCase.assertThrows(function() {
obj.boolCol = 'cat';
});
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() {
obj.boolCol = null;
}, 'can only set property values in a write transaction');
},
testLinkTypesPropertyGetters: function() { testLinkTypesPropertyGetters: function() {
var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]}); var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]});
var obj = null; var obj = null;