Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

allow location to be cleared

  • Loading branch information...
commit d464b180cf6a99b32c20605c926617b70dab85f0 1 parent c050875
Cody Stoltman authored April 12, 2012
10  lib/controllers/users.js
@@ -97,7 +97,9 @@ module.exports = function() {
97 97
     var self = this,
98 98
         data = this.req.body;
99 99
 
100  
-    if(!data.name && !data.avatar && !data.location) {
  100
+    var location = Object.keys(data).indexOf('location') > -1;
  101
+
  102
+    if(!data.name && !data.avatar && !location) {
101 103
       return self.res.json(400, { error: 'Invalid entity' });
102 104
     }
103 105
 
@@ -105,10 +107,12 @@ module.exports = function() {
105 107
     var attributes = {};
106 108
     if(data.name) { attributes.name = data.name; }
107 109
     if(data.avatar) { attributes.avatar = data.avatar; }
108  
-    if(data.location) { attributes.location = data.location; }
  110
+    if(location) {
  111
+      attributes.location = data.location;
  112
+    }
109 113
 
110 114
     User.get(id, function(err, user) {
111  
-      user.update(attributes, function(err) {
  115
+      user.update(attributes, function(err, obj) {
112 116
         if(err) {
113 117
           return self.res.json(500, { error: 'Error updating user' });
114 118
         }
25  test/controllers/users-test.js
@@ -260,6 +260,31 @@ describe('Users', function() {
260 260
       });
261 261
     });
262 262
 
  263
+    // Test updating location
  264
+    describe('empty location', function() {
  265
+
  266
+      before(function(done) {
  267
+        // add a user to ensure a good ID
  268
+        makePostReq('/users', {name: 'Test User'}, function(err, res, body) {
  269
+          var id = JSON.parse(body)._id;
  270
+
  271
+          makePutReq('/users/' + id, {location: ''}, function(err, res, body) {
  272
+            result = res;
  273
+            data = JSON.parse(body);
  274
+            done();
  275
+          });
  276
+        });
  277
+      });
  278
+
  279
+      it('should return a 200 status code', function() {
  280
+        result.statusCode.should.equal(200);
  281
+      });
  282
+
  283
+      it('should clear location', function() {
  284
+        data.location.should.equal('');
  285
+      });
  286
+    });
  287
+
263 288
   });
264 289
 
265 290
 

0 notes on commit d464b18

Please sign in to comment.
Something went wrong with that request. Please try again.