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

Commit 88622127 by Sushant Committed by GitHub

fix(datatypes): DATE/DATEONLY marked as changed when changed from null to null (#8483)

1 parent 669f09fd
......@@ -355,6 +355,11 @@ DATE.prototype._isChanged = function _isChanged(value, originalValue) {
return false;
}
// not changed when set to same empty value
if (!originalValue && !value && originalValue === value) {
return false;
}
return true;
};
......@@ -406,6 +411,11 @@ DATEONLY.prototype._isChanged = function _isChanged(value, originalValue) {
return false;
}
// not changed when set to same empty value
if (!originalValue && !value && originalValue === value) {
return false;
}
return true;
};
......
......@@ -11,7 +11,8 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
beforeEach(function() {
this.User = current.define('User', {
name: DataTypes.STRING,
birthdate: DataTypes.DATE,
birthday: DataTypes.DATE,
yoj: DataTypes.DATEONLY,
meta: DataTypes.JSON
});
});
......@@ -49,16 +50,16 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
it('should return true for multiple changed values', function() {
const user = this.User.build({
name: 'a',
birthdate: new Date(new Date() - 10)
birthday: new Date(new Date() - 10)
}, {
isNewRecord: false,
raw: true
});
user.set('name', 'b');
user.set('birthdate', new Date());
user.set('birthday', new Date());
expect(user.changed('name')).to.equal(true);
expect(user.changed('birthdate')).to.equal(true);
expect(user.changed('birthday')).to.equal(true);
});
it('should return false for two instances with same value', function() {
......@@ -67,14 +68,14 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
const secondDate = new Date(milliseconds);
const user = this.User.build({
birthdate: firstDate
birthday: firstDate
}, {
isNewRecord: false,
raw: true
});
user.set('birthdate', secondDate);
expect(user.changed('birthdate')).to.equal(false);
user.set('birthday', secondDate);
expect(user.changed('birthday')).to.equal(false);
});
it('should return true for changed JSON with same object', function() {
......@@ -149,5 +150,25 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
user.set('meta.address', { street: 'Main street', number: '40' } );
expect(user.changed('meta')).to.equal(false);
});
it('should return false when changed from null to null', function() {
const attributes = {};
for (const attr in this.User.rawAttributes) {
attributes[attr] = null;
}
const user = this.User.build(attributes, {
isNewRecord: false,
raw: true
});
for (const attr in this.User.rawAttributes) {
user.set(attr, null);
}
for (const attr in this.User.rawAttributes) {
expect(user.changed(attr), `${attr} is not changed`).to.equal(false);
}
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!