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

Commit 6700695d by Ruben Bridgewater

Fix a couple tests

1 parent 8a3672c9
......@@ -25,7 +25,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
(['or', 'and']).forEach(function(method) {
var word = method.toUpperCase();
describe.skip('Sequelize.' + method, function() {
describe('Sequelize.' + method, function() {
it('can handle plain strings', function() {
return this.User.find({
where: Sequelize[method]('1=1', '2=2')
......@@ -33,38 +33,38 @@ describe(Support.getTestDialectTeaser('Model'), function() {
logging: function(sql) {
if (dialect === 'mssql') {
expect(sql).to.contain('WHERE (1=1 ' + word + ' 2=2)');
}else {
} else {
expect(sql).to.contain('WHERE (1=1 ' + word + ' 2=2) LIMIT 1');
}
}
});
});
it('can handle arrays', function() {
it.skip('can handle arrays', function() {
return this.User.find({
where: Sequelize[method](['1=?', 1], ['2=?', 2])
}, {
logging: function(sql) {
if (dialect === 'mssql') {
expect(sql).to.contain('WHERE (1=1 ' + word + ' 2=2)');
}else {
} else {
expect(sql).to.contain('WHERE (1=1 ' + word + ' 2=2) LIMIT 1');
}
}
});
});
it('can handle objects', function() {
it.skip('can handle objects', function() {
return this.User.find({
where: Sequelize[method]({ username: 'foo', intVal: 2 }, { secretValue: 'bar' })
}, {
logging: function(sql) {
var expectation = ({
mysql: "WHERE (`User`.`username`='foo' AND `User`.`intVal`=2 " + word + " `User`.`secretValue`='bar')",
mssql: 'WHERE ([User].[username]=\'foo\' AND [User].[intVal]=2 ' + word + ' [User].[secretValue]=\'bar\')',
sqlite: "WHERE (`User`.`username`='foo' AND `User`.`intVal`=2 " + word + " `User`.`secretValue`='bar')",
postgres: 'WHERE ("User"."username"=\'foo\' AND "User"."intVal"=2 ' + word + ' "User"."secretValue"=\'bar\')',
mariadb: "WHERE (`User`.`username`='foo' AND `User`.`intVal`=2 " + word + " `User`.`secretValue`='bar')"
mysql: "WHERE (`User`.`username` = 'foo' AND `User`.`intVal` = 2 " + word + " `User`.`secretValue` = 'bar')",
mssql: 'WHERE ([User].[username] = \'foo\' AND [User].[intVal] = 2 ' + word + ' [User].[secretValue] = \'bar\')',
sqlite: "WHERE (`User`.`username` = 'foo' AND `User`.`intVal` = 2 " + word + " `User`.`secretValue` = 'bar')",
postgres: 'WHERE ("User"."username" = \'foo\' AND "User"."intVal" = 2 ' + word + ' "User"."secretValue" = \'bar\')',
mariadb: "WHERE (`User`.`username` = 'foo' AND `User`.`intVal` = 2 " + word + " `User`.`secretValue` = 'bar')"
})[Support.getTestDialect()];
if (!expectation) {
......@@ -81,11 +81,11 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}, {
logging: function(sql) {
var expectation = ({
mysql: 'WHERE (`User`.`id`=1 ' + word + ' `User`.`id`=2)',
sqlite: 'WHERE (`User`.`id`=1 ' + word + ' `User`.`id`=2)',
postgres: 'WHERE ("User"."id"=1 ' + word + ' "User"."id"=2)',
mssql: 'WHERE ([User].[id]=1 ' + word + ' [User].[id]=2)',
mariadb: 'WHERE (`User`.`id`=1 ' + word + ' `User`.`id`=2)'
mysql: 'WHERE (`User`.`id` = 1 ' + word + ' `User`.`id` = 2)',
sqlite: 'WHERE (`User`.`id` = 1 ' + word + ' `User`.`id` = 2)',
postgres: 'WHERE ("User"."id" = 1 ' + word + ' "User"."id" = 2)',
mssql: 'WHERE ([User].[id] = 1 ' + word + ' [User].[id] = 2)',
mariadb: 'WHERE (`User`.`id` = 1 ' + word + ' `User`.`id` = 2)'
})[Support.getTestDialect()];
if (!expectation) {
......@@ -98,7 +98,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
describe.skip('Combinations of Sequelize.and and Sequelize.or', function() {
describe('Combinations of Sequelize.and and Sequelize.or', function() {
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'))
......@@ -115,8 +115,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
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}}))
where: Sequelize.and(Sequelize.or({username: {$eq: 'foo'}}, {username: {$eq: 'bar'}}),
Sequelize.or({id: {$eq: 1}}, {id: {$eq: 4}}))
}, {
logging: function(sql) {
var expectation = ({
......@@ -152,8 +152,8 @@ describe(Support.getTestDialectTeaser('Model'), function() {
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}}))
where: Sequelize.or(Sequelize.and({username: {$eq: 'foo'}}, {username: {$eq: 'bar'}}),
Sequelize.and({id: {$eq: 1}}, {id: {$eq: 4}}))
}, {
logging: function(sql) {
var expectation = ({
......@@ -174,6 +174,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
if (dialect !== 'postgres') {
// TODO: Fix this. There's a weird output produced by SqlString.arrayToList
it('still allows simple arrays lookups', function() {
return this.User.find({
where: ['id IN (?) OR id IN (?)', [1, 2], [3, 4]]
......@@ -206,16 +207,16 @@ describe(Support.getTestDialectTeaser('Model'), function() {
if (dialect === 'postgres') {
expect(sql).to.contain(
'WHERE (' + [
'"User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\' AND ',
'"User"."id" = 42 AND 2=2 AND (1=1) AND "User"."username" = \'foo\' AND ',
'(',
'"User"."id"=42 OR 2=2 OR 1=1 OR "User"."username"=\'foo\' OR ',
'("User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\') OR ',
'("User"."id"=42 OR 2=2 OR 1=1 OR "User"."username"=\'foo\')',
'"User"."id" = 42 OR 2=2 OR (1=1) OR "User"."username" = \'foo\' OR ',
'("User"."id" = 42 AND 2=2 AND (1=1) AND "User"."username" = \'foo\') OR ',
'("User"."id" = 42 OR 2=2 OR (1=1) OR "User"."username" = \'foo\')',
') AND ',
'(',
'"User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\' AND ',
'("User"."id"=42 OR 2=2 OR 1=1 OR "User"."username"=\'foo\') AND ',
'("User"."id"=42 AND 2=2 AND 1=1 AND "User"."username"=\'foo\')',
'"User"."id" = 42 AND 2=2 AND (1=1) AND "User"."username" = \'foo\' AND ',
'("User"."id" = 42 OR 2=2 OR (1=1) OR "User"."username" = \'foo\') AND ',
'("User"."id" = 42 AND 2=2 AND (1=1) AND "User"."username" = \'foo\')',
')'
].join('') +
')'
......@@ -223,16 +224,16 @@ describe(Support.getTestDialectTeaser('Model'), function() {
} else if (dialect === 'mssql') {
expect(sql).to.contain(
'WHERE (' + [
'[User].[id]=42 AND 2=2 AND 1=1 AND [User].[username]=\'foo\' AND ',
'[User].[id] = 42 AND 2=2 AND (1=1) AND [User].[username] = \'foo\' AND ',
'(',
'[User].[id]=42 OR 2=2 OR 1=1 OR [User].[username]=\'foo\' OR ',
'([User].[id]=42 AND 2=2 AND 1=1 AND [User].[username]=\'foo\') OR ',
'([User].[id]=42 OR 2=2 OR 1=1 OR [User].[username]=\'foo\')',
'[User].[id] = 42 OR 2=2 OR (1=1) OR [User].[username] = \'foo\' OR ',
'([User].[id] = 42 AND 2=2 AND (1=1) AND [User].[username] = \'foo\') OR ',
'([User].[id] = 42 OR 2=2 OR (1=1) OR [User].[username] = \'foo\')',
') AND ',
'(',
'[User].[id]=42 AND 2=2 AND 1=1 AND [User].[username]=\'foo\' AND ',
'([User].[id]=42 OR 2=2 OR 1=1 OR [User].[username]=\'foo\') AND ',
'([User].[id]=42 AND 2=2 AND 1=1 AND [User].[username]=\'foo\')',
'[User].[id] = 42 AND 2=2 AND (1=1) AND [User].[username] = \'foo\' AND ',
'([User].[id] = 42 OR 2=2 OR (1=1) OR [User].[username] = \'foo\') AND ',
'([User].[id] = 42 AND 2=2 AND (1=1) AND [User].[username] = \'foo\')',
')'
].join('') +
')'
......@@ -240,16 +241,16 @@ describe(Support.getTestDialectTeaser('Model'), function() {
} else {
expect(sql).to.contain(
'WHERE (' + [
"`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo' AND ",
"`User`.`id` = 42 AND 2=2 AND (1=1) AND `User`.`username` = 'foo' AND ",
'(',
"`User`.`id`=42 OR 2=2 OR 1=1 OR `User`.`username`='foo' OR ",
"(`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo') OR ",
"(`User`.`id`=42 OR 2=2 OR 1=1 OR `User`.`username`='foo')",
"`User`.`id` = 42 OR 2=2 OR (1=1) OR `User`.`username` = 'foo' OR ",
"(`User`.`id` = 42 AND 2=2 AND (1=1) AND `User`.`username` = 'foo') OR ",
"(`User`.`id` = 42 OR 2=2 OR (1=1) OR `User`.`username` = 'foo')",
') AND ',
'(',
"`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo' AND ",
"(`User`.`id`=42 OR 2=2 OR 1=1 OR `User`.`username`='foo') AND ",
"(`User`.`id`=42 AND 2=2 AND 1=1 AND `User`.`username`='foo')",
"`User`.`id` = 42 AND 2=2 AND (1=1) AND `User`.`username` = 'foo' AND ",
"(`User`.`id` = 42 OR 2=2 OR (1=1) OR `User`.`username` = 'foo') AND ",
"(`User`.`id` = 42 AND 2=2 AND (1=1) AND `User`.`username` = 'foo')",
')'
].join('') +
')'
......
......@@ -44,6 +44,7 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
return Promise.resolve();
});
});
it('supports automatically rolling back with a thrown error', function() {
var t;
return (expect(this.sequelize.transaction(function(transaction) {
......@@ -53,15 +54,24 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
expect(t.finished).to.be.equal('rollback');
});
});
it('supports automatically rolling back with a rejection', function() {
return expect(this.sequelize.transaction(function() {
var t;
return (expect(this.sequelize.transaction(function(transaction) {
t = transaction;
return Promise.reject('Swag');
})).to.eventually.be.rejected;
})).to.eventually.be.rejected).then(function() {
expect(t.finished).to.be.equal('rollback');
});
});
it('errors when no promise chain is returned', function() {
return expect(this.sequelize.transaction(function() {
})).to.eventually.be.rejected;
it('errors when no promise chain is returned', function() {
var t;
return (expect(this.sequelize.transaction(function(transaction) {
t = transaction;
})).to.eventually.be.rejected).then(function() {
expect(t.finished).to.be.equal('rollback');
});
});
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!