Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #121: Prevent attribute from being set as property on resource if ... #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/resourceful/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
});
}

Expand Down
4 changes: 4 additions & 0 deletions test/hooks-sync-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`": {
Expand Down Expand Up @@ -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`": {
Expand Down Expand Up @@ -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`": {
Expand Down Expand Up @@ -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`": {
Expand Down
9 changes: 8 additions & 1 deletion test/resourceful-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down