Skip to content
Browse files

Describe test case

  • Loading branch information...
1 parent c457f6a commit 1ad0d91e576a756d00463f88eba2a3860fa46230 @1602 committed Dec 11, 2011
Showing with 43 additions and 30 deletions.
  1. +5 −5 test/common_test.js
  2. +38 −25 test/hookable_test.coffee
View
10 test/common_test.js
@@ -48,7 +48,7 @@ function testOrm(schema) {
approved: Boolean,
joinedAt: Date,
age: Number,
- password: String
+ passwd: String
});
Post = schema.define('Post', {
@@ -238,8 +238,8 @@ function testOrm(schema) {
it('should handle virtual attributes', function (test) {
var salt = 's0m3s3cr3t5a1t';
- User.setter.password = function (password) {
- this._password = calcHash(password, salt);
+ User.setter.passwd = function (password) {
+ this._passwd = calcHash(password, salt);
};
function calcHash(pass, salt) {
@@ -251,8 +251,8 @@ function testOrm(schema) {
}
var u = new User;
- u.password = 's3cr3t';
- test.equal(u.password, calcHash('s3cr3t', salt));
+ u.passwd = 's3cr3t';
+ test.equal(u.passwd, calcHash('s3cr3t', salt));
test.done();
});
View
63 test/hookable_test.coffee
@@ -30,39 +30,52 @@ it "should trigger before create", (test)->
test.done()
User.create {}, ()-> test.ok "saved"
-it "should trigger after create", (test)->
- User.afterCreate = ()->
- User.afterCreate = null
- test.done()
- User.create {}, ()-> test.ok "saved"
+it "should trigger after create", (test) ->
+ User.afterCreate = (next) ->
+ User.afterCreate = null
+ next()
-it "should trigger before save", (test)->
- User.beforeSave = ()->
- User.beforeSave = null
- test.done()
- user = new User
- user.save ()-> test.ok "saved"
+ User.create {}, ->
+ test.ok "saved"
+ test.done()
-it "should trigger after save", (test)->
- User.afterSave = ()->
- User.afterSave = null
- test.done()
- user = new User
- user.save ()-> test.ok "saved"
+it 'should trigger before save', (test) ->
+ test.expect(3)
+ User.beforeSave = (next) ->
+ User.beforeSave = null
+ @name = 'mr. ' + @name
+ next()
+ user = new User name: 'Jonathan'
-it "should trigger before update", (test)->
+ user.save ->
+ 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
+ next()
+
+ user = new User
+ user.save ->
+ test.ok "saved"
+ test.done()
+
+it "should trigger before update", (test) ->
User.beforeUpdate = ()->
User.beforeUpdate = null
test.done()
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)->
- User.afterUpdate = ()->
- User.afterUpdate = null
- test.done()
- User.create {}, (err, user)->
- user.updateAttributes {email:"1@1.com"}, ()-> test.ok "updated"
+it "should trigger after update", (test) ->
+ User.afterUpdate = ()->
+ User.afterUpdate = null
+ test.done()
+ User.create {}, (err, user)->
+ user.updateAttributes {email:"1@1.com"}, ()-> test.ok "updated"
it "should trigger before destroy", (test)->
User.beforeDestroy = ()->

0 comments on commit 1ad0d91

Please sign in to comment.
Something went wrong with that request. Please try again.