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

Commit 87b6d5f7 by Daniel Durante

Added specs for updateAttributes, and fixed a small createdAt bug.

1 parent b14aeda9
Showing with 13 additions and 4 deletions
...@@ -103,7 +103,7 @@ module.exports = (function() { ...@@ -103,7 +103,7 @@ module.exports = (function() {
fields.push(updatedAtAttr) fields.push(updatedAtAttr)
} }
if (fields.indexOf(createdAtAttr) === -1) { if (fields.indexOf(createdAtAttr) === -1 && this.isNewRecord === true) {
fields.push(createdAtAttr) fields.push(createdAtAttr)
} }
} }
...@@ -218,9 +218,10 @@ module.exports = (function() { ...@@ -218,9 +218,10 @@ module.exports = (function() {
var self = this var self = this
var readOnlyAttributes = Object.keys(this.__factory.primaryKeys) var readOnlyAttributes = Object.keys(this.__factory.primaryKeys)
readOnlyAttributes.push('id') readOnlyAttributes.push('id')
if (this.isNewRecord === true) {
readOnlyAttributes.push('createdAt') readOnlyAttributes.push('createdAt')
}
readOnlyAttributes.push('updatedAt') readOnlyAttributes.push('updatedAt')
readOnlyAttributes.push('deletedAt') readOnlyAttributes.push('deletedAt')
......
...@@ -690,10 +690,10 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -690,10 +690,10 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
expect(users.length).toEqual(2) expect(users.length).toEqual(2)
expect(users[0].username).toEqual("Peter") expect(users[0].username).toEqual("Peter")
expect(parseInt(+users[0].createdAt/5000)).toEqual(parseInt(+new Date()/5000)) expect(parseInt(+users[0].createdAt/5000, 10)).toEqual(parseInt(+new Date()/5000))
expect(users[1].username).toEqual("Paul") expect(users[1].username).toEqual("Paul")
expect(parseInt(+users[1].createdAt/5000)).toEqual(parseInt(+new Date()/5000)) expect(parseInt(+users[1].createdAt/5000, 10)).toEqual(parseInt(+new Date()/5000))
done() done()
}) })
...@@ -725,6 +725,14 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() { ...@@ -725,6 +725,14 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
}) // - bulkCreate }) // - bulkCreate
describe('update', function() { describe('update', function() {
it('updates the attributes that we select only', function(done) {
this.User.create({username: 'Peter', secretValue: '42'}).success(function(user) {
user.updateAttributes({ secretValue: '43' }, ['secretValue']).on('sql', function(sql) {
expect(sql).toMatch(/UPDATE\s+[`"]+Users[`"]+\s+SET\s+[`"]+secretValue[`"]='43',[`"]+updatedAt[`"]+='[^`",]+'\s+WHERE [`"]+id[`"]+=1/)
done()
})
})
})
it('updates only values that match filter', function(done) { it('updates only values that match filter', function(done) {
var self = this var self = this
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!