diff --git a/lib/resourceful/core.js b/lib/resourceful/core.js index 3f57eee..eead584 100644 --- a/lib/resourceful/core.js +++ b/lib/resourceful/core.js @@ -116,7 +116,9 @@ resourceful.define = function (name, definition) { if (attrs) { Object.keys(attrs).forEach(function (k) { - self._properties[k] = attrs[k]; + if (k in Factory.properties || k === '_rev') { + self._properties[k] = attrs[k]; + } }); } diff --git a/test/hooks-sync-test.js b/test/hooks-sync-test.js index 1c7dadd..1eb5eb7 100644 --- a/test/hooks-sync-test.js +++ b/test/hooks-sync-test.js @@ -7,6 +7,7 @@ vows.describe('resourceful/hooks/sync').addBatch({ topic: function () { return resourceful.define('Resource', function () { this.property('name'); + this.property('counter', Number); }); }, "synchronous 'before' hooks on `save`": { @@ -41,6 +42,7 @@ vows.describe('resourceful/hooks/sync').addBatch({ topic: function () { return resourceful.define('Resource2', function () { this.property('name'); + this.property('counter', Number); }); }, "synchronous 'after' hooks on `save`": { @@ -85,6 +87,7 @@ vows.describe('resourceful/hooks/sync').addBatch({ topic: function () { return resourceful.define('Resource3', function () { this.property('title'); + this.property('counter', Number); }); }, "with synchronous 'before' hooks on `create`": { @@ -119,6 +122,7 @@ vows.describe('resourceful/hooks/sync').addBatch({ topic: function () { return resourceful.define('Resource4', function () { this.property('title'); + this.property('counter', Number); }); }, "with synchronous 'after' hooks on `create`": { diff --git a/test/resourceful-test.js b/test/resourceful-test.js index 80d6990..4a17990 100644 --- a/test/resourceful-test.js +++ b/test/resourceful-test.js @@ -138,7 +138,14 @@ vows.describe('resourceful').addVows({ assert.include(r, 'kind'); assert.isString(r.kind); } - } + }, "When instantiated with an attribute that's not a defined property": { + topic: function (R) { + return new(R)({ title: 'The Great Gatsby', kind: 'Classic Novels', author: 'F. Scott Fitzgerald' }); + }, + "should return `undefined` when that attribute is accessed": function(r) { + assert.isUndefined(r.author); + } + }, }, "A Resource with duplicate properties": { topic: function () {