From 25076ab08748aa600f44224e0e259f7fe77c802d Mon Sep 17 00:00:00 2001 From: Harry Wolff Date: Thu, 10 Jul 2014 07:58:26 -0400 Subject: [PATCH] Fix slowdown of tests by reverting back to using knex in test/utils --- core/test/utils/index.js | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/core/test/utils/index.js b/core/test/utils/index.js index edea7d29d0..be27ebd23f 100644 --- a/core/test/utils/index.js +++ b/core/test/utils/index.js @@ -1,4 +1,4 @@ -var config = require('../../server/config'), +var knex = require('../../server/models/base').knex, when = require('when'), sequence = require('when/sequence'), nodefn = require('when/node'), @@ -20,7 +20,6 @@ function clearData() { } function insertPosts() { - var knex = config().database.knex; // ToDo: Get rid of pyramid of doom return when(knex('posts').insert(DataGenerator.forKnex.posts).then(function () { return knex('tags').insert(DataGenerator.forKnex.tags).then(function () { @@ -47,18 +46,16 @@ function insertMorePosts(max) { } } - return sequence(_.times(posts.length, function (index) { + return sequence(_.times(posts.length, function(index) { return function() { - return config().database.knex('posts').insert(posts[index]); - }; + return knex('posts').insert(posts[index]); + } })); } function insertMorePostsTags(max) { max = max || 50; - var knex = config().database.knex; - return when.all([ // PostgreSQL can return results in any order knex('posts').orderBy('id', 'asc').select('id'), @@ -89,8 +86,7 @@ function insertMorePostsTags(max) { } function insertDefaultUser() { - var user, - knex = config().database.knex; + var user; user = DataGenerator.forKnex.createUser(DataGenerator.Content.users[0]); @@ -101,8 +97,7 @@ function insertDefaultUser() { function insertEditorUser() { var users = [], - userRoles = [], - knex = config().database.knex; + userRoles = []; users.push(DataGenerator.forKnex.createUser(DataGenerator.Content.users[1])); userRoles.push(DataGenerator.forKnex.createUserRole(2, 2)); @@ -115,8 +110,7 @@ function insertEditorUser() { function insertAuthorUser() { var users = [], - userRoles = [], - knex = config().database.knex; + userRoles = []; users.push(DataGenerator.forKnex.createUser(DataGenerator.Content.users[2])); userRoles.push(DataGenerator.forKnex.createUserRole(3, 3)); @@ -128,8 +122,7 @@ function insertAuthorUser() { } function insertDefaultApp() { - var apps = [], - knex = config().database.knex; + var apps = []; apps.push(DataGenerator.forKnex.createApp(DataGenerator.Content.apps[0])); @@ -145,16 +138,13 @@ function insertDefaultApp() { } function insertApps() { - var knex = config().database.knex; return knex('apps').insert(DataGenerator.forKnex.apps).then(function () { return knex('app_fields').insert(DataGenerator.forKnex.app_fields); }); } function insertAppWithSettings() { - var apps = [], - app_settings = [], - knex = config().database.knex; + var apps = [], app_settings = []; apps.push(DataGenerator.forKnex.createApp(DataGenerator.Content.apps[0])); app_settings.push(DataGenerator.forKnex.createAppSetting(DataGenerator.Content.app_settings[0])); @@ -172,9 +162,7 @@ function insertAppWithSettings() { }); } function insertAppWithFields() { - var apps = [], - app_fields = [], - knex = config().database.knex; + var apps = [], app_fields = []; apps.push(DataGenerator.forKnex.createApp(DataGenerator.Content.apps[0])); app_fields.push(DataGenerator.forKnex.createAppField(DataGenerator.Content.app_fields[0]));