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

Commit 4df0e8e9 by Mick Hansen

fix more tests

1 parent 043077ba
...@@ -838,7 +838,7 @@ module.exports = (function() { ...@@ -838,7 +838,7 @@ module.exports = (function() {
// Add WHERE to sub or main query // Add WHERE to sub or main query
if (options.hasOwnProperty('where')) { if (options.hasOwnProperty('where')) {
options.where = this.getWhereConditions(options.where, mainTableAs, Model, options) options.where = this.getWhereConditions(options.where, mainTableAs || tableName, Model, options)
if (subQuery) { if (subQuery) {
subQueryItems.push(" WHERE " + options.where) subQueryItems.push(" WHERE " + options.where)
} else { } else {
......
...@@ -1937,8 +1937,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -1937,8 +1937,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
var tableName = '' var tableName = ''
, ident = this.sequelize.queryInterface.QueryGenerator.quoteIdentifier , ident = this.sequelize.queryInterface.QueryGenerator.quoteIdentifier
, escape = this.sequelize.queryInterface.QueryGenerator.escape , escape = this.sequelize.queryInterface.QueryGenerator.escape
if(this.Project.tableName) { if(this.Project.name) {
tableName = ident(this.Project.tableName) + '.' tableName = ident(this.Project.name) + '.'
} }
this.User.findAll({ this.User.findAll({
where: [ where: [
...@@ -1962,8 +1962,9 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -1962,8 +1962,9 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
it('should not overwrite a specified deletedAt', function(done) { it('should not overwrite a specified deletedAt', function(done) {
var tableName = '' var tableName = ''
, ident = this.sequelize.queryInterface.QueryGenerator.quoteIdentifier , ident = this.sequelize.queryInterface.QueryGenerator.quoteIdentifier
if(this.User.tableName) {
tableName = ident(this.User.tableName) + '.' if(this.User.name) {
tableName = ident(this.User.name) + '.'
} }
this.User.findAll({ this.User.findAll({
where: [ where: [
......
...@@ -617,7 +617,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () { ...@@ -617,7 +617,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
Page.create({ content: 'om nom nom' }).success(function(page) { Page.create({ content: 'om nom nom' }).success(function(page) {
book.setPages([ page ]).success(function() { book.setPages([ page ]).success(function() {
Book.find({ Book.find({
where: (dialect === 'postgres' ? '"Books"."id"=' : '`Books`.`id`=') + book.id, where: (dialect === 'postgres' ? '"Book"."id"=' : '`Book`.`id`=') + book.id,
include: [Page] include: [Page]
}).success(function(leBook) { }).success(function(leBook) {
page.updateAttributes({ content: 'something totally different' }).success(function(page) { page.updateAttributes({ content: 'something totally different' }).success(function(page) {
......
...@@ -394,7 +394,7 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -394,7 +394,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
]} ]}
], ],
order: [ order: [
['Users.id', 'ASC'] ['User.id', 'ASC']
] ]
}).done(function (err, users) { }).done(function (err, users) {
expect(err).not.to.be.ok expect(err).not.to.be.ok
...@@ -1394,7 +1394,7 @@ describe(Support.getTestDialectTeaser("Include"), function () { ...@@ -1394,7 +1394,7 @@ describe(Support.getTestDialectTeaser("Include"), function () {
], ],
limit: 3, limit: 3,
order: [ order: [
[self.sequelize.col(self.models.Product.tableName+'.id'), 'ASC'] [self.sequelize.col(self.models.Product.name+'.id'), 'ASC']
] ]
}).done(function (err, products) { }).done(function (err, products) {
expect(err).not.to.be.ok expect(err).not.to.be.ok
......
...@@ -158,7 +158,7 @@ if (dialect.match(/^postgres/)) { ...@@ -158,7 +158,7 @@ if (dialect.match(/^postgres/)) {
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
}, },
{ {
arguments: ['mySchema.myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}], arguments: [{schema: 'mySchema', tableName: 'myTable'}, {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}],
expectation: "CREATE TABLE IF NOT EXISTS mySchema.myTable (title VARCHAR(255), name VARCHAR(255));", expectation: "CREATE TABLE IF NOT EXISTS mySchema.myTable (title VARCHAR(255), name VARCHAR(255));",
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
}, },
...@@ -586,13 +586,13 @@ if (dialect.match(/^postgres/)) { ...@@ -586,13 +586,13 @@ if (dialect.match(/^postgres/)) {
expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL) RETURNING *;", expectation: "INSERT INTO \"myTable\" (\"name\",\"nullValue\") VALUES ('foo',NULL),('bar',NULL) RETURNING *;",
context: {options: {omitNull: true}} // Note: As above context: {options: {omitNull: true}} // Note: As above
}, { }, {
arguments: ['mySchema.myTable', [{name: 'foo'}, {name: 'bar'}]], arguments: [{schema: 'mySchema', tableName: 'myTable'}, [{name: 'foo'}, {name: 'bar'}]],
expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'),('bar') RETURNING *;" expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'),('bar') RETURNING *;"
}, { }, {
arguments: ['mySchema.myTable', [{name: JSON.stringify({info: 'Look ma a " quote'})}, {name: JSON.stringify({info: 'Look ma another " quote'})}]], arguments: [{schema: 'mySchema', tableName: 'myTable'}, [{name: JSON.stringify({info: 'Look ma a " quote'})}, {name: JSON.stringify({info: 'Look ma another " quote'})}]],
expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('{\"info\":\"Look ma a \\\" quote\"}'),('{\"info\":\"Look ma another \\\" quote\"}') RETURNING *;" expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('{\"info\":\"Look ma a \\\" quote\"}'),('{\"info\":\"Look ma another \\\" quote\"}') RETURNING *;"
}, { }, {
arguments: ['mySchema.myTable', [{name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'bar'}]], arguments: [{schema: 'mySchema', tableName: 'myTable'}, [{name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'bar'}]],
expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'';DROP TABLE mySchema.myTable;'),('bar') RETURNING *;" expectation: "INSERT INTO \"mySchema\".\"myTable\" (\"name\") VALUES ('foo'';DROP TABLE mySchema.myTable;'),('bar') RETURNING *;"
}, },
...@@ -630,15 +630,15 @@ if (dialect.match(/^postgres/)) { ...@@ -630,15 +630,15 @@ if (dialect.match(/^postgres/)) {
expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL) RETURNING *;", expectation: "INSERT INTO myTable (name,nullValue) VALUES ('foo',NULL),('bar',NULL) RETURNING *;",
context: {options: {omitNull: true, quoteIdentifiers: false}} // Note: As above context: {options: {omitNull: true, quoteIdentifiers: false}} // Note: As above
}, { }, {
arguments: ['mySchema.myTable', [{name: 'foo'}, {name: 'bar'}]], arguments: [{schema: 'mySchema', tableName: 'myTable'}, [{name: 'foo'}, {name: 'bar'}]],
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo'),('bar') RETURNING *;", expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo'),('bar') RETURNING *;",
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
}, { }, {
arguments: ['mySchema.myTable', [{name: JSON.stringify({info: 'Look ma a " quote'})}, {name: JSON.stringify({info: 'Look ma another " quote'})}]], arguments: [{schema: 'mySchema', tableName: 'myTable'}, [{name: JSON.stringify({info: 'Look ma a " quote'})}, {name: JSON.stringify({info: 'Look ma another " quote'})}]],
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('{\"info\":\"Look ma a \\\" quote\"}'),('{\"info\":\"Look ma another \\\" quote\"}') RETURNING *;", expectation: "INSERT INTO mySchema.myTable (name) VALUES ('{\"info\":\"Look ma a \\\" quote\"}'),('{\"info\":\"Look ma another \\\" quote\"}') RETURNING *;",
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
}, { }, {
arguments: ['mySchema.myTable', [{name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'bar'}]], arguments: [{schema: 'mySchema', tableName: 'myTable'}, [{name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'bar'}]],
expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo'';DROP TABLE mySchema.myTable;'),('bar') RETURNING *;", expectation: "INSERT INTO mySchema.myTable (name) VALUES ('foo'';DROP TABLE mySchema.myTable;'),('bar') RETURNING *;",
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
} }
...@@ -737,11 +737,11 @@ if (dialect.match(/^postgres/)) { ...@@ -737,11 +737,11 @@ if (dialect.match(/^postgres/)) {
expectation: "UPDATE myTable SET bar=2 WHERE name='foo' RETURNING *", expectation: "UPDATE myTable SET bar=2 WHERE name='foo' RETURNING *",
context: {options: {omitNull: true, quoteIdentifiers: false}}, context: {options: {omitNull: true, quoteIdentifiers: false}},
}, { }, {
arguments: ['mySchema.myTable', {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, {id: 2}], arguments: [{schema: 'mySchema', tableName: 'myTable'}, {name: 'foo', birthday: moment("2011-03-27 10:01:55 +0000", "YYYY-MM-DD HH:mm:ss Z").toDate()}, {id: 2}],
expectation: "UPDATE mySchema.myTable SET name='foo',birthday='2011-03-27 10:01:55.000 +00:00' WHERE id=2 RETURNING *", expectation: "UPDATE mySchema.myTable SET name='foo',birthday='2011-03-27 10:01:55.000 +00:00' WHERE id=2 RETURNING *",
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
}, { }, {
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'foo'}], arguments: [{schema: 'mySchema', tableName: 'myTable'}, {name: "foo';DROP TABLE mySchema.myTable;"}, {name: 'foo'}],
expectation: "UPDATE mySchema.myTable SET name='foo'';DROP TABLE mySchema.myTable;' WHERE name='foo' RETURNING *", expectation: "UPDATE mySchema.myTable SET name='foo'';DROP TABLE mySchema.myTable;' WHERE name='foo' RETURNING *",
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
} }
...@@ -767,10 +767,10 @@ if (dialect.match(/^postgres/)) { ...@@ -767,10 +767,10 @@ if (dialect.match(/^postgres/)) {
arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}, {limit: 10}], arguments: ['myTable', {name: "foo';DROP TABLE myTable;"}, {limit: 10}],
expectation: "DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"name\"='foo'';DROP TABLE myTable;' LIMIT 10)" expectation: "DELETE FROM \"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"myTable\" WHERE \"name\"='foo'';DROP TABLE myTable;' LIMIT 10)"
}, { }, {
arguments: ['mySchema.myTable', {name: 'foo'}], arguments: [{schema: 'mySchema', tableName: 'myTable'}, {name: 'foo'}],
expectation: "DELETE FROM \"mySchema\".\"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"mySchema\".\"myTable\" WHERE \"name\"='foo' LIMIT 1)" expectation: "DELETE FROM \"mySchema\".\"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"mySchema\".\"myTable\" WHERE \"name\"='foo' LIMIT 1)"
}, { }, {
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}, {limit: 10}], arguments: [{schema: 'mySchema', tableName: 'myTable'}, {name: "foo';DROP TABLE mySchema.myTable;"}, {limit: 10}],
expectation: "DELETE FROM \"mySchema\".\"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"mySchema\".\"myTable\" WHERE \"name\"='foo'';DROP TABLE mySchema.myTable;' LIMIT 10)" expectation: "DELETE FROM \"mySchema\".\"myTable\" WHERE \"id\" IN (SELECT \"id\" FROM \"mySchema\".\"myTable\" WHERE \"name\"='foo'';DROP TABLE mySchema.myTable;' LIMIT 10)"
}, { }, {
arguments: ['myTable', {name: 'foo'}, {limit: null}], arguments: ['myTable', {name: 'foo'}, {limit: null}],
...@@ -795,11 +795,11 @@ if (dialect.match(/^postgres/)) { ...@@ -795,11 +795,11 @@ if (dialect.match(/^postgres/)) {
expectation: "DELETE FROM myTable WHERE id IN (SELECT id FROM myTable WHERE name='foo'';DROP TABLE myTable;' LIMIT 10)", expectation: "DELETE FROM myTable WHERE id IN (SELECT id FROM myTable WHERE name='foo'';DROP TABLE myTable;' LIMIT 10)",
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
}, { }, {
arguments: ['mySchema.myTable', {name: 'foo'}], arguments: [{schema: 'mySchema', tableName: 'myTable'}, {name: 'foo'}],
expectation: "DELETE FROM mySchema.myTable WHERE id IN (SELECT id FROM mySchema.myTable WHERE name='foo' LIMIT 1)", expectation: "DELETE FROM mySchema.myTable WHERE id IN (SELECT id FROM mySchema.myTable WHERE name='foo' LIMIT 1)",
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
}, { }, {
arguments: ['mySchema.myTable', {name: "foo';DROP TABLE mySchema.myTable;"}, {limit: 10}], arguments: [{schema: 'mySchema', tableName: 'myTable'}, {name: "foo';DROP TABLE mySchema.myTable;"}, {limit: 10}],
expectation: "DELETE FROM mySchema.myTable WHERE id IN (SELECT id FROM mySchema.myTable WHERE name='foo'';DROP TABLE mySchema.myTable;' LIMIT 10)", expectation: "DELETE FROM mySchema.myTable WHERE id IN (SELECT id FROM mySchema.myTable WHERE name='foo'';DROP TABLE mySchema.myTable;' LIMIT 10)",
context: {options: {quoteIdentifiers: false}} context: {options: {quoteIdentifiers: false}}
}, { }, {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!