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

Commit facebaf4 by Sascha Depold

Merge branch 'mocha' of github.com:sequelize/sequelize into mocha

2 parents daf4c69a dad4c5c6
test:
@mocha -c $(find ./test -name "*.test.js")
.PHONY: test
module.exports = {
up: function(migration, DataTypes, done) {
migration
.createTable('Person', {
name: DataTypes.STRING,
isBetaMember: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false
}
})
.complete(done)
},
down: function(migration, DataTypes, done) {
migration.dropTable('Person').complete(done)
}
}
module.exports = {
up: function(migration, DataTypes, done) { done() },
down: function(migration, DataTypes, done) { done() }
}
module.exports = {
up: function(migration, DataTypes, done) {
migration.renameTable('Person', 'User').complete(done)
},
down: function(migration, DataTypes, done) {
migration.renameTable('User', 'Person').complete(done)
}
}
module.exports = {
up: function(migration, DataTypes, done) {
migration
.addColumn('User', 'isAdmin', { type: DataTypes.BOOLEAN, defaultValue: false, allowNull: false })
.complete(function(err) {
if (err) {
done(err)
} else {
migration
.addColumn('User', 'signature', DataTypes.TEXT)
.complete(function(err) {
if (err) {
done(err)
} else {
migration.addColumn('User', 'shopId', { type: DataTypes.INTEGER, allowNull: true }).complete(done)
}
})
}
})
},
down: function(migration, DataTypes, done) {
migration.removeColumn('User', 'signature').complete(function(err) {
if (err) {
done(err)
} else {
migration.removeColumn('User', 'shopId').complete(function(err) {
if (err) {
done(err)
} else {
migration.removeColumn('User', 'isAdmin').complete(done)
}
})
}
})
}
}
module.exports = {
up: function(migration, DataTypes, done) {
migration.removeColumn('User', 'shopId').complete(done)
},
down: function(migration, DataTypes, done) {
migration.addColumn('User', 'shopId', { type: DataTypes.INTEGER, allowNull: true }).complete(done)
}
}
module.exports = {
up: function(migration, DataTypes, done) {
migration.changeColumn('User', 'signature', {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'Signature'
}).complete(done)
},
down: function(migration, DataTypes, done) { done() }
}
module.exports = {
up: function(migration, DataTypes, done) {
migration.renameColumn('User', 'signature', 'sig').complete(done)
},
down: function(migration, DataTypes, done) {
migration.renameColumn('User', 'sig', 'signature').complete(done)
}
}
module.exports = function(sequelize, DataTypes) {
return sequelize.define('Project' + parseInt(Math.random() * 9999999999999999), {
name: DataTypes.STRING
})
}
\ No newline at end of file
......@@ -2,12 +2,13 @@ var chai = require('chai')
, expect = chai.expect
, semver = require("semver")
, config = require(__dirname + "/config/config")
, Utils = require(__dirname + '/../lib/utils')
, Support = require(__dirname + '/support')
, dialect = Support.getTestDialect()
, Sequelize = require(__dirname + '/../index')
, noDomains = semver.lt(process.version, '0.8.0')
chai.Assertion.includeStack = true
describe(Support.getTestDialectTeaser("Configuration"), function() {
describe('Connections problems should fail with a nice message', function() {
it('when we don\'t have the correct server details', function(done) {
......
var chai = require('chai')
, expect = chai.expect
, Sequelize = require(__dirname + '/../index')
, Utils = require(__dirname + '/../lib/utils')
, Support = require(__dirname + '/support')
, dialect = Support.getTestDialect()
describe(Support.getTestDialectTeaser("DaoValidator"), function() {
var sequelize = Support.createSequelizeInstance({ dialect: dialect })
chai.Assertion.includeStack = true
describe(Support.getTestDialectTeaser("DaoValidator"), function() {
describe('validations', function() {
before(function(done) {
this.sequelize = Object.create(sequelize)
Support.clearDatabase(this.sequelize, done)
})
var checks = {
is: {
spec: { args: ["[a-z]",'i'] },
......
var chai = require('chai')
, expect = chai.expect
, Sequelize = require(__dirname + '/../index')
, Support = require(__dirname + '/support')
chai.Assertion.includeStack = true
describe(Support.getTestDialectTeaser('DataTypes'), function() {
it('should return DECIMAL for the default decimal type', function(done) {
expect(Sequelize.DECIMAL.toString()).to.equal('DECIMAL')
done()
})
it('should return DECIMAL(10,2) for the default decimal type with arguments', function(done) {
expect(Sequelize.DECIMAL(10, 2)).to.equal('DECIMAL(10,2)')
done()
})
var tests = [
[Sequelize.STRING, 'STRING', 'VARCHAR(255)'],
[Sequelize.STRING(1234), 'STRING(1234)', 'VARCHAR(1234)'],
[Sequelize.STRING(1234).BINARY, 'STRING(1234).BINARY', 'VARCHAR(1234) BINARY'],
[Sequelize.STRING.BINARY, 'STRING.BINARY', 'VARCHAR(255) BINARY'],
[Sequelize.TEXT, 'TEXT', 'TEXT'],
[Sequelize.DATE, 'DATE', 'DATETIME'],
[Sequelize.NOW, 'NOW', 'NOW'],
[Sequelize.BOOLEAN, 'BOOLEAN', 'TINYINT(1)'],
[Sequelize.INTEGER, 'INTEGER', 'INTEGER'],
[Sequelize.INTEGER.UNSIGNED, 'INTEGER.UNSIGNED', 'INTEGER UNSIGNED'],
[Sequelize.INTEGER(11), 'INTEGER(11)','INTEGER(11)'],
[Sequelize.INTEGER(11).UNSIGNED, 'INTEGER(11).UNSIGNED', 'INTEGER(11) UNSIGNED'],
[Sequelize.INTEGER(11).UNSIGNED.ZEROFILL,'INTEGER(11).UNSIGNED.ZEROFILL','INTEGER(11) UNSIGNED ZEROFILL'],
[Sequelize.INTEGER(11).ZEROFILL,'INTEGER(11).ZEROFILL', 'INTEGER(11) ZEROFILL'],
[Sequelize.INTEGER(11).ZEROFILL.UNSIGNED,'INTEGER(11).ZEROFILL.UNSIGNED', 'INTEGER(11) UNSIGNED ZEROFILL'],
[Sequelize.BIGINT, 'BIGINT', 'BIGINT'],
[Sequelize.BIGINT.UNSIGNED, 'BIGINT.UNSIGNED', 'BIGINT UNSIGNED'],
[Sequelize.BIGINT(11), 'BIGINT(11)','BIGINT(11)'],
[Sequelize.BIGINT(11).UNSIGNED, 'BIGINT(11).UNSIGNED', 'BIGINT(11) UNSIGNED'],
[Sequelize.BIGINT(11).UNSIGNED.ZEROFILL, 'BIGINT(11).UNSIGNED.ZEROFILL','BIGINT(11) UNSIGNED ZEROFILL'],
[Sequelize.BIGINT(11).ZEROFILL, 'BIGINT(11).ZEROFILL', 'BIGINT(11) ZEROFILL'],
[Sequelize.BIGINT(11).ZEROFILL.UNSIGNED, 'BIGINT(11).ZEROFILL.UNSIGNED', 'BIGINT(11) UNSIGNED ZEROFILL'],
[Sequelize.FLOAT, 'FLOAT', 'FLOAT'],
[Sequelize.FLOAT.UNSIGNED, 'FLOAT.UNSIGNED', 'FLOAT UNSIGNED'],
[Sequelize.FLOAT(11), 'FLOAT(11)','FLOAT(11)'],
[Sequelize.FLOAT(11).UNSIGNED, 'FLOAT(11).UNSIGNED', 'FLOAT(11) UNSIGNED'],
[Sequelize.FLOAT(11).UNSIGNED.ZEROFILL,'FLOAT(11).UNSIGNED.ZEROFILL','FLOAT(11) UNSIGNED ZEROFILL'],
[Sequelize.FLOAT(11).ZEROFILL,'FLOAT(11).ZEROFILL', 'FLOAT(11) ZEROFILL'],
[Sequelize.FLOAT(11).ZEROFILL.UNSIGNED,'FLOAT(11).ZEROFILL.UNSIGNED', 'FLOAT(11) UNSIGNED ZEROFILL'],
[Sequelize.FLOAT(11, 12), 'FLOAT(11,12)','FLOAT(11,12)'],
[Sequelize.FLOAT(11, 12).UNSIGNED, 'FLOAT(11,12).UNSIGNED', 'FLOAT(11,12) UNSIGNED'],
[Sequelize.FLOAT(11, 12).UNSIGNED.ZEROFILL,'FLOAT(11,12).UNSIGNED.ZEROFILL','FLOAT(11,12) UNSIGNED ZEROFILL'],
[Sequelize.FLOAT(11, 12).ZEROFILL,'FLOAT(11,12).ZEROFILL', 'FLOAT(11,12) ZEROFILL'],
[Sequelize.FLOAT(11, 12).ZEROFILL.UNSIGNED,'FLOAT(11,12).ZEROFILL.UNSIGNED', 'FLOAT(11,12) UNSIGNED ZEROFILL']
]
tests.forEach(function(test) {
it('transforms "' + test[1] + '" to "' + test[2] + '"', function(done) {
expect(test[0].toString()).to.equal(test[2])
done()
})
})
})
var chai = require('chai')
, expect = chai.expect
, Sequelize = require(__dirname + '/../index')
, Support = require(__dirname + '/support')
chai.Assertion.includeStack = true
describe(Support.getTestDialectTeaser("Language Util"), function() {
after(function(done) {
this.sequelize.options.language = 'en'
done()
})
describe("Plural", function(){
before(function(done) {
this.sequelize.options.language = 'es'
done()
})
it("should rename tables to their plural form...", function(done){
var self = this
, table = self.sequelize.define('arbol', {name: Sequelize.STRING})
, table2 = self.sequelize.define('androide', {name: Sequelize.STRING})
expect(table.tableName).to.equal('arboles')
expect(table2.tableName).to.equal('androides')
done()
})
it("should be able to pluralize/singularize associations...", function(done){
var self = this
, table = self.sequelize.define('arbol', {name: Sequelize.STRING})
, table2 = self.sequelize.define('androide', {name: Sequelize.STRING})
, table3 = self.sequelize.define('hombre', {name: Sequelize.STRING})
table.hasOne(table2)
table2.belongsTo(table)
table3.hasMany(table2)
expect(table.associations.androides.identifier).to.equal('arbolId')
expect(table2.associations.arboles).to.exist
expect(table3.associations.androideshombres).to.exist
done()
})
})
})
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/support')
, DataTypes = require(__dirname + "/../lib/data-types")
, dialect = Support.getTestDialect()
, QueryChainer = require("../lib/query-chainer")
, CustomEventEmitter = require("../lib/emitters/custom-event-emitter")
, _ = require('lodash')
chai.Assertion.includeStack = true
describe(Support.getTestDialectTeaser("QueryChainer"), function () {
beforeEach(function(done) {
this.queryChainer = new QueryChainer()
done()
})
describe('add', function() {
it('adds a new serial item if method is passed', function(done) {
expect(this.queryChainer.serials.length).to.equal(0)
this.queryChainer.add({}, 'foo')
expect(this.queryChainer.serials.length).to.equal(1)
done()
})
it('adds a new emitter if no method is passed', function(done) {
expect(this.queryChainer.emitters.length).to.equal(0)
this.queryChainer.add(new CustomEventEmitter())
expect(this.queryChainer.emitters.length).to.equal(1)
done()
})
})
describe('run', function() {
it('finishes when all emitters are finished', function(done) {
var emitter1 = new CustomEventEmitter(function(e) { e.emit('success') })
var emitter2 = new CustomEventEmitter(function(e) { e.emit('success') })
this.queryChainer.add(emitter1)
this.queryChainer.add(emitter2)
this.queryChainer.run().success(function() {
expect(true).to.be.true
done()
}).error(function(err) {
console.log(err)
})
emitter1.run()
setTimeout(function() { emitter2.run() }, 100)
})
it("returns the result of the passed emitters", function(done) {
var emitter1 = new CustomEventEmitter(function(e) { e.emit('success', 1) })
this.queryChainer.add(emitter1)
this.queryChainer.run().success(function(results) {
expect(results).to.exist
expect(results.length).to.equal(1)
expect(results[0]).to.equal(1)
done()
})
emitter1.run()
})
it("returns the result of the passed emitters in the order of the occurrence of adding the emitters", function(done) {
var emitter1 = new CustomEventEmitter(function(e) { e.emit('success', 1) })
, emitter2 = new CustomEventEmitter(function(e) { e.emit('success', 2) })
, emitter3 = new CustomEventEmitter(function(e) { e.emit('success', 3) })
this.queryChainer.add(emitter1)
this.queryChainer.add(emitter2)
this.queryChainer.add(emitter3)
this.queryChainer.run().success(function(results) {
expect(results.length).to.equal(3)
expect(results).to.include.members([1,2,3])
done()
})
emitter2.run()
emitter1.run()
emitter3.run()
})
it("returns the result as an array and each result as part of the callback signature", function(done) {
var emitter1 = new CustomEventEmitter(function(e) { e.emit('success', 1) })
, emitter2 = new CustomEventEmitter(function(e) { e.emit('success', 2) })
this.queryChainer.add(emitter1)
this.queryChainer.add(emitter2)
this.queryChainer.run().success(function(results, result1, result2) {
expect(result1).to.exist
expect(result2).to.exist
expect(result1).to.equal(1)
expect(result2).to.equal(2)
done()
})
emitter2.run()
emitter1.run()
})
})
describe('runSerially', function() {
it('finishes when all emitters are finished', function(done) {
var emitter1 = new CustomEventEmitter(function(e) { e.emit('success') })
var emitter2 = new CustomEventEmitter(function(e) { e.emit('success') })
this.queryChainer.add(emitter1, 'run')
this.queryChainer.add(emitter2, 'run')
this.queryChainer.runSerially().success(function() {
expect(true).to.be.true
done()
})
})
it("returns the result of the passed emitters", function(done) {
var emitter1 = new CustomEventEmitter(function(e) { e.emit('success', 1) })
this.queryChainer.add(emitter1, 'run')
this.queryChainer.runSerially().success(function(results) {
expect(results).to.exist
expect(results.length).to.equal(1)
expect(results[0]).to.equal(1)
done()
})
})
it("returns the result of the passed emitters in the order of the occurrence of adding the emitters", function(done) {
var emitter1 = new CustomEventEmitter(function(e) { e.emit('success', 1) })
, emitter2 = new CustomEventEmitter(function(e) { setTimeout(function() { e.emit('success', 2) }, 100) })
, emitter3 = new CustomEventEmitter(function(e) { e.emit('success', 3) })
this.queryChainer.add(emitter1, 'run')
this.queryChainer.add(emitter2, 'run')
this.queryChainer.add(emitter3, 'run')
this.queryChainer.runSerially().success(function(results) {
expect(results.length).to.equal(3)
expect(results).to.contain.members([1,2,3])
done()
})
})
it("returns the result as an array and each result as part of the callback signature", function(done) {
var emitter1 = new CustomEventEmitter(function(e) { e.emit('success', 1) })
, emitter2 = new CustomEventEmitter(function(e) { e.emit('success', 2) })
this.queryChainer.add(emitter1, 'run')
this.queryChainer.add(emitter2, 'run')
this.queryChainer.runSerially().success(function(results, result1, result2) {
expect(result1).to.exist
expect(result2).to.exist
expect(result1).to.equal(1)
expect(result2).to.equal(2)
done()
})
})
})
})
/* jshint multistr: true */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/support')
, DataTypes = require(__dirname + "/../lib/data-types")
, dialect = Support.getTestDialect()
, _ = require('lodash')
chai.Assertion.includeStack = true
describe(Support.getTestDialectTeaser("QueryGenerators"), function () {
before(function(done) {
this.interface = this.sequelize.getQueryInterface()
done()
})
describe("comments", function() {
it("should create a comment for a column", function(done) {
var self = this
, User = this.sequelize.define('User', {
username: {type: DataTypes.STRING, comment: 'Some lovely info for my DBA'}
})
User.sync({ force: true }).success(function(){
var sql = ''
if (dialect === "mysql") {
sql = 'SELECT COLUMN_COMMENT as cmt FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = \'' + self.sequelize.config.database + '\' AND TABLE_NAME = \'Users\' AND COLUMN_NAME = \'username\'';
}
else if (dialect === "postgres" || dialect === "postgres-native") {
sql = 'SELECT com.description as cmt FROM pg_attribute a JOIN pg_class pgc ON pgc.oid = a.attrelid \
LEFT JOIN pg_index i ON (pgc.oid = i.indrelid AND i.indkey[0] = a.attnum) \
LEFT JOIN pg_description com on (pgc.oid = com.objoid AND a.attnum = com.objsubid) \
WHERE a.attnum > 0 AND pgc.oid = a.attrelid AND pg_table_is_visible(pgc.oid) \
AND NOT a.attisdropped AND pgc.relname = \'Users\' AND a.attname = \'username\'';
}
else if (dialect === "sqlite") {
// sqlite doesn't support comments except for explicit comments in the file
expect(true).to.be.true
return done()
} else {
console.log('FIXME: This dialect is not supported :(');
expect(true).to.be.true
return done()
}
self.sequelize.query(sql, null, {raw: true}).success(function(result) {
expect(result[0].cmt).to.equal('Some lovely info for my DBA');
done()
})
})
})
})
})
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/support')
, DataTypes = require(__dirname + "/../lib/data-types")
, dialect = Support.getTestDialect()
, _ = require('lodash')
chai.Assertion.includeStack = true
describe(Support.getTestDialectTeaser("QueryInterface"), function () {
before(function(done) {
this.interface = this.sequelize.getQueryInterface()
done()
})
describe('dropAllTables', function() {
it("should drop all tables", function(done) {
var self = this
this.interface.dropAllTables().complete(function(err) {
expect(err).to.be.null
self.interface.showAllTables().complete(function(err, tableNames) {
expect(err).to.be.null
expect(tableNames.length).to.equal(0)
self.interface.createTable('table', { name: DataTypes.STRING }).complete(function(err) {
expect(err).to.be.null
self.interface.showAllTables().complete(function(err, tableNames) {
expect(err).to.be.null
expect(tableNames.length).to.equal(1)
self.interface.dropAllTables().complete(function(err) {
expect(err).to.be.null
self.interface.showAllTables().complete(function(err, tableNames) {
expect(err).to.be.null
expect(tableNames.length).to.equal(0)
done()
})
})
})
})
})
})
})
})
describe('indexes', function() {
beforeEach(function(done) {
this.interface.createTable('User', {
username: DataTypes.STRING,
isAdmin: DataTypes.BOOLEAN
}).success(done)
})
it('adds, reads and removes an index to the table', function(done) {
var self = this
this.interface.addIndex('User', ['username', 'isAdmin']).complete(function(err) {
expect(err).to.be.null
self.interface.showIndex('User').complete(function(err, indexes) {
expect(err).to.be.null
var indexColumns = _.uniq(indexes.map(function(index) { return index.name }))
expect(indexColumns).to.include('user_username_is_admin')
self.interface.removeIndex('User', ['username', 'isAdmin']).complete(function(err) {
expect(err).to.be.null
self.interface.showIndex('User').complete(function(err, indexes) {
expect(err).to.be.null
indexColumns = _.uniq(indexes.map(function(index) { return index.name }))
expect(indexColumns).to.be.empty
done()
})
})
})
})
})
})
describe('describeTable', function() {
it('reads the metadata of the table', function(done) {
var self = this
var Users = self.sequelize.define('User', {
username: DataTypes.STRING,
isAdmin: DataTypes.BOOLEAN,
enumVals: DataTypes.ENUM('hello', 'world')
}, { freezeTableName: true })
Users.sync({ force: true }).success(function() {
self.interface.describeTable('User').complete(function(err, metadata) {
expect(err).to.be.null
var username = metadata.username
var isAdmin = metadata.isAdmin
var enumVals = metadata.enumVals
expect(username.type).to.equal(dialect === 'postgres' ? 'CHARACTER VARYING' : 'VARCHAR(255)')
expect(username.allowNull).to.be.true
expect(username.defaultValue).to.be.null
expect(isAdmin.type).to.equal(dialect === 'postgres' ? 'BOOLEAN' : 'TINYINT(1)')
expect(isAdmin.allowNull).to.be.true
expect(isAdmin.defaultValue).to.be.null
if (dialect === "postgres" || dialect === "postgres-native") {
expect(enumVals.special).to.be.instanceof(Array)
expect(enumVals.special.length).to.equal(2);
}
done()
})
})
})
})
})
var Support = require(__dirname + '/support')
, dialect = Support.getTestDialect()
before(function(done) {
var sequelize = Support.createSequelizeInstance({ dialect: dialect })
this.sequelize = sequelize
done()
})
beforeEach(function(done) {
Support.clearDatabase(this.sequelize, done)
})
......@@ -3,9 +3,11 @@ var chai = require('chai')
, Utils = require(__dirname + '/../lib/utils')
, Support = require(__dirname + '/support')
chai.Assertion.includeStack = true
describe(Support.getTestDialectTeaser("Utils"), function() {
describe('removeCommentsFromFunctionString', function() {
it("removes line comments at the start of a line", function() {
it("removes line comments at the start of a line", function(done) {
var functionWithLineComments = function() {
// noot noot
}
......@@ -14,9 +16,10 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
, result = Utils.removeCommentsFromFunctionString(string)
expect(result).not.to.match(/.*noot.*/)
done()
})
it("removes lines comments in the middle of a line", function() {
it("removes lines comments in the middle of a line", function(done) {
var functionWithLineComments = function() {
alert(1) // noot noot
}
......@@ -25,9 +28,10 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
, result = Utils.removeCommentsFromFunctionString(string)
expect(result).not.to.match(/.*noot.*/)
done()
})
it("removes range comments", function() {
it("removes range comments", function(done) {
var s = function() {
alert(1) /*
noot noot
......@@ -42,67 +46,80 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
expect(result).not.to.match(/.*noot.*/)
expect(result).not.to.match(/.*foo.*/)
expect(result).to.match(/.*alert\(2\).*/)
done()
})
})
describe('argsArePrimaryKeys', function() {
it("doesn't detect primary keys if primareyKeys and values have different lengths", function() {
it("doesn't detect primary keys if primareyKeys and values have different lengths", function(done) {
expect(Utils.argsArePrimaryKeys([1,2,3], [1])).to.be.false
done()
})
it("doesn't detect primary keys if primary keys are hashes or arrays", function() {
it("doesn't detect primary keys if primary keys are hashes or arrays", function(done) {
expect(Utils.argsArePrimaryKeys([[]], [1])).to.be.false
done()
})
it('detects primary keys if length is correct and data types are matching', function() {
it('detects primary keys if length is correct and data types are matching', function(done) {
expect(Utils.argsArePrimaryKeys([1,2,3], ["INTEGER", "INTEGER", "INTEGER"])).to.be.true
done()
})
it("detects primary keys if primary keys are dates and lengths are matching", function() {
it("detects primary keys if primary keys are dates and lengths are matching", function(done) {
expect(Utils.argsArePrimaryKeys([new Date()], ['foo'])).to.be.true
done()
})
})
describe('underscore', function() {
describe('underscoredIf', function() {
it('is defined', function() {
it('is defined', function(done) {
expect(Utils._.underscoredIf).to.be.ok
done()
})
it('underscores if second param is true', function() {
it('underscores if second param is true', function(done) {
expect(Utils._.underscoredIf('fooBar', true)).to.equal('foo_bar')
done()
})
it("doesn't underscore if second param is false", function() {
it("doesn't underscore if second param is false", function(done) {
expect(Utils._.underscoredIf('fooBar', false)).to.equal('fooBar')
done()
})
})
describe('camelizeIf', function() {
it('is defined', function() {
it('is defined', function(done) {
expect(Utils._.camelizeIf).to.be.ok
done()
})
it('camelizes if second param is true', function() {
it('camelizes if second param is true', function(done) {
expect(Utils._.camelizeIf('foo_bar', true)).to.equal('fooBar')
done()
})
it("doesn't camelize if second param is false", function() {
it("doesn't camelize if second param is false", function(done) {
expect(Utils._.underscoredIf('fooBar', true)).to.equal('foo_bar')
done()
})
})
})
describe('isHash', function() {
it('doesn\'t match arrays', function() {
it('doesn\'t match arrays', function(done) {
expect(Utils.isHash([])).to.be.false
done()
})
it('doesn\'t match null', function() {
it('doesn\'t match null', function(done) {
expect(Utils.isHash(null)).to.be.false
done()
})
it('matches plain objects', function() {
it('matches plain objects', function(done) {
var values = {
'name': {
'first': 'Foo',
......@@ -111,9 +128,10 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
}
expect(Utils.isHash(values)).to.be.true
done()
})
it('matches plain objects with length property/key', function() {
it('matches plain objects with length property/key', function(done) {
var values = {
'name': {
'first': 'Foo',
......@@ -123,18 +141,21 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
}
expect(Utils.isHash(values)).to.be.true
done()
})
})
describe('format', function() {
it('should format where clause correctly when the value is truthy', function() {
it('should format where clause correctly when the value is truthy', function(done) {
var where = ['foo = ?', 1]
expect(Utils.format(where)).to.equal('foo = 1')
done()
})
it('should format where clause correctly when the value is false', function() {
it('should format where clause correctly when the value is false', function(done) {
var where = ['foo = ?', 0]
expect(Utils.format(where)).to.equal('foo = 0')
done()
})
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!