diff --git a/server/classrooms/classroom_handler.coffee b/server/classrooms/classroom_handler.coffee index 3456376f4..5ef0d1a98 100644 --- a/server/classrooms/classroom_handler.coffee +++ b/server/classrooms/classroom_handler.coffee @@ -57,10 +57,11 @@ ClassroomHandler = class ClassroomHandler extends Handler members = _.clone(classroom.get('members')) if _.any(members, (memberID) -> memberID.equals(req.user.get('_id'))) return @sendSuccess(res, @formatEntity(req, classroom)) - members.push req.user.get('_id') - classroom.set('members', members) - classroom.save (err, classroom) => + update = { $push: { members : req.user.get('_id')}} + classroom.update update, (err) => return @sendDatabaseError(res, err) if err + members.push req.user.get('_id') + classroom.set('members', members) return @sendSuccess(res, @formatEntity(req, classroom)) formatEntity: (req, doc) -> diff --git a/test/server/functional/classrooms.spec.coffee b/test/server/functional/classrooms.spec.coffee index ce121eb0d..4bd176b1c 100644 --- a/test/server/functional/classrooms.spec.coffee +++ b/test/server/functional/classrooms.spec.coffee @@ -123,13 +123,16 @@ describe 'POST /db/classroom/:id/members', -> data = { name: 'Classroom 5' } request.post {uri: classroomsURL, json: data }, (err, res, body) -> classroomCode = body.code + classroomID = body._id expect(res.statusCode).toBe(200) loginNewUser (user2) -> url = getURL("/db/classroom/~/members") data = { code: classroomCode } request.post { uri: url, json: data }, (err, res, body) -> expect(res.statusCode).toBe(200) - done() + Classroom.findById classroomID, (err, classroom) -> + expect(classroom.get('members').length).toBe(1) + done() describe 'POST /db/classroom/:id/invite-members', ->