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

Commit 5e68ef9d by Jan Aagaard Meier

Fixes #665

1 parent eaefe44c
......@@ -365,19 +365,21 @@ module.exports = (function() {
}
}
if (this.__options.timestamps && isNewRecord) {
if (isNewRecord) {
if (this.hasDefaultValues) {
Utils._.each(this.defaultValues, function(valueFn, key) {
if (!defaults.hasOwnProperty(key))
defaults[key] = valueFn()
})
}
if (this.__options.timestamps) {
defaults[this.__options.underscored ? 'created_at' : 'createdAt'] = Utils.now()
defaults[this.__options.underscored ? 'updated_at' : 'updatedAt'] = Utils.now()
if (this.__options.paranoid) {
defaults[this.__options.underscored ? 'deleted_at' : 'deletedAt'] = null
}
if (this.hasDefaultValues) {
Utils._.each(this.defaultValues, function(valueFn, key) {
if (!defaults.hasOwnProperty(key))
defaults[key] = valueFn()
})
}
}
......
......@@ -7,6 +7,7 @@ if(typeof require === 'function') {
}
buster.spec.expose()
buster.testRunner.timeout = 1000
describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
before(function(done) {
......@@ -124,6 +125,21 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
expect(Task.build().flag).toEqual(false)
})
it("fills the objects with default values", function() {
var Task = this.sequelize.define('Task', {
title: {type: Sequelize.STRING, defaultValue: 'a task!'},
foo: {type: Sequelize.INTEGER, defaultValue: 2},
bar: {type: Sequelize.DATE},
foobar: {type: Sequelize.TEXT, defaultValue: 'asd'},
flag: {type: Sequelize.BOOLEAN, defaultValue: false}
}, { timestamps: false })
expect(Task.build().title).toEqual('a task!')
expect(Task.build().foo).toEqual(2)
expect(Task.build().bar).toEqual(undefined)
expect(Task.build().foobar).toEqual('asd')
expect(Task.build().flag).toEqual(false)
})
it("stores the the passed values in a special variable", function() {
var user = this.User.build({ username: 'John Wayne' })
expect(user.selectedValues).toEqual({ username: 'John Wayne' })
......
......@@ -6,6 +6,7 @@ if (typeof require === 'function') {
}
buster.spec.expose()
buster.testRunner.timeout = 1000
describe(Helpers.getTestDialectTeaser("DAO"), function() {
before(function(done) {
......
......@@ -6,6 +6,7 @@ if(typeof require === 'function') {
}
buster.spec.expose()
buster.testRunner.timeout = 1000
describe(Helpers.getTestDialectTeaser("DaoValidator"), function() {
describe('validations', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!