0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Unit Test fixes for MySQL

issue #858

- there is no guaranteed order to arrays, so sort before testing them
- tests run much faster, date comparisons fail
- settings tests are more explicit, otherwise they fail random validations
- dates must be inserted as date objects
This commit is contained in:
Hannah Wolfe 2013-09-27 12:52:31 +01:00
parent d544b4aebb
commit 5c10f6608c
5 changed files with 16 additions and 27 deletions

View file

@ -139,11 +139,11 @@ describe('Post Model', function () {
createdPost.has('html').should.equal(true);
createdPost.get('html').should.equal('<p>' + newPost.markdown + '</p>');
createdPost.get('slug').should.equal('test-title-1');
createdPost.get('created_at').should.be.below(new Date().getTime()).and.be.above(new Date(0).getTime());
createdPost.get('created_at').should.be.above(new Date(0).getTime());
createdPost.get('created_by').should.equal(1);
createdPost.get('author_id').should.equal(1);
createdPost.get('created_by').should.equal(createdPost.get('author_id'));
createdPost.get('updated_at').should.be.below(new Date().getTime()).and.be.above(new Date(0).getTime());
createdPost.get('updated_at').should.be.above(new Date(0).getTime());
createdPost.get('updated_by').should.equal(1);
should.equal(createdPost.get('published_at'), null);
should.equal(createdPost.get('published_by'), null);

View file

@ -76,13 +76,7 @@ describe('Settings Model', function () {
results.length.should.be.above(0);
firstSetting = results.models[1];
// The edit method has been modified to take an object of
// key/value pairs
firstSetting.set('value', 'new value');
return SettingsModel.edit(firstSetting);
return SettingsModel.edit({key: "description", value: "new value"});
}).then(function (edited) {
@ -92,7 +86,7 @@ describe('Settings Model', function () {
edited = edited[0];
edited.attributes.key.should.equal(firstSetting.attributes.key);
edited.attributes.key.should.equal('description');
edited.attributes.value.should.equal('new value');
done();
@ -111,13 +105,8 @@ describe('Settings Model', function () {
results.length.should.be.above(0);
model1 = results.models[1];
model2 = results.models[2];
// The edit method has been modified to take an object of
// key/value pairs
model1.set('value', 'new value1');
model2.set('value', 'new value2');
model1 = {key: "description", value: "another new value"};
model2 = {key: "title", value: "new title"};
return SettingsModel.edit([model1, model2]);
@ -129,13 +118,13 @@ describe('Settings Model', function () {
editedModel = edited[0];
editedModel.attributes.key.should.equal(model1.attributes.key);
editedModel.attributes.value.should.equal('new value1');
editedModel.attributes.key.should.equal(model1.key);
editedModel.attributes.value.should.equal(model1.value);
editedModel = edited[1];
editedModel.attributes.key.should.equal(model2.attributes.key);
editedModel.attributes.value.should.equal('new value2');
editedModel.attributes.key.should.equal(model2.key);
editedModel.attributes.value.should.equal(model2.value);
done();

View file

@ -130,7 +130,7 @@ describe('Tag Model', function () {
return postModel.save();
}).then(function (postModel) {
var tagNames = postModel.related('tags').models.map(function (t) { return t.attributes.name; });
tagNames.should.eql(seededTagNames);
tagNames.sort().should.eql(seededTagNames);
return TagModel.findAll();
}).then(function (tagsFromDB) {
@ -155,7 +155,7 @@ describe('Tag Model', function () {
return PostModel.read({id: postModel.id}, { withRelated: ['tags']});
}).then(function (reloadedPost) {
var tagNames = reloadedPost.related('tags').models.map(function (t) { return t.attributes.name; });
tagNames.should.eql(['tag1', 'tag3']);
tagNames.sort().should.eql(['tag1', 'tag3']);
done();
}).then(null, done);
@ -180,7 +180,7 @@ describe('Tag Model', function () {
}).then(function (reloadedPost) {
var tagModels = reloadedPost.related('tags').models,
tagNames = tagModels.map(function (t) { return t.attributes.name; });
tagNames.should.eql(['tag1', 'tag2', 'tag3']);
tagNames.sort().should.eql(['tag1', 'tag2', 'tag3']);
tagModels[2].id.should.eql(4); // make sure it hasn't just added a new tag with the same name
done();
@ -201,7 +201,7 @@ describe('Tag Model', function () {
return PostModel.read({id: postModel.id}, { withRelated: ['tags']});
}).then(function (reloadedPost) {
var tagNames = reloadedPost.related('tags').models.map(function (t) { return t.attributes.name; });
tagNames.should.eql(['tag1', 'tag2', 'tag3']);
tagNames.sort().should.eql(['tag1', 'tag2', 'tag3']);
done();
}).then(null, done);

View file

@ -94,7 +94,7 @@ describe('permissions', function () {
.then(function (actionsMap) {
should.exist(actionsMap);
actionsMap.edit.should.eql(['post', 'tag', 'user', 'page']);
actionsMap.edit.sort().should.eql(['post', 'tag', 'user', 'page'].sort());
actionsMap.should.equal(permissions.actionsMap);

View file

@ -37,7 +37,7 @@ sampleUser = function (i) {
email: "joe_" + i + "@bloggs.com",
password: "$2a$10$c5G9RS5.dXRt3UqvZ5wNgOLQLc7ZFc2DJo01du0oLT1YYOM67KJMe",
created_by: 1,
created_at: 1234567890
created_at: new Date()
};
};