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

Commit 0dff27a8 by Jan Aagaard Meier

Set updatedAt timestamp when validations is true in bulkUpdate. Closes #2136

1 parent e04ce1d1
Showing with 18 additions and 16 deletions
......@@ -1202,6 +1202,7 @@ module.exports = (function() {
if (options.validate === true) {
var build = self.build(attrValueHash)
build.set(self._timestampAttributes.updatedAt, attrValueHash[self._timestampAttributes.updatedAt], { raw: true })
// We want to skip validations for all other fields
var updatedFields = Object.keys(attrValueHash)
......
......@@ -746,21 +746,22 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
{ username: 'Bob', secretValue: '43' }]
this.User.bulkCreate(data).success(function() {
self.User.update({username: 'Bill'}, {secretValue: '42'}).done(function(err) {
expect(err).not.to.be.ok
self.User.findAll({order: 'id'}).success(function(users) {
expect(users.length).to.equal(3)
expect(users[0].username).to.equal("Bill")
expect(users[1].username).to.equal("Bill")
expect(users[2].username).to.equal("Bob")
setTimeout(function () {
self.User.update({username: 'Bill'}, {secretValue: '42'}).done(function(err) {
expect(err).not.to.be.ok
self.User.findAll({order: 'id'}).success(function(users) {
expect(users.length).to.equal(3)
expect(parseInt(+users[0].updatedAt/5000, 10)).to.be.closeTo(parseInt(+new Date()/5000, 10), 1)
expect(parseInt(+users[1].updatedAt/5000, 10)).to.be.closeTo(parseInt(+new Date()/5000, 10), 1)
expect(users[0].username).to.equal("Bill")
expect(users[1].username).to.equal("Bill")
expect(users[2].username).to.equal("Bob")
done()
expect(users[0].updatedAt).to.be.afterTime(users[2].updatedAt)
done()
})
})
})
}, 1000);
})
})
......@@ -775,14 +776,14 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
self.User.update({username: 'Bill'}, {secretValue: '42'}).done(function(err, affectedRows) {
expect(err).not.to.be.ok
expect(affectedRows).to.equal(2)
done()
})
self.User.update({username: 'Bill'}, {secretValue: '44'}).done(function(err, affectedRows) {
expect(err).not.to.be.ok
expect(affectedRows).to.equal(0)
done()
})
})
......@@ -960,14 +961,14 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
self.User.destroy({secretValue: '42'}).done(function(err, affectedRows) {
expect(err).not.to.be.ok
expect(affectedRows).to.equal(2)
done()
})
self.User.destroy({secretValue: '44'}).done(function(err, affectedRows) {
expect(err).not.to.be.ok
expect(affectedRows).to.equal(0)
done()
})
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!