From 18d65471bebc94179efa9f054de244bcf58b6b1c Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Tue, 27 Oct 2015 10:28:34 -0700 Subject: [PATCH] fix and tests for setting null properties --- src/RJSObject.mm | 2 +- tests/ObjectTests.js | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/RJSObject.mm b/src/RJSObject.mm index 2405e1ca..c6bd1224 100644 --- a/src/RJSObject.mm +++ b/src/RJSObject.mm @@ -100,7 +100,7 @@ template<> JSValueRef RJSAccessor::default_value_for_property(JSContextRef ctx, } 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) { return JSValueMakeNull(ctx); diff --git a/tests/ObjectTests.js b/tests/ObjectTests.js index 21887319..1fa91aed 100644 --- a/tests/ObjectTests.js +++ b/tests/ObjectTests.js @@ -157,6 +157,58 @@ module.exports = BaseTest.extend({ 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() { var realm = new Realm({schema: [schemas.LinkTypes, schemas.TestObject]}); var obj = null;