From c093648525657addd17d3748b28361513f7626fe Mon Sep 17 00:00:00 2001 From: Amir Jafarian Date: Wed, 1 Jun 2016 16:26:41 -0400 Subject: [PATCH] Fix error message * Fix error message when PK is changed in `replaceById` --- lib/dao.js | 2 +- test/manipulation.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/dao.js b/lib/dao.js index 2c8f543b..458a5b92 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -2648,7 +2648,7 @@ DataAccessObject.replaceById = function(id, data, options, cb) { if (id !== data[pkName]) { var err = new Error('id property (' + pkName + ') ' + - 'cannot be updated from ' + inst[pkName] + ' to ' + data[pkName]); + 'cannot be updated from ' + id + ' to ' + data[pkName]); err.statusCode = 400; process.nextTick(function() { cb(err); }); return cb.promise; diff --git a/test/manipulation.test.js b/test/manipulation.test.js index 7f46cb21..f0baa94d 100644 --- a/test/manipulation.test.js +++ b/test/manipulation.test.js @@ -1020,6 +1020,18 @@ describe('manipulation', function() { .catch(done); }); + it('should fail when changing id', function(done) { + Post.findById(postInstance.id, function(err, p) { + if (err) return done(err); + p.replaceAttributes({ title: 'b', id: 999 }, function(err, p) { + should.exist(err); + var expectedErrMsg = 'id property (id) cannot be updated from ' + postInstance.id + ' to 999'; + err.message.should.equal(expectedErrMsg); + done(); + }); + }); + }); + it('works without options(callback variant)', function(done) { Post.findById(postInstance.id, function(err, p) { if (err) return done(err);