diff --git a/core/server/data/fixtures/index.js b/core/server/data/fixtures/index.js index df5c8b6e4d..2fff4ed502 100644 --- a/core/server/data/fixtures/index.js +++ b/core/server/data/fixtures/index.js @@ -1,4 +1,5 @@ -var sequence = require('when/sequence'), +var when = require('when'), + sequence = require('when/sequence'), _ = require('lodash'), utils = require('../../utils'), Post = require('../../models/post').Post, @@ -206,26 +207,30 @@ populateFixtures = function () { // add the tag to the post relations.push(function () { - Post.forge({id: 1}).fetch({withRelated: ['tags']}).then(function (post) { - post.tags().attach([1]); + return Post.forge({id: 1}).fetch({withRelated: ['tags']}).then(function (post) { + return post.tags().attach([1]); }); }); //grant permissions to roles relations.push(function () { + var relationOps = [], + relationOp; + // admins gets all permissions - Role.forge({name: 'Administrator'}).fetch({withRelated: ['permissions']}).then(function (role) { - Permissions.forge().fetch().then(function (perms) { + relationOp = Role.forge({name: 'Administrator'}).fetch({withRelated: ['permissions']}).then(function (role) { + return Permissions.forge().fetch().then(function (perms) { var admin_perm = _.map(perms.toJSON(), function (perm) { return perm.id; }); return role.permissions().attach(_.compact(admin_perm)); }); }); + relationOps.push(relationOp); // editor gets access to posts, users and settings.browse, settings.read - Role.forge({name: 'Editor'}).fetch({withRelated: ['permissions']}).then(function (role) { - Permissions.forge().fetch().then(function (perms) { + relationOp = Role.forge({name: 'Editor'}).fetch({withRelated: ['permissions']}).then(function (role) { + return Permissions.forge().fetch().then(function (perms) { var editor_perm = _.map(perms.toJSON(), function (perm) { if (perm.object_type === 'post' || perm.object_type === 'user' || perm.object_type === 'slug') { return perm.id; @@ -239,10 +244,11 @@ populateFixtures = function () { return role.permissions().attach(_.compact(editor_perm)); }); }); + relationOps.push(relationOp); // author gets access to post.add, slug.generate, settings.browse, settings.read, users.browse and users.read - Role.forge({name: 'Author'}).fetch({withRelated: ['permissions']}).then(function (role) { - Permissions.forge().fetch().then(function (perms) { + relationOp = Role.forge({name: 'Author'}).fetch({withRelated: ['permissions']}).then(function (role) { + return Permissions.forge().fetch().then(function (perms) { var author_perm = _.map(perms.toJSON(), function (perm) { if (perm.object_type === 'post' && perm.action_type === 'add') { return perm.id; @@ -263,6 +269,9 @@ populateFixtures = function () { return role.permissions().attach(_.compact(author_perm)); }); }); + relationOps.push(relationOp); + + return when.all(relationOps); }); return sequence(ops).then(function () { @@ -294,9 +303,12 @@ updateFixtures = function () { }); relations.push(function () { + var relationOps = [], + relationOp; + // admin gets all new permissions - Role.forge({name: 'Administrator'}).fetch({withRelated: ['permissions']}).then(function (role) { - Permissions.forge().fetch().then(function (perms) { + relationOp = Role.forge({name: 'Administrator'}).fetch({withRelated: ['permissions']}).then(function (role) { + return Permissions.forge().fetch().then(function (perms) { var admin_perm = _.map(perms.toJSON(), function (perm) { var result = fixtures.permissions003.filter(function (object) { return object.object_type === perm.object_type && object.action_type === perm.action_type; @@ -309,10 +321,11 @@ updateFixtures = function () { return role.permissions().attach(_.compact(admin_perm)); }); }); + relationOps.push(relationOp); // editor gets access to posts, users and settings.browse, settings.read - Role.forge({name: 'Editor'}).fetch({withRelated: ['permissions']}).then(function (role) { - Permissions.forge().fetch().then(function (perms) { + relationOp = Role.forge({name: 'Editor'}).fetch({withRelated: ['permissions']}).then(function (role) { + return Permissions.forge().fetch().then(function (perms) { var editor_perm = _.map(perms.toJSON(), function (perm) { if (perm.object_type === 'post' || perm.object_type === 'user') { return perm.id; @@ -326,10 +339,11 @@ updateFixtures = function () { return role.permissions().attach(_.compact(editor_perm)); }); }); + relationOps.push(relationOp); // author gets access to post.add, post.slug, settings.browse, settings.read, users.browse and users.read - Role.forge({name: 'Author'}).fetch({withRelated: ['permissions']}).then(function (role) { - Permissions.forge().fetch().then(function (perms) { + relationOp = Role.forge({name: 'Author'}).fetch({withRelated: ['permissions']}).then(function (role) { + return Permissions.forge().fetch().then(function (perms) { var author_perm = _.map(perms.toJSON(), function (perm) { if (perm.object_type === 'post' && perm.action_type === 'add') { return perm.id; @@ -350,6 +364,9 @@ updateFixtures = function () { return role.permissions().attach(_.compact(author_perm)); }); }); + relationOps.push(relationOp); + + return when.all(relationOps); }); return sequence(ops).then(function () { diff --git a/core/test/integration/api/api_db_spec.js b/core/test/integration/api/api_db_spec.js index d2576e7843..3ca5734256 100644 --- a/core/test/integration/api/api_db_spec.js +++ b/core/test/integration/api/api_db_spec.js @@ -43,13 +43,13 @@ describe('DB API', function () { result.db.should.be.instanceof(Array); result.db.should.be.empty; }).then(function () { - TagsAPI.browse().then(function (results) { + return TagsAPI.browse().then(function (results) { should.exist(results); should.exist(results.tags); results.tags.length.should.equal(0); }); }).then(function () { - PostAPI.browse().then(function (results) { + return PostAPI.browse().then(function (results) { should.exist(results); results.posts.length.should.equal(0); done(); diff --git a/core/test/utils/index.js b/core/test/utils/index.js index a6d9a7869f..1d992dc14a 100644 --- a/core/test/utils/index.js +++ b/core/test/utils/index.js @@ -186,7 +186,7 @@ function insertAppWithFields() { function insertDefaultFixtures() { return insertDefaultUser().then(function () { - return insertPosts() + return insertPosts(); }).then(function () { return insertApps(); });