Skip to content

Commit

Permalink
Add test for non-existent field
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Macalinao <me@ian.pw>
  • Loading branch information
macalinao committed Aug 12, 2014
1 parent 3634a04 commit 5342eb0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var _ = require('lodash');
var async = require('async');
var queryHelper = require('./query');
var utils = require('./utils');
Expand Down Expand Up @@ -81,7 +82,7 @@ exports.update = function(model) {
var doc = req.doc;
var body = req.body;
for (var prop in body) {
if (!body.hasOwnProperty(prop)) {
if (!_.has(body, prop)) {
continue;
}
doc[prop] = body[prop];
Expand Down
14 changes: 14 additions & 0 deletions test/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,20 @@ describe('routes', function() {
});
});

it('should not change a non-existent field', function(done) {
User.id = 'name';
request(app).put('/users/Bob')
.send({
dne: 'Basketball'
})
.end(function(err, res) {
expect(err).to.be.null;
expect(res.status).to.equal(200);
expect(res.body.dne).to.be.undefined;
done();
});
});

it('should 404 if the document was not found', function(done) {
User.id = 'name';
request(app).put('/users/DNE')
Expand Down

0 comments on commit 5342eb0

Please sign in to comment.