var mongoose = require('mongoose');
var _ = require('lodash');

var AcceptanceTest = mongoose.model('AcceptanceTest');
var Situation = mongoose.model('Situation');

exports.find = function(req, res, next, id) {
    AcceptanceTest
        .findById(id)
        .populate('createdBy', '-password')
        .populate('derniereExecution', '-acceptanceTest -createdBy')
        .exec(function(err, acceptanceTest) {
            if (err) return next(err);
            if (!acceptanceTest) return res.send(404);
            req.acceptanceTest = acceptanceTest;
            next();
        });
};

exports.list = function(req, res, next) {
    AcceptanceTest
        .find()
        .populate('createdBy', '-password')
        .populate('derniereExecution', '-acceptanceTest -createdBy')
        .exec(function(err, acceptanceTests) {
            if (err) return next(err);
            res.send(acceptanceTests);
        });
};

exports.listValidated = function(req, res, next) {
    var query = AcceptanceTest
        .find({ state: 'validated' })
        .populate('derniereExecution', '-acceptanceTest -createdBy');

    if (req.user) {
        query.populate('createdBy', '-password');
    } else {
        query.select('-comment -state -createdBy');
    }

    query.exec(function(err, acceptanceTests) {
        if (err) return next(err);
        res.send(acceptanceTests);
    });
};

exports.listRejected = function(req, res, next) {
    AcceptanceTest
        .find({ state: 'rejected' })
        .populate('createdBy', '-password')
        .populate('derniereExecution', '-acceptanceTest -createdBy')
        .exec(function(err, acceptanceTests) {
            if (err) return next(err);
            res.send(acceptanceTests);
        });
};

exports.listPending = function(req, res, next) {
    AcceptanceTest
        .find({ state: 'pending' })
        .populate('createdBy', '-password')
        .populate('derniereExecution', '-acceptanceTest -createdBy')
        .exec(function(err, acceptanceTests) {
            if (err) return next(err);
            res.send(acceptanceTests);
        });
};

exports.listMine = function(req, res, next) {
    AcceptanceTest
        .find({ createdBy: req.user._id })
        .populate('createdBy', '-password')
        .populate('derniereExecution', '-acceptanceTest -createdBy')
        .exec(function(err, acceptanceTests) {
            if (err) return next(err);
            res.send(acceptanceTests);
        });
};

exports.create = function(req, res, next) {
    Situation.findById(req.body.situation, function(err, situation) {
        if (err) return next(err);
        if (!situation) return res.send(404);
        var acceptanceTest = new AcceptanceTest(_.pick(req.body, 'name', 'description', 'droitsAttendus'));
        acceptanceTest
            .set('createdBy', req.user._id)
            .set('situation', situation._id)
            .save(function(err) {
                if (err) return next(err);
                situation.set('status', 'test').save(function(err) {
                    if (err) return next(err);
                    res.send(acceptanceTest);
                });
            });
    });
};

exports.show = function(req, res) {
    res.send(req.acceptanceTest);
};

exports.update = function(req, res, next) {
    req.acceptanceTest
        .set('_updated', Date.now())
        .set(_.pick(req.body, 'name', 'description', 'droitsAttendus'))
        .save(function(err) {
            if (err) return next(err);
            res.send(req.situation);
        });
};

exports.delete = function(req, res, next) {
    req.acceptanceTest.remove(function(err) {
        if (err) return next(err);
        res.send(204);
    });
};

exports.validate = function(req, res, next) {
  console.log(req.body.comment);
    req.acceptanceTest
        .set('state', req.body.state)
        .set('comment', req.body.comment)
        .save(function(err) {
            if (err) return next(err);
            res.send(200);
        });
};

@@ -3741,41 +3741,8 @@
 ) %7B%0A
-  console.log(req.body.comment);%0A
     

Drop console.log