model-definition.spec.js
1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var should = require("should")
, config = require("./config/config")
, Helpers = require("./config/helpers")
, Sequelize = require("../index")
describe('ModelDefinition', function() {
var sequelize = new Sequelize(config.database, config.username, config.password, { logging: false })
, User = sequelize.define('User', { name: Sequelize.STRING, bio: Sequelize.TEXT })
afterEach(function() {
Helpers.async(function(done) {
sequelize.drop().on('success', done)
})
})
describe('.all', function() {
beforeEach(function() {
var createUser = function(num, cb) {
console.log('create user')
User.create({name: 'user' + num, bio: 'foobar'}).on('success', function(user){
--num ? createUser(num, cb) : cb()
})
}
Helpers.async(function(done) {
User.sync({force: true}).on('success', function() { done() })
})
Helpers.async(function(done) { createUser(2, done) })
})
it("should return all users", function() {
Helpers.async(function(done) {
User.all.on('success', function(users) {
done()
expect(users.length).toEqual(2)
})
})
})
})
describe('.create with options', function() {
var Person = sequelize.define('Person', { name: Sequelize.STRING, options: Sequelize.TEXT })
beforeEach(function() {
Helpers.async(function(done) {
Person.sync({force: true}).on('success', function() { done() })
})
})
it('should allow the creation of an object with options as attribute', function() {
Helpers.async(function(done) {
var options = JSON.stringify({ foo: 'bar', bar: 'foo' })
Person.create({name: 'John Doe', options: options}).on('success', function(person) {
expect(person.options).toEqual(options)
done()
})
})
})
})
})