mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 21:33:24 +03:00
Merge pull request #520 from gotdibbs/Timeouts
Patch to prevent timeouts in unit tests
This commit is contained in:
commit
fafead5718
@ -176,6 +176,10 @@ var path = require('path'),
|
||||
src: ['core/test/unit/**/api*_spec.js']
|
||||
},
|
||||
|
||||
frontend: {
|
||||
src: ['core/test/unit/**/frontend*_spec.js']
|
||||
},
|
||||
|
||||
perm: {
|
||||
src: ['core/test/unit/**/permissions_spec.js']
|
||||
},
|
||||
|
@ -10,8 +10,21 @@ describe("Role Model", function () {
|
||||
|
||||
should.exist(RoleModel);
|
||||
|
||||
before(function (done) {
|
||||
helpers.clearData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
beforeEach(function (done) {
|
||||
helpers.resetData().then(function () {
|
||||
this.timeout(5000);
|
||||
helpers.initData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
helpers.clearData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
@ -91,8 +104,21 @@ describe("Permission Model", function () {
|
||||
|
||||
should.exist(PermissionModel);
|
||||
|
||||
before(function (done) {
|
||||
helpers.clearData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
beforeEach(function (done) {
|
||||
helpers.resetData().then(function () {
|
||||
this.timeout(5000);
|
||||
helpers.initData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
helpers.clearData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
@ -9,10 +9,32 @@ var _ = require("underscore"),
|
||||
describe('Post Model', function () {
|
||||
|
||||
var PostModel = Models.Post,
|
||||
UserModel = Models.User;
|
||||
UserModel = Models.User,
|
||||
userData = {
|
||||
password: 'testpass1',
|
||||
email_address: "test@test1.com",
|
||||
full_name: "Mr Biscuits"
|
||||
};
|
||||
|
||||
before(function (done) {
|
||||
helpers.clearData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
beforeEach(function (done) {
|
||||
helpers.resetData().then(function () {
|
||||
this.timeout(5000);
|
||||
helpers.initData()
|
||||
.then(function () {
|
||||
return UserModel.add(userData);
|
||||
})
|
||||
.then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
helpers.clearData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
@ -48,62 +70,36 @@ describe('Post Model', function () {
|
||||
});
|
||||
|
||||
it('can findAll, returning author and user data', function (done) {
|
||||
var firstPost,
|
||||
userData = {
|
||||
password: 'testpass1',
|
||||
email_address: "test@test1.com",
|
||||
full_name: "Mr Biscuits"
|
||||
};
|
||||
var firstPost;
|
||||
|
||||
helpers.resetData().then(function () {
|
||||
UserModel.add(userData).then(function (createdUser) {
|
||||
PostModel.findAll({}).then(function (results) {
|
||||
should.exist(results);
|
||||
results.length.should.be.above(0);
|
||||
firstPost = results.models[0].toJSON();
|
||||
|
||||
PostModel.findAll({}).then(function (results) {
|
||||
should.exist(results);
|
||||
results.length.should.be.above(0);
|
||||
firstPost = results.models[0].toJSON();
|
||||
firstPost.author.should.be.a("object");
|
||||
firstPost.user.should.be.a("object");
|
||||
firstPost.author.full_name.should.equal("Mr Biscuits");
|
||||
firstPost.user.full_name.should.equal("Mr Biscuits");
|
||||
|
||||
firstPost.author.should.be.a("object");
|
||||
firstPost.user.should.be.a("object");
|
||||
firstPost.author.full_name.should.equal("Mr Biscuits");
|
||||
firstPost.user.full_name.should.equal("Mr Biscuits");
|
||||
|
||||
return true;
|
||||
|
||||
}).then(null, done);
|
||||
|
||||
done();
|
||||
}).then(null, done);
|
||||
});
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
it('can findOne, returning author and user data', function (done) {
|
||||
var firstPost,
|
||||
userData = {
|
||||
password: 'testpass1',
|
||||
email_address: "test@test1.com",
|
||||
full_name: "Mr Biscuits"
|
||||
};
|
||||
var firstPost;
|
||||
|
||||
helpers.resetData().then(function () {
|
||||
UserModel.add(userData).then(function (createdUser) {
|
||||
PostModel.findOne({}).then(function (result) {
|
||||
should.exist(result);
|
||||
firstPost = result.toJSON();
|
||||
|
||||
PostModel.findOne({}).then(function (result) {
|
||||
should.exist(result);
|
||||
firstPost = result.toJSON();
|
||||
firstPost.author.should.be.a("object");
|
||||
firstPost.user.should.be.a("object");
|
||||
firstPost.author.full_name.should.equal("Mr Biscuits");
|
||||
firstPost.user.full_name.should.equal("Mr Biscuits");
|
||||
|
||||
firstPost.author.should.be.a("object");
|
||||
firstPost.user.should.be.a("object");
|
||||
firstPost.author.full_name.should.equal("Mr Biscuits");
|
||||
firstPost.user.full_name.should.equal("Mr Biscuits");
|
||||
|
||||
return true;
|
||||
|
||||
}).then(null, done);
|
||||
|
||||
done();
|
||||
}).then(null, done);
|
||||
});
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
it('can edit', function (done) {
|
||||
@ -172,7 +168,9 @@ describe('Post Model', function () {
|
||||
content_raw: 'Test Content 1'
|
||||
};
|
||||
|
||||
// Create 12 posts with the sametitle
|
||||
this.timeout(5000); // this is a patch to ensure it doesn't timeout.
|
||||
|
||||
// Create 12 posts with the same title
|
||||
sequence(_.times(12, function (i) {
|
||||
return function () {
|
||||
return PostModel.add({
|
||||
@ -241,7 +239,7 @@ describe('Post Model', function () {
|
||||
});
|
||||
|
||||
it('can fetch a paginated set, with various options', function (done) {
|
||||
this.timeout(5000);
|
||||
this.timeout(10000); // this is a patch to ensure it doesn't timeout.
|
||||
|
||||
helpers.insertMorePosts().then(function () {
|
||||
|
||||
|
@ -8,8 +8,21 @@ describe('Settings Model', function () {
|
||||
|
||||
var SettingsModel = Models.Settings;
|
||||
|
||||
before(function (done) {
|
||||
helpers.clearData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
beforeEach(function (done) {
|
||||
helpers.resetData().then(function () {
|
||||
this.timeout(5000);
|
||||
helpers.initData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
helpers.clearData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
@ -6,25 +6,35 @@ var _ = require('underscore'),
|
||||
Models = require('../../server/models');
|
||||
when = require('when');
|
||||
|
||||
describe('User Model', function () {
|
||||
|
||||
describe('User Model', function run() {
|
||||
var UserModel = Models.User;
|
||||
|
||||
beforeEach(function (done) {
|
||||
helpers.resetData().then(function () {
|
||||
return when(helpers.insertDefaultUser());
|
||||
}).then(function () {
|
||||
before(function (done) {
|
||||
helpers.clearData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
it('can add first', function (done) {
|
||||
var userData = {
|
||||
password: 'testpass1',
|
||||
email_address: "test@test1.com"
|
||||
};
|
||||
afterEach(function (done) {
|
||||
helpers.clearData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
describe('Registration', function runRegistration() {
|
||||
beforeEach(function (done) {
|
||||
this.timeout(5000);
|
||||
helpers.initData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
it('can add first', function (done) {
|
||||
var userData = {
|
||||
password: 'testpass1',
|
||||
email_address: "test@test1.com"
|
||||
};
|
||||
|
||||
helpers.resetData().then(function () {
|
||||
UserModel.add(userData).then(function (createdUser) {
|
||||
should.exist(createdUser);
|
||||
createdUser.has('uuid').should.equal(true);
|
||||
@ -36,122 +46,139 @@ describe('User Model', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('can\'t add second', function (done) {
|
||||
var userData = {
|
||||
password: 'testpass3',
|
||||
email_address: "test3@test1.com"
|
||||
};
|
||||
describe('Basic Operations', function () {
|
||||
|
||||
return UserModel.add(userData).then(done, function (failure) {
|
||||
failure.message.should.eql('A user is already registered. Only one user for now!');
|
||||
done();
|
||||
}).then(null, done);
|
||||
});
|
||||
beforeEach(function (done) {
|
||||
this.timeout(5000);
|
||||
helpers.initData()
|
||||
.then(function () {
|
||||
return when(helpers.insertDefaultUser());
|
||||
})
|
||||
.then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
it('can browse', function (done) {
|
||||
it('can\'t add second', function (done) {
|
||||
var userData = {
|
||||
password: 'testpass3',
|
||||
email_address: "test3@test1.com"
|
||||
};
|
||||
|
||||
UserModel.browse().then(function (results) {
|
||||
should.exist(results);
|
||||
|
||||
results.length.should.be.above(0);
|
||||
|
||||
done();
|
||||
|
||||
}).then(null, done);
|
||||
});
|
||||
|
||||
it('can read', function (done) {
|
||||
var firstUser;
|
||||
|
||||
UserModel.browse().then(function (results) {
|
||||
|
||||
should.exist(results);
|
||||
|
||||
results.length.should.be.above(0);
|
||||
|
||||
firstUser = results.models[0];
|
||||
|
||||
return UserModel.read({email_address: firstUser.attributes.email_address});
|
||||
|
||||
}).then(function (found) {
|
||||
|
||||
should.exist(found);
|
||||
|
||||
found.attributes.full_name.should.equal(firstUser.attributes.full_name);
|
||||
|
||||
done();
|
||||
|
||||
}).then(null, done);
|
||||
|
||||
});
|
||||
|
||||
it('can edit', function (done) {
|
||||
var firstUser;
|
||||
|
||||
UserModel.browse().then(function (results) {
|
||||
|
||||
should.exist(results);
|
||||
|
||||
results.length.should.be.above(0);
|
||||
|
||||
firstUser = results.models[0];
|
||||
|
||||
return UserModel.edit({id: firstUser.id, url: "some.newurl.com"});
|
||||
|
||||
}).then(function (edited) {
|
||||
|
||||
should.exist(edited);
|
||||
|
||||
edited.attributes.url.should.equal('some.newurl.com');
|
||||
|
||||
done();
|
||||
|
||||
}).then(null, done);
|
||||
});
|
||||
|
||||
it("can get effective permissions", function (done) {
|
||||
UserModel.effectivePermissions(1).then(function (effectivePermissions) {
|
||||
should.exist(effectivePermissions);
|
||||
|
||||
effectivePermissions.length.should.be.above(0);
|
||||
|
||||
done();
|
||||
}).then(null, done);
|
||||
});
|
||||
|
||||
it('can delete', function (done) {
|
||||
var firstUserId;
|
||||
|
||||
UserModel.browse().then(function (results) {
|
||||
|
||||
should.exist(results);
|
||||
|
||||
results.length.should.be.above(0);
|
||||
|
||||
firstUserId = results.models[0].id;
|
||||
|
||||
return UserModel.destroy(firstUserId);
|
||||
|
||||
}).then(function () {
|
||||
|
||||
return UserModel.browse();
|
||||
|
||||
}).then(function (newResults) {
|
||||
var ids, hasDeletedId;
|
||||
|
||||
if (newResults.length < 1) {
|
||||
// Bug out if we only had one user and deleted it.
|
||||
return done();
|
||||
}
|
||||
|
||||
ids = _.pluck(newResults.models, "id");
|
||||
hasDeletedId = _.any(ids, function (id) {
|
||||
return id === firstUserId;
|
||||
return helpers.insertDefaultUser().then(function () {
|
||||
UserModel.add(userData).then(done, function (failure) {
|
||||
failure.message.should.eql('A user is already registered. Only one user for now!');
|
||||
done();
|
||||
}).then(null, done);
|
||||
});
|
||||
});
|
||||
|
||||
hasDeletedId.should.equal(false);
|
||||
done();
|
||||
it('can browse', function (done) {
|
||||
|
||||
}).then(null, done);
|
||||
UserModel.browse().then(function (results) {
|
||||
should.exist(results);
|
||||
|
||||
results.length.should.be.above(0);
|
||||
|
||||
done();
|
||||
|
||||
}).then(null, done);
|
||||
});
|
||||
|
||||
it('can read', function (done) {
|
||||
var firstUser;
|
||||
|
||||
UserModel.browse().then(function (results) {
|
||||
|
||||
should.exist(results);
|
||||
|
||||
results.length.should.be.above(0);
|
||||
|
||||
firstUser = results.models[0];
|
||||
|
||||
return UserModel.read({email_address: firstUser.attributes.email_address});
|
||||
|
||||
}).then(function (found) {
|
||||
|
||||
should.exist(found);
|
||||
|
||||
found.attributes.full_name.should.equal(firstUser.attributes.full_name);
|
||||
|
||||
done();
|
||||
|
||||
}).then(null, done);
|
||||
|
||||
});
|
||||
|
||||
it('can edit', function (done) {
|
||||
var firstUser;
|
||||
|
||||
UserModel.browse().then(function (results) {
|
||||
|
||||
should.exist(results);
|
||||
|
||||
results.length.should.be.above(0);
|
||||
|
||||
firstUser = results.models[0];
|
||||
|
||||
return UserModel.edit({id: firstUser.id, url: "some.newurl.com"});
|
||||
|
||||
}).then(function (edited) {
|
||||
|
||||
should.exist(edited);
|
||||
|
||||
edited.attributes.url.should.equal('some.newurl.com');
|
||||
|
||||
done();
|
||||
|
||||
}).then(null, done);
|
||||
});
|
||||
|
||||
it("can get effective permissions", function (done) {
|
||||
UserModel.effectivePermissions(1).then(function (effectivePermissions) {
|
||||
should.exist(effectivePermissions);
|
||||
|
||||
effectivePermissions.length.should.be.above(0);
|
||||
|
||||
done();
|
||||
}).then(null, done);
|
||||
});
|
||||
|
||||
it('can delete', function (done) {
|
||||
var firstUserId;
|
||||
|
||||
UserModel.browse().then(function (results) {
|
||||
|
||||
should.exist(results);
|
||||
|
||||
results.length.should.be.above(0);
|
||||
|
||||
firstUserId = results.models[0].id;
|
||||
|
||||
return UserModel.destroy(firstUserId);
|
||||
|
||||
}).then(function () {
|
||||
|
||||
return UserModel.browse();
|
||||
|
||||
}).then(function (newResults) {
|
||||
var ids, hasDeletedId;
|
||||
|
||||
if (newResults.length < 1) {
|
||||
// Bug out if we only had one user and deleted it.
|
||||
return done();
|
||||
}
|
||||
|
||||
ids = _.pluck(newResults.models, "id");
|
||||
hasDeletedId = _.any(ids, function (id) {
|
||||
return id === firstUserId;
|
||||
});
|
||||
|
||||
hasDeletedId.should.equal(false);
|
||||
done();
|
||||
|
||||
}).then(null, done);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@ -248,7 +248,8 @@ describe('Core Helpers', function () {
|
||||
helpers.loadCoreHelpers(ghost).then(function () {
|
||||
rendered = handlebars.helpers.pagination.call({pagination: {page: 1, prev: undefined, next: undefined, limit: 15, total: 8, pages: 1}});
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal('\n<nav id="pagination" role="pagination">\n \n <div class="page-number">Page 1<span class="extended"> of 1</span></div>\n \n</nav>');
|
||||
// strip out carriage returns and compare.
|
||||
rendered.string.replace(/\r/g, '').should.equal('\n<nav id="pagination" role="pagination">\n \n <div class="page-number">Page 1<span class="extended"> of 1</span></div>\n \n</nav>');
|
||||
done();
|
||||
}).then(null, done);
|
||||
});
|
||||
@ -258,7 +259,8 @@ describe('Core Helpers', function () {
|
||||
helpers.loadCoreHelpers(ghost).then(function () {
|
||||
rendered = handlebars.helpers.pagination.call({pagination: {page: 1, prev: undefined, next: 2, limit: 15, total: 8, pages: 3}});
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal('\n<nav id="pagination" role="pagination">\n \n <div class="previous-page"><a href="/page/2/">Older Posts →</a></div>\n \n <div class="page-number">Page 1<span class="extended"> of 3</span></div>\n \n</nav>');
|
||||
// strip out carriage returns and compare.
|
||||
rendered.string.replace(/\r/g, '').should.equal('\n<nav id="pagination" role="pagination">\n \n <div class="previous-page"><a href="/page/2/">Older Posts →</a></div>\n \n <div class="page-number">Page 1<span class="extended"> of 3</span></div>\n \n</nav>');
|
||||
done();
|
||||
}).then(null, done);
|
||||
});
|
||||
@ -268,7 +270,8 @@ describe('Core Helpers', function () {
|
||||
helpers.loadCoreHelpers(ghost).then(function () {
|
||||
rendered = handlebars.helpers.pagination.call({pagination: {page: 2, prev: 1, next: 3, limit: 15, total: 8, pages: 3}});
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal('\n<nav id="pagination" role="pagination">\n \n <div class="previous-page"><a href="/page/3/">Older Posts →</a></div>\n \n <div class="page-number">Page 2<span class="extended"> of 3</span></div>\n \n <div class="next-page"><a href="/page/1/">← Newer Posts</a></div>\n \n</nav>');
|
||||
// strip out carriage returns and compare.
|
||||
rendered.string.replace(/\r/g, '').should.equal('\n<nav id="pagination" role="pagination">\n \n <div class="previous-page"><a href="/page/3/">Older Posts →</a></div>\n \n <div class="page-number">Page 2<span class="extended"> of 3</span></div>\n \n <div class="next-page"><a href="/page/1/">← Newer Posts</a></div>\n \n</nav>');
|
||||
done();
|
||||
}).then(null, done);
|
||||
});
|
||||
@ -278,7 +281,8 @@ describe('Core Helpers', function () {
|
||||
helpers.loadCoreHelpers(ghost).then(function () {
|
||||
rendered = handlebars.helpers.pagination.call({pagination: {page: 3, prev: 2, next: undefined, limit: 15, total: 8, pages: 3}});
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal('\n<nav id="pagination" role="pagination">\n \n <div class="page-number">Page 3<span class="extended"> of 3</span></div>\n \n <div class="next-page"><a href="/page/2/">← Newer Posts</a></div>\n \n</nav>');
|
||||
// strip out carriage returns and compare.
|
||||
rendered.string.replace(/\r/g, '').should.equal('\n<nav id="pagination" role="pagination">\n \n <div class="page-number">Page 3<span class="extended"> of 3</span></div>\n \n <div class="next-page"><a href="/page/2/">← Newer Posts</a></div>\n \n</nav>');
|
||||
done();
|
||||
}).then(null, done);
|
||||
});
|
||||
|
@ -42,11 +42,9 @@ sampleUserRole = function (i) {
|
||||
};
|
||||
|
||||
helpers = {
|
||||
resetData: function () {
|
||||
|
||||
return this.clearData().then(function () {
|
||||
return migration.init();
|
||||
});
|
||||
initData: function (done) {
|
||||
return migration.init();
|
||||
},
|
||||
|
||||
clearData: function () {
|
||||
@ -54,7 +52,6 @@ helpers = {
|
||||
return migration.migrateDownFromVersion(migration.currentVersion);
|
||||
},
|
||||
|
||||
|
||||
insertMorePosts: function () {
|
||||
var lang, status, posts, promises = [], i, j;
|
||||
for (i = 0; i < 2; i += 1) {
|
||||
@ -69,6 +66,7 @@ helpers = {
|
||||
}
|
||||
return when.all(promises);
|
||||
},
|
||||
|
||||
insertDefaultUser: function () {
|
||||
|
||||
var users = [],
|
||||
@ -82,6 +80,7 @@ helpers = {
|
||||
|
||||
return when.all(u_promises);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = helpers;
|
@ -13,12 +13,27 @@ var _ = require("underscore"),
|
||||
|
||||
describe('permissions', function () {
|
||||
|
||||
before(function (done) {
|
||||
helpers.clearData()
|
||||
.then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
beforeEach(function (done) {
|
||||
helpers.resetData().then(function () {
|
||||
return helpers.insertDefaultUser();
|
||||
}).then(function () {
|
||||
done();
|
||||
}, done);
|
||||
this.timeout(5000);
|
||||
helpers.initData()
|
||||
.then(helpers.insertDefaultUser)
|
||||
.then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
helpers.clearData()
|
||||
.then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
var testPerms = [
|
||||
|
@ -12,7 +12,20 @@ var _ = require("underscore"),
|
||||
describe('Plugins', function () {
|
||||
|
||||
before(function (done) {
|
||||
helpers.resetData().then(function () {
|
||||
helpers.clearData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
beforeEach(function (done) {
|
||||
this.timeout(5000);
|
||||
helpers.initData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
helpers.clearData().then(function () {
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user