resourceful
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -28,3 +28,3 @@ var common = require('./common'); | ||
// | ||
// Restricted, include property in model.restricted() output | ||
// Restricted, exclude property in model.safeJSON() output | ||
// | ||
@@ -31,0 +31,0 @@ restricted: function() { |
@@ -752,3 +752,2 @@ var util = require('util'), | ||
Resource.prototype.toJSON = function () { | ||
@@ -758,6 +757,7 @@ return resourceful.clone(this.properties); | ||
Resource.prototype.restricted = function () { | ||
Resource.prototype.safeJSON = function () { | ||
var schema = this.constructor.schema; | ||
return resourceful.clone(this.properties, function(key) { | ||
return schema.properties[key] && schema.properties[key].restricted; | ||
return resourceful.clone(this.properties, function (key) { | ||
return key === '_id' || key === '_rev' || key === 'resource' | ||
|| (schema.properties[key] && !schema.properties[key].restricted); | ||
}); | ||
@@ -771,3 +771,3 @@ }; | ||
Resource.prototype.toString = function () { | ||
return JSON.stringify(this.properties); | ||
return JSON.stringify(this.toJSON()); | ||
}; | ||
@@ -774,0 +774,0 @@ |
{ | ||
"name": "resourceful", | ||
"description": "A storage agnostic resource-oriented ODM for building prototypical models with validation and sanitization.", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"url": "http://github.com/flatiron/resourceful", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -111,3 +111,3 @@ var assert = require('assert'), | ||
"adds them to `Resource.properties`": function (r) { | ||
assert.equal(Object.keys(r.properties).length,3); | ||
assert.equal(Object.keys(r.properties).length, 3); | ||
assert.include(r.properties, 'title'); | ||
@@ -118,6 +118,6 @@ assert.include(r.properties, 'kind'); | ||
topic: function (R) { | ||
return new(R)({ title: 'The Great Gatsby' }); | ||
return new(R)({ title: 'The Great Gatsby', kind: 'Classic Novels' }); | ||
}, | ||
"should respond to toString()": function (r) { | ||
assert.equal(r.toString(), '{"title":"The Great Gatsby","resource":"Book"}'); | ||
assert.equal(r.toString(), '{"title":"The Great Gatsby","kind":"Classic Novels","resource":"Book"}'); | ||
}, | ||
@@ -127,8 +127,8 @@ "should respond to toJSON()": function (r) { | ||
}, | ||
"should respond to restricted() with filtered properties": function (r) { | ||
var restricted = r.restricted(); | ||
"should respond to safeJSON() without filtered properties": function (r) { | ||
var restricted = r.safeJSON(); | ||
assert.isObject(restricted); | ||
assert.ok(restricted.title); | ||
assert.ok(!restricted.kind); | ||
assert.ok(!restricted.title); | ||
assert.ok(restricted.kind); | ||
}, | ||
@@ -145,3 +145,3 @@ "should return the attributes, when `Object.keys` is called": function (r) { | ||
assert.include(r, 'kind'); | ||
assert.isUndefined(r.kind); | ||
assert.isString(r.kind); | ||
} | ||
@@ -148,0 +148,0 @@ } |
Sorry, the diff of this file is not supported yet
173584
3975