Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[fix] dont crash without a callback in update #108

Closed
wants to merge 4 commits into from

3 participants

@chbm

one liner

@travisbot

This pull request passes (merged 64b8696 into 68f1cf0).

@Marak

@chbm - Could you please also commit the failing test which causes this?

Thanks!

@travisbot

This pull request passes (merged 4c9d0cb into ff957d1).

@travisbot

This pull request passes (merged 1d3d5ba into ff957d1).

@chbm chbm closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 26, 2012
  1. @chbm
Commits on Aug 27, 2012
  1. @chbm
Commits on Aug 28, 2012
  1. @chbm

    * [test] test cases for #108

    chbm authored
Commits on Aug 29, 2012
  1. @chbm
This page is out of date. Refresh to see the latest.
View
6 lib/resourceful/resource.js
@@ -365,7 +365,7 @@ Resource.update = function (id, obj, callback) {
result[key] = oldid;
obj[key] = oldid;
}
- callback(err, result);
+ callback && callback(err, result);
})
: callback && callback(new Error('key is undefined'));
};
@@ -870,8 +870,8 @@ Resource.prototype.toJSON = function () {
Resource.prototype.safeJSON = function () {
var schema = this.constructor.schema;
return resourceful.clone(this.properties, function (key) {
- return key === '_id' || key === '_rev' || key === 'resource'
- || (schema.properties[key] && !schema.properties[key].restricted);
+ return !(key === '_id' || key === '_rev' || key === 'resource'
+ || (schema.properties[key] && schema.properties[key].restricted));
});
};
View
22 test/engines-test.js
@@ -329,13 +329,16 @@ engines.forEach(function (e) {
"a Resource.update() request when successful": {
topic: function () {
resources[e].Author.update('bob', { age: 31 }, this.callback);
- },
- "should respond with a Resource instance": function (err, obj) {
- assert.isNull(err);
- assert.isObject(obj);
- assert.instanceOf(obj, resourceful.Resource);
- assert.equal(obj.constructor, resources[e].Author);
- },
+ },
+ "should not crash when not passed a callback": function (err, obj) {
+ resources[e].Author.update('mat', { age: 35, hair: 'brown' });
+ },
+ "should respond with a Resource instance": function (err, obj) {
+ assert.isNull(err);
+ assert.isObject(obj);
+ assert.instanceOf(obj, resourceful.Resource);
+ assert.equal(obj.constructor, resources[e].Author);
+ },
"should respond with the right object": function (err, obj) {
assert.isNull(err);
assert.equal(obj.id, 'bob');
@@ -512,10 +515,13 @@ engines.forEach(function (e) {
assert.isNull(err);
assert.isFalse(obj.isNewRecord);
},
- "a Resource.prototype.update() request": {
+ "a Resource.prototype.update() request": {
topic: function (obj) {
obj.update({ age: 35, hair: 'black' }, this.callback);
},
+ "should not crash when not passed a callback": function (err, obj) {
+ obj.update({ age: 35, hair: 'black' });
+ },
"should respond with a Resource instance": function (err, obj) {
assert.isNull(err);
assert.isObject(obj);
View
4 test/resourceful-test.js
@@ -126,6 +126,10 @@ vows.describe('resourceful').addVows({
assert.ok(!restricted.title);
assert.ok(restricted.kind);
+
+ assert.ok(!restricted._rev);
+ assert.ok(!restricted._id);
+ assert.ok(!restricted.resource);
},
"should return the attributes, when `Object.keys` is called": function (r) {
var keys = Object.keys(r);
Something went wrong with that request. Please try again.