attributes.test.js
2.66 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* jshint camelcase: false */
/* jshint expr: true */
var chai = require('chai')
, Sequelize = require('../../index')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + "/../../lib/data-types")
, dialect = Support.getTestDialect()
, datetime = require('chai-datetime')
chai.use(datetime)
chai.config.includeStack = true
describe(Support.getTestDialectTeaser("Model"), function () {
describe('attributes', function () {
describe('field', function () {
beforeEach(function () {
var queryInterface = this.sequelize.getQueryInterface();
this.User = this.sequelize.define('user', {
name: {
type: DataTypes.STRING,
field: 'full_name'
}
}, {
tableName: 'users',
timestamps: false
})
return queryInterface.createTable('users', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
full_name: {
type: DataTypes.STRING
}
});
});
it('should create, fetch and update with alternative field names from a simple model', function () {
var self = this;
return this.User.create({
name: 'Foobar'
}).then(function () {
return self.User.find({
limit: 1
});
}).then(function (user) {
expect(user.get('name')).to.equal('Foobar');
return user.updateAttributes({
name: 'Barfoo'
});
}).then(function () {
return self.User.find({
limit: 1
});
}).then(function (user) {
expect(user.get('name')).to.equal('Barfoo');
})
});
it('should work with a simple where', function () {
var self = this;
return this.User.create({
name: 'Foobar'
}).then(function () {
return self.User.find({
where: {
name: 'Foobar'
}
});
}).then(function (user) {
expect(user).to.be.ok
})
});
it('should work with bulkCreate and findAll', function () {
var self = this;
return this.User.bulkCreate([{
name: 'Abc',
}, {
name: 'Bcd'
}, {
name: 'Cde'
}]).then(function () {
return self.User.findAll();
}).then(function (users) {
users.forEach(function (user) {
expect(['Abc', 'Bcd', 'Cde'].indexOf(user.get('name')) !== -1).to.be.true
});
});
});
})
})
})