Fix id update error message formatting

Error is raised when trying to update an id property while forceId
is set to true
This commit is contained in:
Rémi Bèges 2016-12-17 17:21:04 +01:00
parent 0cf863a483
commit 9afaa9a66e
2 changed files with 16 additions and 2 deletions

View File

@ -3130,8 +3130,9 @@ function(data, options, cb) {
for (var i = 0, n = idNames.length; i < n; i++) {
var idName = idNames[i];
if (data[idName] !== undefined && !idEquals(data[idName], inst[idName])) {
var err = new Error(g.f('{{id}} property (%s) ' +
'cannot be updated from %s to %s'), idName, inst[idName], data[idName]);
var err = new Error(g.f('{{id}} cannot be updated from ' +
'%s to %s when forceId is set to true',
inst[idName], data[idName]));
err.statusCode = 400;
process.nextTick(function() {
cb(err);

View File

@ -308,6 +308,19 @@ describe('optional-validation', function() {
d.updateAttributes({'name': NEW_NAME}, expectChangeSuccess(done));
});
});
it('returns an error when trying to update the id property when forceId is set to true',
function(done) {
ModelWithForceId.create({name: 'foo'}, function(err, model) {
if (err) return done(err);
model.updateAttributes({id: 123}, function(err) {
err.should.be.instanceOf(Error);
err.message.should.eql('id cannot be updated from ' + model.id +
' to 123 when forceId is set to true');
done();
});
});
});
});
});