Permalink
Browse files

allow location to be cleared

  • Loading branch information...
1 parent c050875 commit d464b180cf6a99b32c20605c926617b70dab85f0 @particlebanana particlebanana committed Apr 12, 2012
Showing with 32 additions and 3 deletions.
  1. +7 −3 lib/controllers/users.js
  2. +25 −0 test/controllers/users-test.js
@@ -97,18 +97,22 @@ module.exports = function() {
var self = this,
data = this.req.body;
- if(!data.name && !data.avatar && !data.location) {
+ var location = Object.keys(data).indexOf('location') > -1;
+
+ if(!data.name && !data.avatar && !location) {
return self.res.json(400, { error: 'Invalid entity' });
}
// Build an object of attributes to update
var attributes = {};
if(data.name) { attributes.name = data.name; }
if(data.avatar) { attributes.avatar = data.avatar; }
- if(data.location) { attributes.location = data.location; }
+ if(location) {
+ attributes.location = data.location;
+ }
User.get(id, function(err, user) {
- user.update(attributes, function(err) {
+ user.update(attributes, function(err, obj) {
if(err) {
return self.res.json(500, { error: 'Error updating user' });
}
@@ -260,6 +260,31 @@ describe('Users', function() {
});
});
+ // Test updating location
+ describe('empty location', function() {
+
+ before(function(done) {
+ // add a user to ensure a good ID
+ makePostReq('/users', {name: 'Test User'}, function(err, res, body) {
+ var id = JSON.parse(body)._id;
+
+ makePutReq('/users/' + id, {location: ''}, function(err, res, body) {
+ result = res;
+ data = JSON.parse(body);
+ done();
+ });
+ });
+ });
+
+ it('should return a 200 status code', function() {
+ result.statusCode.should.equal(200);
+ });
+
+ it('should clear location', function() {
+ data.location.should.equal('');
+ });
+ });
+
});

0 comments on commit d464b18

Please sign in to comment.