testTemplateUpdateNotValidated: function(test) { test.expect(5); var theTemplate = Template.factory({ name: 'Template test', description: '', html: '<h1>Test</h1>', plain: 'Test' }); theTemplate.save(function(err) { test.ifError(err); httpTest.post('/templates/edit/' + theTemplate.id, { name: '' }, function(err, res) { test.ifError(err); Template.find(theTemplate.id, function(err, updatedTemplate) { test.ifError(err); test.strictEqual(updatedTemplate.id, theTemplate.id); test.strictEqual(updatedTemplate.name, 'Template test'); test.done(); }); }); }); },
testTagUpdateNotValidated: function(test) { test.expect(5); var theTag = Tag.factory({ name: 'Tag test', description: '' }); theTag.save(function(err) { test.ifError(err); httpTest.post('/tags/edit/' + theTag.id, { name: '' }, function(err, res) { test.ifError(err); Tag.find(theTag.id, function(err, updatedTag) { test.ifError(err); test.strictEqual(updatedTag.id, theTag.id); test.strictEqual(updatedTag.name, 'Tag test'); test.done(); }); }); }); },
testTemplateRemove: function(test) { test.expect(4); var theTemplate = Template.factory({ name: 'Template test', description: '', html: '<h1>Test</h1>', plain: 'Test' }); theTemplate.save(function(err) { test.ifError(err); httpTest.get('/templates/remove/' + theTemplate.id, function(err, res) { test.ifError(err); Template.findAll(function(err, templates) { test.ifError(err); test.strictEqual(templates.length, 0); test.done(); }); }); }); },
loseUser.model.save(function(err) { if (!err) { callback(null, result); } else { callback(error.factory('rating', 'finishBattle', err, logger)); } });
me.model.save(function(err) { if (!err) { me.emit('save'); callback(null); } else { callback(error.factory('Usermodel', 'save', 'Cannot save user model ' + err, logger)); } });
Session.prototype.getCurrentUser = function(token, next){ try{ var user = jwt.verify(token, global.config.SESSION_SECRET); this.user = userModel.factory(user); next(false, user); } catch(e) { next(new Error('ERROR_SESSION_EXPIRED')); } };
return function(module, settings) { //returns a replacement for require() that already knows what the app framework context is var tmp = require(module); //use the vanilla require function to load the module context.require = require('context_loader')(context); //re-add itself to the context (probaby not needed but has come in handy) if(typeof tmp.factory == "function") { //if the module has a factory function, we will trust that function to initialze things within the module return tmp.factory(context, settings); } if(typeof tmp == "function") { //if the module returns a bare function instead, _.bind it to the app framework context return _.bind(require(module), context, settings); } return tmp; //if we can't bind it and it doesn't provide a factory, just return it like normal };
user.findById(uid, function(err, userModel) { if (!err) { if (userModel) { userModel.on('save', function() { me.api.pushUserUpdate(userModel); }); me.list[uid] = userModel; callback(null); } else { callback(error.factory('onlinelist', 'add', 'User not found', logger)); } } else { callback(err); } });
testTagEdit: function(test) { test.expect(2); var theTag = Tag.factory({ name: 'Tag Test' }); theTag.save(function(err) { test.ifError(err); httpTest.get('/tags/edit/' + theTag.id, function(err, res) { test.ifError(err); test.done(); }); }); },
testTemplateView: function(test) { test.expect(2); var theTemplate = Template.factory({ name: 'Template test', description: '', html: '<h1>Test</h1>', plain: 'Test' }); theTemplate.save(function(err) { test.ifError(err); httpTest.get('/templates/' + theTemplate.id, function(err, res) { test.ifError(err); test.done(); }); }); },
testTagRemove: function(test) { test.expect(4); var theTag = Tag.factory({ name: 'Tag test', description: '' }); theTag.save(function(err) { test.ifError(err); httpTest.get('/tags/remove/' + theTag.id, function(err, res) { test.ifError(err); Tag.findAll(function(err, tags) { test.ifError(err); test.strictEqual(tags.length, 0); test.done(); }); }); }); },
mongoose.model('users').find({}, function(err, users) { if (err) { callback(error.factory('rating', 'recalcRating', 'DB error ' + err, logger)); } else { users = _.sortBy(users, function(user) { return 10000000 - user.rating.points; }); rating = []; // рейтинг выстраиваю по лигам for(var i = 0; i < leagueRef.data.length; i++) { rating[leagueRef.data[i].index] = []; } for(var i = 0; i < users.length; i++) { if (!users[i].get('botId')) { rating[users[i].rating.league].push(users[i]); } } me.rating = rating; callback(null); } });