Describe test case
This commit is contained in:
parent
c457f6ae00
commit
1ad0d91e57
|
@ -48,7 +48,7 @@ function testOrm(schema) {
|
||||||
approved: Boolean,
|
approved: Boolean,
|
||||||
joinedAt: Date,
|
joinedAt: Date,
|
||||||
age: Number,
|
age: Number,
|
||||||
password: String
|
passwd: String
|
||||||
});
|
});
|
||||||
|
|
||||||
Post = schema.define('Post', {
|
Post = schema.define('Post', {
|
||||||
|
@ -238,8 +238,8 @@ function testOrm(schema) {
|
||||||
it('should handle virtual attributes', function (test) {
|
it('should handle virtual attributes', function (test) {
|
||||||
var salt = 's0m3s3cr3t5a1t';
|
var salt = 's0m3s3cr3t5a1t';
|
||||||
|
|
||||||
User.setter.password = function (password) {
|
User.setter.passwd = function (password) {
|
||||||
this._password = calcHash(password, salt);
|
this._passwd = calcHash(password, salt);
|
||||||
};
|
};
|
||||||
|
|
||||||
function calcHash(pass, salt) {
|
function calcHash(pass, salt) {
|
||||||
|
@ -251,8 +251,8 @@ function testOrm(schema) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var u = new User;
|
var u = new User;
|
||||||
u.password = 's3cr3t';
|
u.passwd = 's3cr3t';
|
||||||
test.equal(u.password, calcHash('s3cr3t', salt));
|
test.equal(u.passwd, calcHash('s3cr3t', salt));
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -30,34 +30,47 @@ it "should trigger before create", (test)->
|
||||||
test.done()
|
test.done()
|
||||||
User.create {}, ()-> test.ok "saved"
|
User.create {}, ()-> test.ok "saved"
|
||||||
|
|
||||||
it "should trigger after create", (test)->
|
it "should trigger after create", (test) ->
|
||||||
User.afterCreate = ()->
|
User.afterCreate = (next) ->
|
||||||
User.afterCreate = null
|
User.afterCreate = null
|
||||||
test.done()
|
next()
|
||||||
User.create {}, ()-> test.ok "saved"
|
|
||||||
|
|
||||||
it "should trigger before save", (test)->
|
User.create {}, ->
|
||||||
User.beforeSave = ()->
|
test.ok "saved"
|
||||||
|
test.done()
|
||||||
|
|
||||||
|
it 'should trigger before save', (test) ->
|
||||||
|
test.expect(3)
|
||||||
|
User.beforeSave = (next) ->
|
||||||
User.beforeSave = null
|
User.beforeSave = null
|
||||||
test.done()
|
@name = 'mr. ' + @name
|
||||||
user = new User
|
next()
|
||||||
user.save ()-> test.ok "saved"
|
user = new User name: 'Jonathan'
|
||||||
|
|
||||||
it "should trigger after save", (test)->
|
user.save ->
|
||||||
User.afterSave = ()->
|
test.equals User.schema.adapter.cache.User[user.id].name, user.name
|
||||||
|
test.equals user.name, 'mr. Jonathan'
|
||||||
|
test.ok 'saved'
|
||||||
|
test.done()
|
||||||
|
|
||||||
|
it 'should trigger after save', (test)->
|
||||||
|
User.afterSave = (next)->
|
||||||
User.afterSave = null
|
User.afterSave = null
|
||||||
test.done()
|
next()
|
||||||
user = new User
|
|
||||||
user.save ()-> test.ok "saved"
|
|
||||||
|
|
||||||
it "should trigger before update", (test)->
|
user = new User
|
||||||
|
user.save ->
|
||||||
|
test.ok "saved"
|
||||||
|
test.done()
|
||||||
|
|
||||||
|
it "should trigger before update", (test) ->
|
||||||
User.beforeUpdate = ()->
|
User.beforeUpdate = ()->
|
||||||
User.beforeUpdate = null
|
User.beforeUpdate = null
|
||||||
test.done()
|
test.done()
|
||||||
User.create {}, (err, user)->
|
User.create {}, (err, user)->
|
||||||
user.updateAttributes {email:"1@1.com"}, ()-> test.ok "updated"
|
user.updateAttributes {email:"1@1.com"}, () -> test.ok "updated"
|
||||||
|
|
||||||
it "should trigger after update", (test)->
|
it "should trigger after update", (test) ->
|
||||||
User.afterUpdate = ()->
|
User.afterUpdate = ()->
|
||||||
User.afterUpdate = null
|
User.afterUpdate = null
|
||||||
test.done()
|
test.done()
|
||||||
|
|
Loading…
Reference in New Issue