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

Commit 3568ced8 by Ruben Bridgewater

Refactor more tests

1 parent 0d383338
......@@ -14,9 +14,9 @@ if (Support.dialectIsMySQL()) {
var User = this.sequelize.define('User', { username: DataTypes.STRING })
, spy = sinon.spy();
User.sync({force: true}).on('success', function() {
User.create({username: 'user1'}).on('success', function() {
User.count().on('success', function(count) {
User.sync({force: true}).then(function() {
User.create({username: 'user1'}).then(function() {
User.count().then(function(count) {
expect(count).to.equal(1);
spy();
......
......@@ -12,147 +12,131 @@ chai.config.includeStack = true;
if (dialect === 'sqlite') {
describe('[SQLITE Specific] DAOFactory', function() {
after(function(done) {
after(function() {
this.sequelize.options.storage = ':memory:';
done();
});
beforeEach(function(done) {
beforeEach(function() {
this.sequelize.options.storage = dbFile;
this.User = this.sequelize.define('User', {
age: DataTypes.INTEGER,
name: DataTypes.STRING,
bio: DataTypes.TEXT
});
this.User.sync({ force: true }).success(function() {
done();
});
return this.User.sync({ force: true });
});
storages.forEach(function(storage) {
describe('with storage "' + storage + '"', function() {
after(function(done) {
after(function() {
if (storage === dbFile) {
require('fs').writeFile(dbFile, '', function() {
done();
});
require('fs').writeFileSync(dbFile, '');
}
});
describe('create', function() {
it('creates a table entry', function(done) {
it('creates a table entry', function() {
var self = this;
this.User.create({ age: 21, name: 'John Wayne', bio: 'noot noot' }).success(function(user) {
return this.User.create({ age: 21, name: 'John Wayne', bio: 'noot noot' }).then(function(user) {
expect(user.age).to.equal(21);
expect(user.name).to.equal('John Wayne');
expect(user.bio).to.equal('noot noot');
self.User.all().success(function(users) {
return self.User.findAll().then(function(users) {
var usernames = users.map(function(user) {
return user.name;
});
expect(usernames).to.contain('John Wayne');
done();
});
});
});
it('should allow the creation of an object with options as attribute', function(done) {
it('should allow the creation of an object with options as attribute', function() {
var Person = this.sequelize.define('Person', {
name: DataTypes.STRING,
options: DataTypes.TEXT
});
Person.sync({ force: true }).success(function() {
return Person.sync({ force: true }).then(function() {
var options = JSON.stringify({ foo: 'bar', bar: 'foo' });
Person.create({
return Person.create({
name: 'John Doe',
options: options
}).success(function(people) {
}).then(function(people) {
expect(people.options).to.deep.equal(options);
done();
});
});
});
it('should allow the creation of an object with a boolean (true) as attribute', function(done) {
it('should allow the creation of an object with a boolean (true) as attribute', function() {
var Person = this.sequelize.define('Person', {
name: DataTypes.STRING,
has_swag: DataTypes.BOOLEAN
});
Person.sync({ force: true }).success(function() {
Person.create({
return Person.sync({ force: true }).then(function() {
return Person.create({
name: 'John Doe',
has_swag: true
}).success(function(people) {
}).then(function(people) {
expect(people.has_swag).to.be.ok;
done();
});
});
});
it('should allow the creation of an object with a boolean (false) as attribute', function(done) {
it('should allow the creation of an object with a boolean (false) as attribute', function() {
var Person = this.sequelize.define('Person', {
name: DataTypes.STRING,
has_swag: DataTypes.BOOLEAN
});
Person.sync({ force: true }).success(function() {
Person.create({
return Person.sync({ force: true }).then(function() {
return Person.create({
name: 'John Doe',
has_swag: false
}).success(function(people) {
}).then(function(people) {
expect(people.has_swag).to.not.be.ok;
done();
});
});
});
});
describe('.find', function() {
beforeEach(function(done) {
this.User.create({name: 'user', bio: 'footbar'}).success(function() {
done();
});
beforeEach(function() {
return this.User.create({name: 'user', bio: 'footbar'});
});
it('finds normal lookups', function(done) {
this.User.find({ where: { name: 'user' } }).success(function(user) {
it('finds normal lookups', function() {
return this.User.find({ where: { name: 'user' } }).then(function(user) {
expect(user.name).to.equal('user');
done();
});
});
it.skip('should make aliased attributes available', function(done) {
this.User.find({ where: { name: 'user' }, attributes: ['id', ['name', 'username']] }).success(function(user) {
it.skip('should make aliased attributes available', function() {
return this.User.find({ where: { name: 'user' }, attributes: ['id', ['name', 'username']] }).then(function(user) {
expect(user.username).to.equal('user');
done();
});
});
});
describe('.all', function() {
beforeEach(function(done) {
this.User.bulkCreate([
beforeEach(function() {
return this.User.bulkCreate([
{name: 'user', bio: 'foobar'},
{name: 'user', bio: 'foobar'}
]).success(function() {
done();
});
]);
});
it('should return all users', function(done) {
this.User.all().on('success', function(users) {
it('should return all users', function() {
return this.User.findAll().then(function(users) {
expect(users).to.have.length(2);
done();
});
});
});
describe('.min', function() {
it('should return the min value', function(done) {
it('should return the min value', function() {
var self = this
, users = [];
......@@ -160,17 +144,16 @@ if (dialect === 'sqlite') {
users[users.length] = {age: i};
}
this.User.bulkCreate(users).success(function() {
self.User.min('age').on('success', function(min) {
return this.User.bulkCreate(users).then(function() {
return self.User.min('age').then(function(min) {
expect(min).to.equal(2);
done();
});
});
});
});
describe('.max', function() {
it('should return the max value', function(done) {
it('should return the max value', function() {
var self = this
, users = [];
......@@ -178,10 +161,9 @@ if (dialect === 'sqlite') {
users[users.length] = {age: i};
}
this.User.bulkCreate(users).success(function() {
self.User.max('age').on('success', function(min) {
return this.User.bulkCreate(users).then(function() {
return self.User.max('age').then(function(min) {
expect(min).to.equal(5);
done();
});
});
});
......
......@@ -10,29 +10,26 @@ chai.config.includeStack = true;
if (dialect === 'sqlite') {
describe('[SQLITE Specific] DAO', function() {
beforeEach(function(done) {
beforeEach(function() {
this.User = this.sequelize.define('User', {
username: DataTypes.STRING
});
this.User.sync({ force: true }).success(function() {
done();
});
return this.User.sync({ force: true });
});
describe('findAll', function() {
it('handles dates correctly', function(done) {
it('handles dates correctly', function() {
var self = this
, user = this.User.build({ username: 'user' });
user.dataValues['createdAt'] = new Date(2011, 4, 4);
user.save().success(function() {
self.User.create({ username: 'new user' }).success(function() {
self.User.findAll({
return user.save().then(function() {
return self.User.create({ username: 'new user' }).then(function() {
return self.User.findAll({
where: ['createdAt > ?', new Date(2012, 1, 1)]
}).success(function(users) {
}).then(function(users) {
expect(users).to.have.length(1);
done();
});
});
});
......
......@@ -762,7 +762,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
User.sync({force: true}).success(function() {
User.create({myvals: [1, 2, 3, 4], mystr: ['One', 'Two', 'Three', 'Four']}).on('success', function(user) {
User.create({myvals: [1, 2, 3, 4], mystr: ['One', 'Two', 'Three', 'Four']}).then(function(user) {
user.myvals = [];
user.mystr = [];
user.save().on('sql', function(sql) {
......@@ -879,7 +879,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
User.sync({ force: true }).success(function() {
User.create({ big: '9223372036854775807' }).on('success', function(user) {
User.create({ big: '9223372036854775807' }).then(function(user) {
expect(user.big).to.be.equal('9223372036854775807');
done();
});
......@@ -892,10 +892,10 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
User.sync({ force: true }).success(function() {
User.create({}).on('success', function(user) {
User.create({}).then(function(user) {
expect(user.userid).to.equal(1);
User.create({}).on('success', function(user) {
User.create({}).then(function(user) {
expect(user.userid).to.equal(2);
done();
});
......
......@@ -1251,7 +1251,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
it('finds all entries', function(done) {
this.User.all().on('success', function(users) {
this.User.all().then(function(users) {
expect(users.length).to.equal(2);
done();
});
......@@ -1535,7 +1535,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
it('should return all users', function(done) {
this.User.all().on('success', function(users) {
this.User.all().then(function(users) {
expect(users.length).to.equal(2);
done();
});
......
......@@ -383,7 +383,7 @@ describe(Support.getTestDialectTeaser('Promise'), function() {
resolve('yoohoo');
});
promise.on('success', spy);
promise.then(spy);
promise.then(function() {
expect(spy.calledOnce).to.be.true;
expect(spy.firstCall.args).to.deep.equal(['yoohoo']);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!