From 3fe9bdc24cf59eadfcd54107fda9be577dc6aab7 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 6 Mar 2014 13:08:22 -0500 Subject: [PATCH 1/6] removed the postbar selector from activeusers --- public/src/forum/topic.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 6383cac823..a83e0493ce 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -622,7 +622,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { socket.on('get_users_in_room', function(data) { if(data && data.room.indexOf('topic') !== -1) { - var activeEl = $('li.post-bar[data-index="0"] .thread_active_users'); + var activeEl = $('.thread_active_users'); function createUserIcon(uid, picture, userslug, username) { if(!activeEl.find('[data-uid="' + uid + '"]').length) { @@ -694,11 +694,9 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { // Get users who are currently replying to the topic entered socket.emit('modules.composer.getUsersByTid', templates.get('topic_id'), function(err, uids) { - var activeUsersEl = $('.thread_active_users'), - x; if (uids && uids.length) { for(var x=0;x Date: Thu, 6 Mar 2014 13:32:26 -0500 Subject: [PATCH 2/6] closes #1167 --- public/src/forum/login.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/src/forum/login.js b/public/src/forum/login.js index 11afd12cdc..de0defd54a 100644 --- a/public/src/forum/login.js +++ b/public/src/forum/login.js @@ -52,7 +52,7 @@ define(function() { return false; }); - $('#content input').focus(); + $('#content #username').focus(); }; return Login; From 4986c8ed3af1f11a95807d9cf22a08fea7e6fcd7 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 6 Mar 2014 14:51:43 -0500 Subject: [PATCH 3/6] fixed tests --- mocks/databasemock.js | 18 ++++++++++---- src/database/mongo.js | 9 +------ src/database/redis.js | 6 ++--- src/meta.js | 3 +++ tests/topics.js | 58 ++++++++++++++++++++++++------------------- tests/user.js | 8 +++--- 6 files changed, 55 insertions(+), 47 deletions(-) diff --git a/mocks/databasemock.js b/mocks/databasemock.js index 89e5f850e7..abdf7fd97a 100644 --- a/mocks/databasemock.js +++ b/mocks/databasemock.js @@ -55,23 +55,31 @@ nconf.set(dbType, testDbConfig); - db = require('../src/database'); + var db = require('../src/database'), + meta = require('../src/meta'); before(function(done) { db.init(function(err) { //Clean up db.flushdb(function(err) { - if(err){ + if(err) { winston.error(err); throw new Error(err); } else { winston.info('test_database flushed'); - done(); - } - //TODO: data seeding, if needed at all + meta.configs.init(function () { + + var webserver = require('../src/webserver'), + sockets = require('../src/socket.io'); + + sockets.init(webserver.server); + + done(); + }); + } }); }); }); diff --git a/src/database/mongo.js b/src/database/mongo.js index f568f3d514..af913ea9e1 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -166,15 +166,8 @@ module.flushdb = function(callback) { db.dropDatabase(function(err, result) { - if (err) { - winston.error(err.message); - if (typeof callback === 'function') { - return callback(err); - } - } - if (typeof callback === 'function') { - callback(); + callback(err); } }); }; diff --git a/src/database/redis.js b/src/database/redis.js index 4655eabb62..3892690a6f 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -117,11 +117,9 @@ module.flushdb = function(callback) { redisClient.send_command('flushdb', [], function(err) { - if (err) { - winston.error(err.message); - return callback(err); + if (typeof callback === 'function') { + callback(); } - callback(); }); }; diff --git a/src/meta.js b/src/meta.js index ce1cd70990..197351a11d 100644 --- a/src/meta.js +++ b/src/meta.js @@ -87,6 +87,9 @@ var fs = require('fs'), Meta.themes = { get: function (callback) { var themePath = nconf.get('themes_path'); + if (typeof themePath !== 'string') { + return callback(null, []); + } fs.readdir(themePath, function (err, files) { async.filter(files, function (file, next) { fs.stat(path.join(themePath, file), function (err, fileStat) { diff --git a/tests/topics.js b/tests/topics.js index 92404ee393..a028c1b274 100644 --- a/tests/topics.js +++ b/tests/topics.js @@ -1,31 +1,39 @@ -var winston = require('winston'); - -process.on('uncaughtException', function (err) { - winston.error('Encountered error while running test suite: ' + err.message); -}); +'use strict'; var assert = require('assert'), - db = require('../mocks/databasemock'); - - -var Topics = require('../src/topics'); + db = require('../mocks/databasemock'), + topics = require('../src/topics'), + categories = require('../src/categories'); describe('Topic\'s', function() { - var topic; - - beforeEach(function(){ - topic = { - userId: 1, - categoryId: 1, - title: 'Test Topic Title', - content: 'The content of test topic' - }; + var topic, + categoryObj; + + before(function(done) { + + categories.create({ + name: 'Test Category', + description: 'Test category created by testing script', + icon: 'fa-check', + blockclass: 'category-blue', + order: '5' + }, function(err, category) { + categoryObj = category; + + topic = { + userId: 1, + categoryId: categoryObj.cid, + title: 'Test Topic Title', + content: 'The content of test topic' + }; + done(); + }); }); describe('.post', function() { it('should create a new topic with proper parameters', function(done) { - Topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) { + topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) { assert.equal(err, null, 'was created with error'); assert.ok(result); @@ -34,9 +42,7 @@ describe('Topic\'s', function() { }); it('should fail to create new topic with wrong parameters', function(done) { - topic.userId = null; - - Topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) { + topics.post({uid: null, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) { assert.equal(err.message, 'invalid-user'); done(); }); @@ -47,8 +53,8 @@ describe('Topic\'s', function() { var newTopic; var newPost; - beforeEach(function(done){ - Topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) { + beforeEach(function(done) { + topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) { newTopic = result.topicData; newPost = result.postData; done(); @@ -57,13 +63,13 @@ describe('Topic\'s', function() { describe('.getTopicData', function() { it('should not receive errors', function(done) { - Topics.getTopicData(newTopic.tid, done); + topics.getTopicData(newTopic.tid, done); }); }); describe('.getTopicDataWithUser', function() { it('should not receive errors', function(done) { - Topics.getTopicDataWithUser(newTopic.tid, done); + topics.getTopicDataWithUser(newTopic.tid, done); }); }); }); diff --git a/tests/user.js b/tests/user.js index 40c7156cbd..5da9412802 100644 --- a/tests/user.js +++ b/tests/user.js @@ -16,7 +16,7 @@ describe('User', function() { beforeEach(function(){ userData = { - name: 'John Smith', + username: 'John Smith', password: 'swordfish', email: 'john@example.com', callback: undefined @@ -25,8 +25,8 @@ describe('User', function() { describe('when created', function() { - it('should be created properly', function(done){ - User.create({usename: userData.name, password: userData.password, email: userData.email}, function(error,userId){ + it('should be created properly', function(done) { + User.create({username: userData.username, password: userData.password, email: userData.email}, function(error,userId){ assert.equal(error, null, 'was created with error'); assert.ok(userId); done(); @@ -35,7 +35,7 @@ describe('User', function() { it('should have a valid email, if using an email', function() { assert.throws( - User.create({username: userData.name, password: userData.password, email: 'fakeMail'},function(){}), + User.create({username: userData.username, password: userData.password, email: 'fakeMail'},function(){}), Error, 'does not validate email' ); From da0e1a8eb91db0bdd6684e86f4b8792b45331687 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 6 Mar 2014 14:52:34 -0500 Subject: [PATCH 4/6] added back err to redis flushdb --- src/database/redis.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/database/redis.js b/src/database/redis.js index 3892690a6f..d672994b6c 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -118,7 +118,7 @@ module.flushdb = function(callback) { redisClient.send_command('flushdb', [], function(err) { if (typeof callback === 'function') { - callback(); + callback(err); } }); }; From acd4771012cc578b84309a145fcc4fa222324d9e Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 6 Mar 2014 15:11:29 -0500 Subject: [PATCH 5/6] dbmock changes --- mocks/databasemock.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mocks/databasemock.js b/mocks/databasemock.js index abdf7fd97a..7a2a11ca60 100644 --- a/mocks/databasemock.js +++ b/mocks/databasemock.js @@ -57,6 +57,7 @@ var db = require('../src/database'), meta = require('../src/meta'); + before(function(done) { db.init(function(err) { @@ -65,21 +66,18 @@ if(err) { winston.error(err); throw new Error(err); - } else { - winston.info('test_database flushed'); - + } - meta.configs.init(function () { + winston.info('test_database flushed'); - var webserver = require('../src/webserver'), - sockets = require('../src/socket.io'); + meta.configs.init(function () { + var webserver = require('../src/webserver'), + sockets = require('../src/socket.io'); sockets.init(webserver.server); - - done(); - }); - } + done(); + }); }); }); }); From d34e68ca25bb948bdf528eda1adbaf8b7d01e4ad Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 6 Mar 2014 15:31:10 -0500 Subject: [PATCH 6/6] convert score to int in mongo --- src/database/mongo.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index af913ea9e1..a9cc09c2d4 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -544,8 +544,8 @@ value = value.toString(); } var data = { - score:score, - value:value + score: parseInt(score, 10), + value: value }; db.collection('objects').update({_key:key, value:value}, {$set:data}, {upsert:true, w: 1}, function(err, result) {