Fix error message

* Fix error message when PK is changed in `replaceById`
This commit is contained in:
Amir Jafarian 2016-06-01 16:26:41 -04:00
parent 39907c6421
commit c093648525
2 changed files with 13 additions and 1 deletions

View File

@ -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;

View File

@ -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);