Created
August 23, 2012 17:20
-
-
Save scottkf/3438974 to your computer and use it in GitHub Desktop.
node-resourceful before update fail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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