Skip to content

Instantly share code, notes, and snippets.

@scottkf
Created August 23, 2012 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottkf/3438974 to your computer and use it in GitHub Desktop.
Save scottkf/3438974 to your computer and use it in GitHub Desktop.
node-resourceful before update fail
var assert = require('assert'),
vows = require('vows'),
resourceful = require('../lib/resourceful');
vows.describe('resourceful/hooks/sync').addBatch({
"a Resource (update)": {
topic: function () {
return resourceful.define('ResourceUpdate', function () {
this.property('name');
this.property('full');
this.prototype.getName = function() {
return this.name + "1"
}
});
},
"synchronous 'before' hooks on `update`": {
topic: function (R) {
var that = this;
that.run = 1;
R.before('update', function (obj) {
that.run *= 2;
obj.counter *= 2;
obj.full = obj.getName();
return true;
});
return R;
},
"when using an instance method in a hook on a Resource ": {
topic: function (R) {
self = this
resource = new(R)({ id: '2013', counter: 0, name: 'a-name' })
resource.save(function(e, i){
resource.update({counter:0}, function (e, res) {
self.callback(e, res);
})
});
},
"should be able to use instance methods within a callback": function (e, res) {
assert.isNull(e);
assert.equal(res.counter, 0);
assert.equal(this.run, 2);
assert.equal(res.getName(), res.full);
}
}
}
}
}).export(module);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment