update-attributes.js
1.94 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
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 })
module.exports = {
'it should update the attributes': function(exit) {
User.sync({force:true}).on('success', function() {
User.create({name: 'snafu'}).on('success', function(user) {
assert.eql(user.name, 'snafu')
user.updateAttributes({name: 'foobar'}).on('success', function(user) {
assert.eql(user.name, 'foobar')
exit(function(){})
})
})
})
},
'it should not set attributes which were not defined': function(exit) {
User.sync({force:true}).on('success', function() {
User.create({name: 'snafu'}).on('success', function(user) {
user.updateAttributes({name: 'foobar', foo: 'bar'}).on('success', function(user) {
assert.eql(user.name, 'foobar')
assert.isUndefined(user.foo)
exit(function(){})
})
})
})
},
'it should not set primary keys or timestamps': function(exit) {
User = sequelize.define('User' + parseInt(Math.random() * 9999999999999), {
name: Sequelize.STRING, bio: Sequelize.TEXT, identifier: {type: Sequelize.STRING, primaryKey: true}
})
User.sync({force:true}).on('success', function() {
User.create({name: 'snafu', identifier: 'identifier'}).on('success', function(user) {
var oldCreatedAt = user.createdAt
, oldIdentifier = user.identifier
user.updateAttributes({name: 'foobar', createdAt: new Date(2000, 1, 1), identifier: 'another identifier'}).on('success', function(user) {
assert.eql(user.createdAt, oldCreatedAt)
assert.eql(user.identifier, oldIdentifier)
exit(function(){})
})
})
})
}
}