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

Commit dabdcbe5 by Sascha Depold

replace random math shit in tests with easy accessor in the config file

1 parent 78848c5b
......@@ -9,7 +9,7 @@ var initialize = function(options, callback) {
options.taskCount = options.taskCount || 1
options.userCount = options.userCount || 1
var num = parseInt(Math.random() * 9999999999999)
var num = config.rand()
, User = sequelize.define('User' + num, { name: Sequelize.STRING })
, Task = sequelize.define('Task' + num, { name: Sequelize.STRING })
, chainer = new Sequelize.Utils.QueryChainer
......
......@@ -5,32 +5,32 @@ var assert = require("assert")
module.exports = {
'it should correctly add the foreign id': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
Task.belongsTo(User)
assert.eql(Task.attributes['User'+num+'Id'], "INT")
},
'it should correctly add the foreign id with underscore': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING }, {underscored: true})
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }, {underscored: true})
Task.belongsTo(User)
assert.eql(Task.attributes['user'+num+'_id'], "INT")
},
'it should correctly add the foreign id if foreignKey is passed': function() {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING })
var User = sequelize.define('User' + config.rand(), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING })
Task.belongsTo(User, {foreignKey: 'person_id'})
assert.eql(Task.attributes['person_id'], "INT")
},
'it should define getter and setter': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
Task.belongsTo(User)
......@@ -39,8 +39,8 @@ module.exports = {
assert.isDefined(t['getUser'+num])
},
'it should define getter and setter according to passed as option': function() {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING })
var User = sequelize.define('User' + config.rand(), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING })
Task.belongsTo(User, {as: 'Person'})
......@@ -49,9 +49,9 @@ module.exports = {
assert.isDefined(t.getPerson)
},
'it should set the foreign id to null': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
Task.belongsTo(User)
......@@ -59,8 +59,8 @@ module.exports = {
assert.isNull(t['User'+num+'Id'])
},
'it should set and get the correct object': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING })
var User = sequelize.define('User' + config.rand(), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING })
Task.belongsTo(User, {as: 'User'})
......@@ -80,8 +80,8 @@ module.exports = {
})
},
'it should correctly delete associations': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING })
var User = sequelize.define('User' + config.rand(), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING })
Task.belongsTo(User, {as: 'User'})
......
......@@ -4,7 +4,7 @@ var assert = require("assert")
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false})
var initUsers = function(num, callback) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { name: Sequelize.STRING, bio: Sequelize.TEXT })
var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT })
, users = []
User.sync({force: true}).on('success', function() {
......@@ -24,7 +24,7 @@ module.exports = {
})
},
'build should fill the object with default values': function() {
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), {
var Task = sequelize.define('Task' + config.rand(), {
title: {type: Sequelize.STRING, defaultValue: 'a task!'},
foo: {type: Sequelize.INTEGER, defaultValue: 2},
bar: {type: Sequelize.DATE},
......
......@@ -4,12 +4,12 @@ var assert = require("assert")
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false})
var initUsers = function(num, callback) {
return sequelize.define('User' + parseInt(Math.random() * 99999999), { name: Sequelize.STRING, bio: Sequelize.TEXT })
return sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT })
}
module.exports = {
'do not allow duplicated records with unique:true': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), {
var User = sequelize.define('User' + config.rand(), {
username: {type: Sequelize.STRING, unique: true}
})
User.sync({force:true}).on('success', function() {
......@@ -22,7 +22,7 @@ module.exports = {
})
},
'it should raise an error if created object breaks definition constraints': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), {
var User = sequelize.define('User' + config.rand(), {
username: {type: Sequelize.STRING, unique: true},
smth: {type: Sequelize.STRING, allowNull: false}
})
......
......@@ -5,7 +5,7 @@ var assert = require("assert")
module.exports = {
'destroy should delete a saved record from the database': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { name: Sequelize.STRING, bio: Sequelize.TEXT })
var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT })
User.sync({force: true}).on('success', function() {
User.create({name: 'hallo', bio: 'welt'}).on('success', function(u) {
User.all.on('success', function(users) {
......@@ -21,7 +21,7 @@ module.exports = {
})
},
'destroy should mark the record as deleted if paranoid is activated': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { name: Sequelize.STRING, bio: Sequelize.TEXT }, {paranoid:true})
var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT }, {paranoid:true})
User.sync({force: true}).on('success', function() {
User.create({name: 'asd', bio: 'asd'}).on('success', function(u) {
assert.isNull(u.deletedAt)
......
......@@ -5,7 +5,7 @@ var assert = require("assert")
module.exports = {
'it should correctly determine equal objects': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { name: Sequelize.STRING, bio: Sequelize.TEXT })
var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT })
User.sync({force: true}).on('success', function() {
User.create({name: 'hallo', bio: 'welt'}).on('success', function(u) {
......@@ -15,7 +15,7 @@ module.exports = {
})
},
'it should correctly work with different primary keys': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), {
var User = sequelize.define('User' + config.rand(), {
foo: {type: Sequelize.STRING, primaryKey: true},
bar: {type: Sequelize.STRING, primaryKey: true},
name: Sequelize.STRING, bio: Sequelize.TEXT
......@@ -29,7 +29,7 @@ module.exports = {
})
},
'equalsOneOf should work': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), {
var User = sequelize.define('User' + config.rand(), {
foo: {type: Sequelize.STRING, primaryKey: true},
bar: {type: Sequelize.STRING, primaryKey: true},
name: Sequelize.STRING, bio: Sequelize.TEXT
......
......@@ -4,7 +4,7 @@ var assert = require("assert")
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false})
var initUsers = function(num, callback) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { name: Sequelize.STRING, bio: Sequelize.TEXT })
var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT })
var createUser = function() {
User.create({name: 'user' + num, bio: 'foobar'}).on('success', function(user){
if(--num) createUser()
......@@ -61,7 +61,7 @@ module.exports = {
})
},
'find should find records by primaryKeys': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 999999999), {
var User = sequelize.define('User' + config.rand(), {
identifier: {type: Sequelize.STRING, primaryKey: true},
name: Sequelize.STRING
})
......
......@@ -5,7 +5,7 @@ var assert = require("assert")
module.exports = {
'it should correctly add the foreign id - monodirectional': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
......@@ -13,7 +13,7 @@ module.exports = {
assert.eql(Task.attributes['User'+num+'Id'], "INT")
},
'it should correctly add the foreign ids - bidirectional': function(exit) {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
......@@ -32,7 +32,7 @@ module.exports = {
})
},
'it should correctly add the foreign id with underscore - monodirectional': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING}, {underscored: true})
......@@ -40,7 +40,7 @@ module.exports = {
assert.isDefined(User.attributes['task'+ num +'_id'])
},
'it should correctly add the foreign id with underscore - bidirectional': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING }, {underscored: true})
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
......@@ -58,7 +58,7 @@ module.exports = {
})
},
'it should correctly add the foreign id when defining the foreignkey as option - monodirectional': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING }, {underscored: true})
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
......@@ -66,7 +66,7 @@ module.exports = {
assert.eql(Task.attributes.person_id, "INT")
},
'it should correctly add the foreign id when defining the foreignkey as option - bidirectional': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING }, {underscored: true})
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
......@@ -81,7 +81,7 @@ module.exports = {
})
},
'it should define getter and setter - monodirectional': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
......@@ -92,7 +92,7 @@ module.exports = {
assert.isDefined(u['getTask'+num+"s"])
},
'it should define getter and setter - bidirectional': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
......@@ -108,7 +108,7 @@ module.exports = {
assert.isDefined(t['getUser'+num+'s'])
},
'it should define getter and setter according to as option - monodirectional': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
......@@ -119,7 +119,7 @@ module.exports = {
assert.isDefined(u.getTasks)
},
'it should define getter and setter according to as option - bidirectional': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
......@@ -135,8 +135,8 @@ module.exports = {
assert.isDefined(t.getUsers)
},
'it should set and get the correct objects - monodirectional': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING })
var User = sequelize.define('User' + config.rand(), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING })
User.hasMany(Task, {as: 'Tasks'})
......@@ -162,8 +162,8 @@ module.exports = {
})
},
'it should set and get the correct objects - bidirectional': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING })
var User = sequelize.define('User' + config.rand(), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING })
User.hasMany(Task, {as: 'Tasks'})
Task.hasMany(User, {as: 'Users'})
......@@ -198,7 +198,7 @@ module.exports = {
})
},
'it should correctly build the connector model names': function(exit){
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
, Person = sequelize.define('Person' + num, { name: Sequelize.STRING })
Person.hasMany(Person, {as: 'Children'})
......@@ -217,7 +217,7 @@ module.exports = {
})
},
'it should correctly get and set the connected models': function(exit) {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
, Person = sequelize.define('Person' + num, { name: Sequelize.STRING })
Person.hasMany(Person, {as: 'Children'})
......
......@@ -5,23 +5,23 @@ var assert = require("assert")
module.exports = {
'it should correctly add the foreign id': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
User.hasOne(Task)
assert.eql(Task.attributes['User'+num+'Id'], "INT")
},
'it should correctly add the foreign id with underscore': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING }, {underscored: true})
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
User.hasOne(Task)
assert.eql(Task.attributes['user'+num+'_id'], "INT")
},
'it should correctly add the foreign id when defining the foreignkey as option': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING }, {underscored: true})
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
......@@ -29,7 +29,7 @@ module.exports = {
assert.eql(Task.attributes.person_id, "INT")
},
'it should define getter and setter': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
......@@ -40,7 +40,7 @@ module.exports = {
assert.isDefined(u['getTask'+num])
},
'it should define getter and setter according to as option': function() {
var num = parseInt(Math.random() * 99999999)
var num = config.rand()
var User = sequelize.define('User' + num, { username: Sequelize.STRING })
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING })
......@@ -51,8 +51,8 @@ module.exports = {
assert.isDefined(u.getTask)
},
'it should set and get the correct objects': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING })
var User = sequelize.define('User' + config.rand(), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING })
User.hasOne(Task, {as: 'Task'})
......@@ -72,8 +72,8 @@ module.exports = {
})
},
'it should correctly unset the obsolete objects': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + parseInt(Math.random() * 99999999), { title: Sequelize.STRING })
var User = sequelize.define('User' + config.rand(), { username: Sequelize.STRING })
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING })
User.hasOne(Task, {as: 'Task'})
......@@ -98,5 +98,9 @@ module.exports = {
})
})
})
},
'it should correctly associate with itself': function(exit) {
var Person = sequelize.define('Person' + config.rand(), { name: Sequelize.STRING })
exit(function(){})
}
}
\ No newline at end of file
......@@ -4,7 +4,7 @@ var assert = require("assert")
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false})
var initUsers = function(num, callback) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { name: Sequelize.STRING, bio: Sequelize.TEXT })
var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT })
, users = []
User.sync({force: true}).on('success', function() {
......
......@@ -5,7 +5,7 @@ var assert = require("assert")
module.exports = {
'save should add a record to the database': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { name: Sequelize.STRING, bio: Sequelize.TEXT })
var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT })
User.sync({force: true}).on('success', function() {
var u = User.build({name: 'hallo', bio: 'welt'})
......@@ -22,7 +22,7 @@ module.exports = {
})
},
'save should update the timestamp updated_at': function(exit) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { name: Sequelize.STRING, bio: Sequelize.TEXT })
var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT })
User.sync({force: true}).on('success', function() {
var now = Date.now()
// timeout is needed, in order to check the update of the timestamp
......
......@@ -2,7 +2,7 @@ var assert = require("assert")
, config = require("./../config")
, Sequelize = require("./../../index")
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false})
, User = sequelize.define('User' + parseInt(Math.random() * 9999999999999), { name: Sequelize.STRING, bio: Sequelize.TEXT })
, User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT })
module.exports = {
'it should update the attributes': function(exit) {
......@@ -28,7 +28,7 @@ module.exports = {
})
},
'it should not set primary keys or timestamps': function(exit) {
User = sequelize.define('User' + parseInt(Math.random() * 9999999999999), {
User = sequelize.define('User' + config.rand(), {
name: Sequelize.STRING, bio: Sequelize.TEXT, identifier: {type: Sequelize.STRING, primaryKey: true}
})
......
......@@ -4,7 +4,7 @@ var assert = require("assert")
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false})
var initUsers = function(num, callback) {
var User = sequelize.define('User' + parseInt(Math.random() * 99999999), { name: Sequelize.STRING, bio: Sequelize.TEXT }, {timestamps:false})
var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT }, {timestamps:false})
, users = []
User.sync({force: true}).on('success', function() {
......
var assert = require("assert")
, config = require("./../config")
, Sequelize = require("./../../index")
, sequelize = new Sequelize('database', 'username', 'password')
......@@ -10,49 +11,49 @@ module.exports = {
assert.eql(s.modelManager.all.length, 1)
},
'it should handle extended attributes correctly - unique': function() {
var User = sequelize.define('User' + parseInt(Math.random() * 999999999), {
var User = sequelize.define('User' + config.rand(), {
username: {type: Sequelize.STRING, unique: true}
}, { timestamps: false })
assert.eql(User.attributes, {username:"VARCHAR(255) UNIQUE",id:"INT NOT NULL auto_increment PRIMARY KEY"})
},
'it should handle extended attributes correctly - default': function() {
var User = sequelize.define('User' + parseInt(Math.random() * 999999999), {
var User = sequelize.define('User' + config.rand(), {
username: {type: Sequelize.STRING, defaultValue: 'foo'}
}, { timestamps: false })
assert.eql(User.attributes, {username:"VARCHAR(255) DEFAULT 'foo'",id:"INT NOT NULL auto_increment PRIMARY KEY"})
},
'it should handle extended attributes correctly - null': function() {
var User = sequelize.define('User' + parseInt(Math.random() * 999999999), {
var User = sequelize.define('User' + config.rand(), {
username: {type: Sequelize.STRING, allowNull: false}
}, { timestamps: false })
assert.eql(User.attributes, {username:"VARCHAR(255) NOT NULL",id:"INT NOT NULL auto_increment PRIMARY KEY"})
},
'it should handle extended attributes correctly - primary key': function() {
var User = sequelize.define('User' + parseInt(Math.random() * 999999999), {
var User = sequelize.define('User' + config.rand(), {
username: {type: Sequelize.STRING, primaryKey: true}
}, { timestamps: false })
assert.eql(User.attributes, {username:"VARCHAR(255) PRIMARY KEY"})
},
'primaryKeys should be correctly determined': function() {
var User = sequelize.define('User' + parseInt(Math.random() * 999999999), {
var User = sequelize.define('User' + config.rand(), {
foo: {type: Sequelize.STRING, primaryKey: true},
bar: Sequelize.STRING
})
assert.eql(User.primaryKeys, {"foo":"VARCHAR(255) PRIMARY KEY"})
},
'it should add updatedAt and createdAt if timestamps is undefined or true': function() {
var User1 = sequelize.define('User' + parseInt(Math.random() * 999999999), {})
var User2 = sequelize.define('User' + parseInt(Math.random() * 999999999), {}, { timestamps: true })
var User1 = sequelize.define('User' + config.rand(), {})
var User2 = sequelize.define('User' + config.rand(), {}, { timestamps: true })
assert.eql(User1.attributes, {id:"INT NOT NULL auto_increment PRIMARY KEY", updatedAt:"DATETIME NOT NULL", createdAt:"DATETIME NOT NULL"})
assert.eql(User2.attributes, {id:"INT NOT NULL auto_increment PRIMARY KEY", updatedAt:"DATETIME NOT NULL", createdAt:"DATETIME NOT NULL"})
},
'it should add deletedAt if paranoid is true': function() {
var User = sequelize.define('User' + parseInt(Math.random() * 999999999), {}, { paranoid: true })
var User = sequelize.define('User' + config.rand(), {}, { paranoid: true })
assert.eql(User.attributes, {id:"INT NOT NULL auto_increment PRIMARY KEY", deletedAt:"DATETIME", updatedAt:"DATETIME NOT NULL", createdAt:"DATETIME NOT NULL"})
},
'timestamp columns should be underscored if underscored is passed': function() {
var User = sequelize.define('User' + parseInt(Math.random() * 999999999), {}, { paranoid: true, underscored: true })
var User = sequelize.define('User' + config.rand(), {}, { paranoid: true, underscored: true })
assert.eql(User.attributes, {id:"INT NOT NULL auto_increment PRIMARY KEY", deleted_at:"DATETIME", updated_at:"DATETIME NOT NULL", created_at:"DATETIME NOT NULL"})
},
'tablenames should be as passed if they are frozen': function() {
......
......@@ -5,10 +5,10 @@ var assert = require("assert")
module.exports = {
'it should sync all models - so instances can be created and saved to the database without failures': function(exit) {
var Project = sequelize.define('project' + parseInt(Math.random() * 9999999999999999999), {
var Project = sequelize.define('project' + config.rand(), {
title: Sequelize.STRING
})
var Task = sequelize.define('task' + parseInt(Math.random() * 99999999999999999), {
var Task = sequelize.define('task' + config.rand(), {
title: Sequelize.STRING
})
......
module.exports = {
username: 'root',
password: null,
database: 'sequelize_test',
host: '127.0.0.1'
username: 'root'
, password: null
, database: 'sequelize_test'
, host: '127.0.0.1'
, rand: function() {
return parseInt(Math.random() * 99999999999999)
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!