不要怂,就是干,撸起袖子干!

Commit 4f0efb34 by Sushant

tests to verify changes saved in hooks persists

1 parent fe94906b
...@@ -102,6 +102,55 @@ describe(Support.getTestDialectTeaser('Hooks'), function() { ...@@ -102,6 +102,55 @@ describe(Support.getTestDialectTeaser('Hooks'), function() {
}); });
}); });
}); });
describe('preserves changes to instance', function() {
it('beforeValidate', function(){
var hookCalled = 0;
this.User.beforeValidate(function(user, options) {
user.mood = 'happy';
hookCalled++;
});
return this.User.create({mood: 'sad', username: 'leafninja'}).then(function(user) {
expect(user.mood).to.equal('happy');
expect(user.username).to.equal('leafninja');
expect(hookCalled).to.equal(1);
});
});
it('afterValidate', function() {
var hookCalled = 0;
this.User.afterValidate(function(user, options) {
user.mood = 'neutral';
hookCalled++;
});
return this.User.create({mood: 'sad', username: 'fireninja'}).then(function(user) {
expect(user.mood).to.equal('neutral');
expect(user.username).to.equal('fireninja');
expect(hookCalled).to.equal(1);
});
});
it('beforeCreate', function(){
var hookCalled = 0;
this.User.beforeCreate(function(user, options) {
user.mood = 'happy';
hookCalled++;
});
return this.User.create({username: 'akira'}).then(function(user) {
expect(user.mood).to.equal('happy');
expect(user.username).to.equal('akira');
expect(hookCalled).to.equal(1);
});
});
});
}); });
}); });
...@@ -78,6 +78,37 @@ describe(Support.getTestDialectTeaser('Hooks'), function() { ...@@ -78,6 +78,37 @@ describe(Support.getTestDialectTeaser('Hooks'), function() {
}); });
}); });
}); });
describe('preserves changes to instance', function() {
it('beforeValidate', function(){
this.User.beforeValidate(function(user, options) {
user.mood = 'happy';
});
return this.User.create({username: 'fireninja', mood: 'invalid'}).then(function(user) {
return user.updateAttributes({username: 'hero'});
}).then(function(user) {
expect(user.username).to.equal('hero');
expect(user.mood).to.equal('happy');
});
});
it('afterValidate', function() {
this.User.afterValidate(function(user, options) {
user.mood = 'sad';
});
return this.User.create({username: 'fireninja', mood: 'nuetral'}).then(function(user) {
return user.updateAttributes({username: 'spider'});
}).then(function(user) {
expect(user.username).to.equal('spider');
expect(user.mood).to.equal('sad');
});
});
});
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!