public
Created

node-resourceful before update fail

  • Download Gist
hooks-before-fail-test.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
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);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.