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

Commit a317a366 by Rob Raux

adds test for postgres empty array cast

1 parent a9f8facf
Showing with 44 additions and 20 deletions
...@@ -333,7 +333,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -333,7 +333,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
describe('create', function() { describe('create', function() {
it("casts empty arrays correctly for postgresql", function(done) { it("casts empty arrays correctly for postgresql insert", function(done) {
if (dialect !== "postgres" && dialect !== "postgresql-native") { if (dialect !== "postgres" && dialect !== "postgresql-native") {
expect('').to.equal('') expect('').to.equal('')
return done() return done()
...@@ -352,6 +352,30 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -352,6 +352,30 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
}) })
it("casts empty array correct for postgres update", function(done) {
if (dialect !== "postgres" && dialect !== "postgresql-native") {
expect('').to.equal('')
return done()
}
var User = this.sequelize.define('UserWithArray', {
myvals: { type: Sequelize.ARRAY(Sequelize.INTEGER) },
mystr: { type: Sequelize.ARRAY(Sequelize.STRING) }
})
User.sync({force: true}).success(function() {
User.create({myvals: [1,2,3,4], mystr: ["One", "Two", "Three", "Four"]}).on('success', function(user){
user.myvals = []
user.mystr = []
user.save().on('sql', function(sql) {
expect(sql.indexOf('ARRAY[]::INTEGER[]')).to.be.above(-1)
expect(sql.indexOf('ARRAY[]::VARCHAR[]')).to.be.above(-1)
done()
})
})
})
})
it("doesn't allow duplicated records with unique:true", function(done) { it("doesn't allow duplicated records with unique:true", function(done) {
var User = this.sequelize.define('UserWithUniqueUsername', { var User = this.sequelize.define('UserWithUniqueUsername', {
...@@ -1809,17 +1833,17 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -1809,17 +1833,17 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
it('eager loads with non-id primary keys', function(done) { it('eager loads with non-id primary keys', function(done) {
var self = this var self = this
self.User = self.sequelize.define('UserPKeagerbelong', { self.User = self.sequelize.define('UserPKeagerbelong', {
username: { username: {
type: Sequelize.STRING, type: Sequelize.STRING,
primaryKey: true primaryKey: true
} }
}) })
self.Group = self.sequelize.define('GroupPKeagerbelong', { self.Group = self.sequelize.define('GroupPKeagerbelong', {
name: { name: {
type: Sequelize.STRING, type: Sequelize.STRING,
primaryKey: true primaryKey: true
} }
}) })
self.User.belongsTo(self.Group) self.User.belongsTo(self.Group)
...@@ -1878,17 +1902,17 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -1878,17 +1902,17 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
it('eager loads with non-id primary keys', function(done) { it('eager loads with non-id primary keys', function(done) {
var self = this var self = this
self.User = self.sequelize.define('UserPKeagerone', { self.User = self.sequelize.define('UserPKeagerone', {
username: { username: {
type: Sequelize.STRING, type: Sequelize.STRING,
primaryKey: true primaryKey: true
} }
}) })
self.Group = self.sequelize.define('GroupPKeagerone', { self.Group = self.sequelize.define('GroupPKeagerone', {
name: { name: {
type: Sequelize.STRING, type: Sequelize.STRING,
primaryKey: true primaryKey: true
} }
}) })
self.Group.hasOne(self.User) self.Group.hasOne(self.User)
...@@ -2000,17 +2024,17 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -2000,17 +2024,17 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
it('eager loads with non-id primary keys', function(done) { it('eager loads with non-id primary keys', function(done) {
var self = this var self = this
self.User = self.sequelize.define('UserPKeagerone', { self.User = self.sequelize.define('UserPKeagerone', {
username: { username: {
type: Sequelize.STRING, type: Sequelize.STRING,
primaryKey: true primaryKey: true
} }
}) })
self.Group = self.sequelize.define('GroupPKeagerone', { self.Group = self.sequelize.define('GroupPKeagerone', {
name: { name: {
type: Sequelize.STRING, type: Sequelize.STRING,
primaryKey: true primaryKey: true
} }
}) })
self.Group.hasMany(self.User) self.Group.hasMany(self.User)
self.User.hasMany(self.Group) self.User.hasMany(self.Group)
...@@ -2032,7 +2056,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -2032,7 +2056,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect(someUser.groupPKeagerones[0].name).to.equal('people') expect(someUser.groupPKeagerones[0].name).to.equal('people')
done() done()
}) })
}) })
}) })
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!