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:
parent
0cf863a483
commit
9afaa9a66e
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue