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

Commit 42bb3458 by Tiago Ribeiro

Fix bug when only createdAt is enabled

1 parent 70a0cb3e
Showing with 33 additions and 1 deletions
...@@ -358,7 +358,7 @@ module.exports = (function() { ...@@ -358,7 +358,7 @@ module.exports = (function() {
&& !!self.Model.rawAttributes[createdAtAttr].defaultValue && !!self.Model.rawAttributes[createdAtAttr].defaultValue
) )
? self.Model.rawAttributes[createdAtAttr].defaultValue ? self.Model.rawAttributes[createdAtAttr].defaultValue
: values[updatedAtAttr]) : Utils.now(self.sequelize.options.dialect))
} }
var query = null var query = null
......
...@@ -863,6 +863,38 @@ describe(Support.getTestDialectTeaser("DAO"), function () { ...@@ -863,6 +863,38 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
}) })
}) })
describe('with custom timestamp options', function() {
var now = Date.now()
it("updates the createdAt column if updatedAt is disabled", function(done) {
var User2 = this.sequelize.define('User2', {
username: DataTypes.STRING
}, { updatedAt: false })
User2.sync().success(function() {
User2.create({ username: 'john doe' }).success(function(johnDoe) {
expect(johnDoe.updatedAt).to.be.undefined;
expect(now).to.be.below(johnDoe.createdAt.getTime())
done()
})
})
})
it("updates the updatedAt column if createdAt is disabled", function(done) {
var User2 = this.sequelize.define('User2', {
username: DataTypes.STRING
}, { createdAt: false })
User2.sync().success(function() {
User2.create({ username: 'john doe' }).success(function(johnDoe) {
expect(johnDoe.createdAt).to.be.undefined;
expect(now).to.be.below(johnDoe.updatedAt.getTime())
done()
})
})
})
})
it('should fail a validation upon creating', function(done){ it('should fail a validation upon creating', function(done){
this.User.create({aNumber: 0, validateTest: 'hello'}).error(function(err){ this.User.create({aNumber: 0, validateTest: 'hello'}).error(function(err){
expect(err).to.exist expect(err).to.exist
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!