Fixed typos and logic for protected properties

This commit is contained in:
Christian Enevoldsen 2015-01-20 21:32:31 +01:00
parent d39f539413
commit 7372fafc97
2 changed files with 7 additions and 6 deletions

View File

@ -321,6 +321,7 @@ ModelBaseClass.prototype.toObject = function (onlySchema, removeHidden, removePr
var props = Model.definition.properties;
var keys = Object.keys(props);
var propertyName, val;
for (var i = 0; i < keys.length; i++) {
propertyName = keys[i];
val = self[propertyName];
@ -393,7 +394,7 @@ ModelBaseClass.prototype.toObject = function (onlySchema, removeHidden, removePr
if (removeHidden && Model.isHiddenProperty(propertyName)) {
continue;
}
if (removeHidden && Model.isProtectedProperty(propertyName)) {
if (removeProtected && Model.isProtectedProperty(propertyName)) {
continue;
}
var ownVal = self[propertyName];
@ -416,11 +417,11 @@ ModelBaseClass.prototype.toObject = function (onlySchema, removeHidden, removePr
};
ModelBaseClass.isProtectedProperty = function (propertyName) {
var model = this;
var Model = this;
var settings = Model.definition && Model.definition.settings;
var protectedProperties = settings & (settings.protectedProperties || settings.protected);
var protectedProperties = settings && (settings.protectedProperties || settings.protected);
if (Array.isArray(protectedProperties)) {
// Cache the protected properties as an object for quick lookup
settings.protectedProperties = {};
for (var i = 0; i < protectedProperties.length; i++) {
settings.protectedProperties[protectedProperties[i]] = true;

View File

@ -271,7 +271,7 @@ describe('ModelDefinition class', function () {
});
it('should serialize protected properties into JSON', function() {
var memory = new DataSoruce({connector: Memory});
var memory = new DataSource({connector: Memory});
var modelBuilder = memory.modelBuilder;
var ProtectedModel = memory.createModel('protected', {}, {
protected: ['protectedProperty']
@ -285,7 +285,7 @@ describe('ModelDefinition class', function () {
});
});
it('should not serialized protected properties of nested models into JSON', function(done){
it('should not serialize protected properties of nested models into JSON', function(done){
var memory = new DataSource({connector: Memory});
var modelBuilder = memory.modelBuilder;
var Parent = memory.createModel('parent');