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

Commit 5193b0d6 by sdepold

refactored test

1 parent 2c30c2c1
Showing with 20 additions and 14 deletions
...@@ -8,7 +8,7 @@ if(typeof require === 'function') { ...@@ -8,7 +8,7 @@ if(typeof require === 'function') {
buster.spec.expose() buster.spec.expose()
dialects.forEach(function(dialect) { dialects.forEach(function(dialect) {
describe('DAO@' + dialect, function() { describe('DAOFactory@' + dialect, function() {
before(function(done) { before(function(done) {
var self = this var self = this
...@@ -17,7 +17,7 @@ dialects.forEach(function(dialect) { ...@@ -17,7 +17,7 @@ dialects.forEach(function(dialect) {
}) })
this.User = this.sequelize.define('User', { this.User = this.sequelize.define('User', {
username: { type: Sequelize.STRING }, username: Sequelize.STRING,
secretValue: Sequelize.STRING secretValue: Sequelize.STRING
}) })
...@@ -25,6 +25,7 @@ dialects.forEach(function(dialect) { ...@@ -25,6 +25,7 @@ dialects.forEach(function(dialect) {
.getQueryInterface() .getQueryInterface()
.dropAllTables() .dropAllTables()
.success(function() { .success(function() {
self.sequelize.daoFactoryManager.daos = []
self.User self.User
.sync({ force: true }) .sync({ force: true })
.success(done) .success(done)
...@@ -36,29 +37,34 @@ dialects.forEach(function(dialect) { ...@@ -36,29 +37,34 @@ dialects.forEach(function(dialect) {
}) })
describe('create with whitelist', function() { describe('create with whitelist', function() {
var data = { before(function() {
username: 'Peter', this.data = {
secretValue: '42' username: 'Peter',
} secretValue: '42'
}
})
it('should only store the values passed in the witelist', function(done) { it('should only store the values passed in the witelist', function(done) {
var self = this; var self = this;
this.User.create(data, ['username']).success(function(user) {
this.User.create(this.data, ['username']).success(function(user) {
self.User.find(user.id).success(function(_user) { self.User.find(user.id).success(function(_user) {
expect(_user.username).toEqual(data.username); expect(_user.username).toEqual(self.data.username);
expect(_user.secretValue).not.toEqual(data.secretValue); expect(_user.secretValue).not.toEqual(self.data.secretValue);
done(); expect(_user.secretValue).toEqual(null);
done();
}) })
}) })
}) })
it('should store all values if no whitelist is specified', function(done) { it('should store all values if no whitelist is specified', function(done) {
var self = this; var self = this;
this.User.create(data).success(function(user) {
this.User.create(this.data).success(function(user) {
self.User.find(user.id).success(function(_user) { self.User.find(user.id).success(function(_user) {
expect(_user.username).toEqual(data.username); expect(_user.username).toEqual(self.data.username);
expect(_user.secretValue).toEqual(data.secretValue); expect(_user.secretValue).toEqual(self.data.secretValue);
done(); done();
}) })
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!