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

Commit ef31e540 by Daniel Durante

Made sure updatedAt was being updated when we setAttributes.

1 parent e68552f5
Showing with 19 additions and 10 deletions
...@@ -223,7 +223,7 @@ module.exports = (function() { ...@@ -223,7 +223,7 @@ module.exports = (function() {
if (this.isNewRecord !== true) { if (this.isNewRecord !== true) {
readOnlyAttributes.push(this.daoFactory.options.underscored === true ? 'created_at' : 'createdAt') readOnlyAttributes.push(this.daoFactory.options.underscored === true ? 'created_at' : 'createdAt')
} }
readOnlyAttributes.push(this.daoFactory.options.underscored === true ? 'updated_at' : 'updatedAt') // readOnlyAttributes.push(this.daoFactory.options.underscored === true ? 'updated_at' : 'updatedAt')
readOnlyAttributes.push(this.daoFactory.options.underscored === true ? 'deleted_at' : 'deletedAt') readOnlyAttributes.push(this.daoFactory.options.underscored === true ? 'deleted_at' : 'deletedAt')
Utils._.each(updates, function(value, attr) { Utils._.each(updates, function(value, attr) {
...@@ -235,6 +235,11 @@ module.exports = (function() { ...@@ -235,6 +235,11 @@ module.exports = (function() {
updateAllowed && (self[attr] = value) updateAllowed && (self[attr] = value)
}) })
// since we're updating the record, we should be updating the updatedAt column..
if (this.daoFactory.options.timestamps === true) {
self[this.daoFactory.options.underscored === true ? 'updated_at' : 'updatedAt'] = new Date()
}
} }
DAO.prototype.destroy = function() { DAO.prototype.destroy = function() {
......
...@@ -985,17 +985,21 @@ describe(Support.getTestDialectTeaser("DAO"), function () { ...@@ -985,17 +985,21 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
identifier: 'identifier' identifier: 'identifier'
}).success(function(user) { }).success(function(user) {
var oldCreatedAt = user.createdAt var oldCreatedAt = user.createdAt
, oldUpdatedAt = user.updatedAt
, oldIdentifier = user.identifier , oldIdentifier = user.identifier
user.updateAttributes({ setTimeout(function () {
name: 'foobar', user.updateAttributes({
createdAt: new Date(2000, 1, 1), name: 'foobar',
identifier: 'another identifier' createdAt: new Date(2000, 1, 1),
}).success(function(user) { identifier: 'another identifier'
expect(new Date(user.createdAt)).to.equalDate(new Date(oldCreatedAt)) }).success(function(user) {
expect(user.identifier).to.equal(oldIdentifier) expect(new Date(user.createdAt)).to.equalDate(new Date(oldCreatedAt))
done() expect(new Date(user.updatedAt)).to.not.equalTime(new Date(oldUpdatedAt))
}) expect(user.identifier).to.equal(oldIdentifier)
done()
})
}, 1000)
}) })
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!