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

Commit c9ce51b4 by Ruben Bridgewater

Refactor all and or where tests to use promises

1 parent e7856524
Showing with 22 additions and 37 deletions
......@@ -12,7 +12,7 @@ chai.use(datetime);
chai.config.includeStack = true;
describe(Support.getTestDialectTeaser('Model'), function() {
beforeEach(function(done) {
beforeEach(function() {
this.User = this.sequelize.define('User', {
username: DataTypes.STRING,
secretValue: DataTypes.STRING,
......@@ -22,17 +22,15 @@ describe(Support.getTestDialectTeaser('Model'), function() {
aBool: DataTypes.BOOLEAN
});
this.User.sync({ force: true }).success(function() {
done();
});
return this.User.sync({ force: true });
});
(['or', 'and']).forEach(function(method) {
var word = method.toUpperCase();
describe.skip('Sequelize.' + method, function() {
it('can handle plain strings', function(done) {
this.User.find({
it('can handle plain strings', function() {
return this.User.find({
where: Sequelize[method]('1=1', '2=2')
}).on('sql', function(sql) {
if (dialect === 'mssql') {
......@@ -40,12 +38,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}else {
expect(sql).to.contain('WHERE (1=1 ' + word + ' 2=2) LIMIT 1');
}
done();
});
});
it('can handle arrays', function(done) {
this.User.find({
it('can handle arrays', function() {
return this.User.find({
where: Sequelize[method](['1=?', 1], ['2=?', 2])
}).on('sql', function(sql) {
if (dialect === 'mssql') {
......@@ -53,12 +50,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}else {
expect(sql).to.contain('WHERE (1=1 ' + word + ' 2=2) LIMIT 1');
}
done();
});
});
it('can handle objects', function(done) {
this.User.find({
it('can handle objects', function() {
return this.User.find({
where: Sequelize[method]({ username: 'foo', intVal: 2 }, { secretValue: 'bar' })
}).on('sql', function(sql) {
var expectation = ({
......@@ -75,13 +71,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
expect(sql).to.contain(expectation);
done();
});
});
it('can handle numbers', function(done) {
this.User.find({
it('can handle numbers', function() {
return this.User.find({
where: Sequelize[method](1, 2)
}).on('sql', function(sql) {
var expectation = ({
......@@ -98,16 +92,14 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
expect(sql).to.contain(expectation);
done();
});
});
});
});
describe.skip('Combinations of Sequelize.and and Sequelize.or', function() {
it('allows nesting of Sequelize.or', function(done) {
this.User.find({
it('allows nesting of Sequelize.or', function() {
return this.User.find({
where: Sequelize.and(Sequelize.or('1=1', '2=2'), Sequelize.or('3=3', '4=4'))
}).on('sql', function(sql) {
if (dialect === 'mssql') {
......@@ -115,12 +107,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}else {
expect(sql).to.contain('WHERE ((1=1 OR 2=2) AND (3=3 OR 4=4)) LIMIT 1');
}
done();
});
});
it('allows nesting of Sequelize.or using object notation', function(done) {
this.User.find({
it('allows nesting of Sequelize.or using object notation', function() {
return this.User.find({
where: Sequelize.and(Sequelize.or({username: {eq: 'foo'}}, {username: {eq: 'bar'}}),
Sequelize.or({id: {eq: 1}}, {id: {eq: 4}}))
}).on('sql', function(sql) {
......@@ -138,12 +129,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
expect(sql).to.contain(expectation);
done();
});
});
it('allows nesting of Sequelize.and', function(done) {
this.User.find({
it('allows nesting of Sequelize.and', function() {
return this.User.find({
where: Sequelize.or(Sequelize.and('1=1', '2=2'), Sequelize.and('3=3', '4=4'))
}).on('sql', function(sql) {
if (dialect === 'mssql') {
......@@ -151,12 +141,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}else {
expect(sql).to.contain('WHERE ((1=1 AND 2=2) OR (3=3 AND 4=4)) LIMIT 1');
}
done();
});
});
it('allows nesting of Sequelize.and using object notation', function(done) {
this.User.find({
it('allows nesting of Sequelize.and using object notation', function() {
return this.User.find({
where: Sequelize.or(Sequelize.and({username: {eq: 'foo'}}, {username: {eq: 'bar'}}),
Sequelize.and({id: {eq: 1}}, {id: {eq: 4}}))
}).on('sql', function(sql) {
......@@ -174,24 +163,22 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}
expect(sql).to.contain(expectation);
done();
});
});
if (dialect !== 'postgres') {
it('still allows simple arrays lookups', function(done) {
this.User.find({
it('still allows simple arrays lookups', function() {
return this.User.find({
where: ['id IN (?) OR id IN (?)', [1, 2], [3, 4]]
}).on('sql', function(sql) {
expect(sql).to.contain('id IN (1, 2) OR id IN (3, 4)');
done();
});
});
}
(['find', 'findAll']).forEach(function(finderMethod) {
it('correctly handles complex combinations', function(done) {
this.User[finderMethod]({
it('correctly handles complex combinations', function() {
return this.User[finderMethod]({
where: [
42, '2=2', ['1=?', 1], { username: 'foo' },
Sequelize.or(
......@@ -258,8 +245,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
')'
);
}
done();
});
});
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!