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

Commit af3d9c1f by Robert Scheinpflug Committed by Sushant

fix instance.set '1970-01-01' to null field (#6839)

1 parent eff38529
Showing with 38 additions and 5 deletions
......@@ -346,11 +346,13 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
if (!(value instanceof Date)) {
value = new Date(value);
}
if (!(originalValue instanceof Date)) {
originalValue = new Date(originalValue);
}
if (originalValue && value.getTime() === originalValue.getTime()) {
return this;
if (originalValue) {
if (!(originalValue instanceof Date)) {
originalValue = new Date(originalValue);
}
if (value.getTime() === originalValue.getTime()) {
return this;
}
}
}
}
......
......@@ -44,5 +44,36 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
var user2 = User.build({});
expect(user2.get('meta')).to.deep.equal({});
});
it('sets the date "1970-01-01" to previously null field', function() {
var User = current.define('User', {
date: {
type: DataTypes.DATE,
allowNull: true
}
});
var user1 = User.build({
date: null
});
user1.set('date', '1970-01-01');
expect(user1.get('date')).to.be.ok;
expect(user1.get('date').getTime()).to.equal(new Date('1970-01-01').getTime());
});
it('overwrites non-date originalValue with date', function() {
var User = current.define('User', {
date: DataTypes.DATE
});
var user = User.build({
date: ' '
}, {
isNewRecord: false,
raw: true
});
user.set('date', new Date());
expect(user.get('date')).to.be.an.instanceof(Date);
expect(user.get('date')).not.to.be.NaN;
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!