From 9afaa9a66ed60f10a16c04ea250a9f2e12514daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20B=C3=A8ges?= Date: Sat, 17 Dec 2016 17:21:04 +0100 Subject: [PATCH] Fix id update error message formatting Error is raised when trying to update an id property while forceId is set to true --- lib/dao.js | 5 +++-- test/optional-validation.test.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/dao.js b/lib/dao.js index 276edf16..67e0d793 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -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); diff --git a/test/optional-validation.test.js b/test/optional-validation.test.js index 95ac6f71..8ea7195d 100644 --- a/test/optional-validation.test.js +++ b/test/optional-validation.test.js @@ -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(); + }); + }); + }); }); });