0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Test file cleanup on accoutn of OCD

This commit is contained in:
Hannah Wolfe 2013-11-11 10:37:09 +00:00
parent 9dd15edab7
commit b0c61720d9
11 changed files with 179 additions and 177 deletions

View file

@ -19,7 +19,7 @@ describe('Post API', function () {
});
beforeEach(function (done) {
testUtils.initData()
testUtils.initData()
.then(function () {
return testUtils.insertDefaultFixtures();
})
@ -30,9 +30,9 @@ describe('Post API', function () {
var pattern_meta = /<meta.*?name="csrf-param".*?content="(.*?)".*?>/i;
pattern_meta.should.exist;
csrfToken = body.match(pattern_meta)[1];
setTimeout((function() {
request.post({uri:testUtils.API.getSigninURL(),
headers: {'X-CSRF-Token': csrfToken}}, function (error, response, body) {
setTimeout((function () {
request.post({uri: testUtils.API.getSigninURL(),
headers: {'X-CSRF-Token': csrfToken}}, function (error, response, body) {
response.should.have.status(200);
done();
}).form({email: user.email, password: user.password});
@ -77,11 +77,11 @@ describe('Post API', function () {
var newTitle = 'My Post',
changedTitle = 'My Post changed',
publishedState = 'published',
newPost = {status:'draft', title:newTitle, markdown:'my post'};
newPost = {status: 'draft', title: newTitle, markdown: 'my post'};
request.post({uri: testUtils.API.getApiURL('posts/'),
headers: {'X-CSRF-Token': csrfToken},
json: newPost}, function (error, response, draftPost) {
headers: {'X-CSRF-Token': csrfToken},
json: newPost}, function (error, response, draftPost) {
response.should.have.status(200);
//TODO: do drafts really need a x-cache-invalidate header
response.should.be.json;
@ -90,8 +90,8 @@ describe('Post API', function () {
draftPost.status = publishedState;
testUtils.API.checkResponse(draftPost, 'post');
request.put({uri: testUtils.API.getApiURL('posts/' + draftPost.id + '/'),
headers: {'X-CSRF-Token': csrfToken},
json: draftPost}, function (error, response, publishedPost) {
headers: {'X-CSRF-Token': csrfToken},
json: draftPost}, function (error, response, publishedPost) {
response.should.have.status(200);
response.headers['x-cache-invalidate'].should.eql('/, /page/*, /rss/, /rss/*, /' + publishedPost.slug + '/');
response.should.be.json;
@ -100,8 +100,8 @@ describe('Post API', function () {
publishedPost.status.should.eql(publishedState);
testUtils.API.checkResponse(publishedPost, 'post');
request.put({uri: testUtils.API.getApiURL('posts/' + publishedPost.id + '/'),
headers: {'X-CSRF-Token': csrfToken},
json: publishedPost}, function (error, response, updatedPost) {
headers: {'X-CSRF-Token': csrfToken},
json: publishedPost}, function (error, response, updatedPost) {
response.should.have.status(200);
response.headers['x-cache-invalidate'].should.eql('/, /page/*, /rss/, /rss/*, /' + updatedPost.slug + '/');
response.should.be.json;
@ -116,8 +116,8 @@ describe('Post API', function () {
it('can delete a post', function (done) {
var deletePostId = 1;
request.del({uri: testUtils.API.getApiURL('posts/' + deletePostId +'/'),
headers: {'X-CSRF-Token': csrfToken}}, function (error, response, body) {
request.del({uri: testUtils.API.getApiURL('posts/' + deletePostId + '/'),
headers: {'X-CSRF-Token': csrfToken}}, function (error, response, body) {
response.should.have.status(200);
response.should.be.json;
var jsonResponse = JSON.parse(body);
@ -131,7 +131,7 @@ describe('Post API', function () {
it('can\'t delete a non existent post', function (done) {
request.del({uri: testUtils.API.getApiURL('posts/99/'),
headers: {'X-CSRF-Token': csrfToken}}, function (error, response, body) {
headers: {'X-CSRF-Token': csrfToken}}, function (error, response, body) {
response.should.have.status(404);
should.not.exist(response.headers['x-cache-invalidate']);
response.should.be.json;
@ -148,8 +148,8 @@ describe('Post API', function () {
newPost = {status: publishedState, title: newTitle, markdown: 'my post'};
request.post({uri: testUtils.API.getApiURL('posts/'),
headers: {'X-CSRF-Token': csrfToken},
json: newPost}, function (error, response, draftPost) {
headers: {'X-CSRF-Token': csrfToken},
json: newPost}, function (error, response, draftPost) {
response.should.have.status(200);
//TODO: do drafts really need a x-cache-invalidate header
response.should.be.json;
@ -158,7 +158,7 @@ describe('Post API', function () {
draftPost.status = publishedState;
testUtils.API.checkResponse(draftPost, 'post');
request.del({uri: testUtils.API.getApiURL('posts/' + draftPost.id + '/'),
headers: {'X-CSRF-Token': csrfToken}}, function (error, response, body) {
headers: {'X-CSRF-Token': csrfToken}}, function (error, response, body) {
response.should.have.status(200);
//TODO: do drafts really need a x-cache-invalidate header
response.should.be.json;
@ -177,7 +177,7 @@ describe('Post API', function () {
should.not.exist(response.headers['x-cache-invalidate']);
response.should.be.json;
var jsonResponse = JSON.parse(body);
jsonResponse.should.exist;
jsonResponse.should.exist;
testUtils.API.checkResponseValue(jsonResponse, ['error']);
done();
});
@ -191,8 +191,8 @@ describe('Post API', function () {
jsonResponse.title = changedValue;
request.put({uri: testUtils.API.getApiURL('posts/1/'),
headers: {'X-CSRF-Token': csrfToken},
json: jsonResponse}, function (error, response, putBody) {
headers: {'X-CSRF-Token': csrfToken},
json: jsonResponse}, function (error, response, putBody) {
response.should.have.status(200);
response.headers['x-cache-invalidate'].should.eql('/, /page/*, /rss/, /rss/*, /' + putBody.slug + '/');
response.should.be.json;
@ -213,8 +213,8 @@ describe('Post API', function () {
jsonResponse.testvalue = changedValue;
jsonResponse.id = 99;
request.put({uri: testUtils.API.getApiURL('posts/99/'),
headers: {'X-CSRF-Token': csrfToken},
json: jsonResponse}, function (error, response, putBody) {
headers: {'X-CSRF-Token': csrfToken},
json: jsonResponse}, function (error, response, putBody) {
response.should.have.status(404);
should.not.exist(response.headers['x-cache-invalidate']);
response.should.be.json;
@ -224,4 +224,4 @@ describe('Post API', function () {
});
});
});
});

View file

@ -30,9 +30,9 @@ describe('Settings API', function () {
var pattern_meta = /<meta.*?name="csrf-param".*?content="(.*?)".*?>/i;
pattern_meta.should.exist;
csrfToken = body.match(pattern_meta)[1];
setTimeout((function() {
request.post({uri:testUtils.API.getSigninURL(),
headers: {'X-CSRF-Token': csrfToken}}, function (error, response, body) {
setTimeout((function () {
request.post({uri: testUtils.API.getSigninURL(),
headers: {'X-CSRF-Token': csrfToken}}, function (error, response, body) {
response.should.have.status(200);
done();
}).form({email: user.email, password: user.password});

View file

@ -30,8 +30,8 @@ describe('Tag API', function () {
var pattern_meta = /<meta.*?name="csrf-param".*?content="(.*?)".*?>/i;
pattern_meta.should.exist;
csrfToken = body.match(pattern_meta)[1];
setTimeout((function() {
request.post({uri:testUtils.API.getSigninURL(),
setTimeout((function () {
request.post({uri: testUtils.API.getSigninURL(),
headers: {'X-CSRF-Token': csrfToken}}, function (error, response, body) {
response.should.have.status(200);
done();

View file

@ -30,8 +30,8 @@ describe('User API', function () {
var pattern_meta = /<meta.*?name="csrf-param".*?content="(.*?)".*?>/i;
pattern_meta.should.exist;
csrfToken = body.match(pattern_meta)[1];
setTimeout((function() {
request.post({uri:testUtils.API.getSigninURL(),
setTimeout((function () {
request.post({uri: testUtils.API.getSigninURL(),
headers: {'X-CSRF-Token': csrfToken}}, function (error, response, body) {
response.should.have.status(200);
done();

View file

@ -7,22 +7,23 @@ var fs = require('fs-extra'),
// Stuff we are testing
admin = require('../../server/controllers/admin');
describe('Admin Controller', function() {
describe('uploader', function() {
describe('Admin Controller', function () {
describe('uploader', function () {
var req, res, storage;
beforeEach(function() {
beforeEach(function () {
req = {
files: {
uploadimage: {
path: "/tmp/TMPFILEID"
}
files: {
uploadimage: {
path: "/tmp/TMPFILEID"
}
};
}
};
res = {
send: function(){}
send: function () {
}
};
storage = sinon.stub();
@ -34,8 +35,8 @@ describe('Admin Controller', function() {
admin.get_storage.restore();
});
describe('can not upload invalid file', function() {
it('should return 415 for invalid file type', function() {
describe('can not upload invalid file', function () {
it('should return 415 for invalid file type', function () {
res.send = sinon.stub();
req.files.uploadimage.name = 'INVALID.FILE';
req.files.uploadimage.type = 'application/octet-stream'
@ -46,8 +47,8 @@ describe('Admin Controller', function() {
});
});
describe('can not upload file with valid extension but invalid type', function() {
it('should return 415 for invalid file type', function() {
describe('can not upload file with valid extension but invalid type', function () {
it('should return 415 for invalid file type', function () {
res.send = sinon.stub();
req.files.uploadimage.name = 'INVALID.jpg';
req.files.uploadimage.type = 'application/octet-stream'
@ -58,20 +59,20 @@ describe('Admin Controller', function() {
});
});
describe('valid file', function() {
describe('valid file', function () {
beforeEach(function() {
beforeEach(function () {
req.files.uploadimage.name = 'IMAGE.jpg';
req.files.uploadimage.type = 'image/jpeg';
sinon.stub(fs, 'unlink').yields();
});
afterEach(function() {
afterEach(function () {
fs.unlink.restore();
});
it('can upload jpg', function(done) {
sinon.stub(res, 'send', function(data) {
it('can upload jpg', function (done) {
sinon.stub(res, 'send', function (data) {
data.should.not.equal(415);
return done();
});
@ -79,9 +80,9 @@ describe('Admin Controller', function() {
admin.uploader(req, res);
});
it('cannot upload jpg with incorrect extension', function(done) {
it('cannot upload jpg with incorrect extension', function (done) {
req.files.uploadimage.name = 'IMAGE.xjpg';
sinon.stub(res, 'send', function(data) {
sinon.stub(res, 'send', function (data) {
data.should.equal(415);
return done();
});
@ -89,10 +90,10 @@ describe('Admin Controller', function() {
admin.uploader(req, res);
});
it('can upload png', function(done) {
it('can upload png', function (done) {
req.files.uploadimage.name = 'IMAGE.png';
req.files.uploadimage.type = 'image/png';
sinon.stub(res, 'send', function(data) {
sinon.stub(res, 'send', function (data) {
data.should.not.equal(415);
return done();
});
@ -100,10 +101,10 @@ describe('Admin Controller', function() {
admin.uploader(req, res);
});
it('can upload gif', function(done) {
it('can upload gif', function (done) {
req.files.uploadimage.name = 'IMAGE.gif';
req.files.uploadimage.type = 'image/gif';
sinon.stub(res, 'send', function(data) {
sinon.stub(res, 'send', function (data) {
data.should.not.equal(415);
return done();
});
@ -111,8 +112,8 @@ describe('Admin Controller', function() {
admin.uploader(req, res);
});
it('should not leave temporary file when uploading', function(done) {
sinon.stub(res, 'send', function(data) {
it('should not leave temporary file when uploading', function (done) {
sinon.stub(res, 'send', function (data) {
fs.unlink.calledOnce.should.be.true;
fs.unlink.args[0][0].should.equal('/tmp/TMPFILEID');
return done();
@ -121,8 +122,8 @@ describe('Admin Controller', function() {
admin.uploader(req, res);
});
it('should send correct url', function(done) {
sinon.stub(res, 'send', function(data) {
it('should send correct url', function (done) {
sinon.stub(res, 'send', function (data) {
data.should.equal('URL');
return done();
});
@ -131,5 +132,4 @@ describe('Admin Controller', function() {
});
});
});
});
});

View file

@ -38,11 +38,11 @@ describe("Ghostdown showdown extensions", function () {
"![image and another,/ image](http://dsurl.stuff)",
"![](http://dsurl.stuff)"
/* No ref-style for now
"![][]",
"![image and another,/ image][stuff]",
"![][stuff]",
"![image and another,/ image][]"
*/
"![][]",
"![image and another,/ image][stuff]",
"![][stuff]",
"![image and another,/ image][]"
*/
]
.forEach(function (imageMarkup) {
var processedMarkup =
@ -60,9 +60,9 @@ describe("Ghostdown showdown extensions", function () {
"![image and another,/ image](http://dsurl.stuff)",
"![](http://dsurl.stuff)"
/* No ref-style for now
"![image and another,/ image][test]\n\n[test]: http://dsurl.stuff",
"![][test]\n\n[test]: http://dsurl.stuff"
*/
"![image and another,/ image][test]\n\n[test]: http://dsurl.stuff",
"![][test]\n\n[test]: http://dsurl.stuff"
*/
]
.forEach(function (imageMarkup) {
var processedMarkup =
@ -73,4 +73,4 @@ describe("Ghostdown showdown extensions", function () {
processedMarkup.should.match(/<img class="js-upload-target"/);
});
});
});
});

View file

@ -8,13 +8,14 @@
var testUtils = require('../utils'),
should = require('should'),
// Stuff we are testing
// Stuff we are testing
Showdown = require('showdown'),
github = require('../../shared/vendor/showdown/extensions/github'),
ghostdown = require('../../client/assets/vendor/showdown/extensions/ghostdown'),
converter = new Showdown.converter({extensions: [ghostdown, github]});
describe("Showdown client side converter", function () {
/*jslint regexp: true */
it("should replace showdown strike through with html", function () {
var testPhrase = {input: "~~foo_bar~~", output: /^<p><del>foo_bar<\/del><\/p>$/},
@ -224,29 +225,29 @@ describe("Showdown client side converter", function () {
});
/* No ref-style for now
it("should convert reference format image", function () {
var testPhrases = [
{
input: "![Google][1]\n\n[1]: http://dsurl.stuff/something.jpg",
output: /^<section.*?<img.*?src="http:\/\/dsurl.stuff\/something.jpg"\/>.*?<\/section>$/,
},
{
input: "![Google][1]\n\n[1]: http://dsurl.stuff/something.jpg \"some text\"",
output: /^<section.*?<img.*?src="http:\/\/dsurl.stuff\/something.jpg"\/>.*?<\/section>$/
},
{
input: "[http://www.google.co.uk]: http://www.google.co.uk\n\n![Hello][http://www.google.co.uk]",
output: /^<section.*?<img.*?src="http:\/\/www.google.co.uk"\/>.*?<\/section>$/
}
],
processedMarkup;
it("should convert reference format image", function () {
var testPhrases = [
{
input: "![Google][1]\n\n[1]: http://dsurl.stuff/something.jpg",
output: /^<section.*?<img.*?src="http:\/\/dsurl.stuff\/something.jpg"\/>.*?<\/section>$/,
},
{
input: "![Google][1]\n\n[1]: http://dsurl.stuff/something.jpg \"some text\"",
output: /^<section.*?<img.*?src="http:\/\/dsurl.stuff\/something.jpg"\/>.*?<\/section>$/
},
{
input: "[http://www.google.co.uk]: http://www.google.co.uk\n\n![Hello][http://www.google.co.uk]",
output: /^<section.*?<img.*?src="http:\/\/www.google.co.uk"\/>.*?<\/section>$/
}
],
processedMarkup;
testPhrases.forEach(function (testPhrase) {
processedMarkup = converter.makeHtml(testPhrase.input);
processedMarkup.should.match(testPhrase.output);
});
});
*/
testPhrases.forEach(function (testPhrase) {
processedMarkup = converter.makeHtml(testPhrase.input);
processedMarkup.should.match(testPhrase.output);
});
});
*/
it("should NOT auto-link URL in HTML", function () {
var testPhrases = [
@ -279,12 +280,12 @@ describe("Showdown client side converter", function () {
});
});
it("should NOT escape underscore inside of code/pre blocks", function() {
it("should NOT escape underscore inside of code/pre blocks", function () {
var testPhrase = {
input: "```\n_____\n```",
output: /^<pre><code>_____ \n<\/code><\/pre>$/
} ,
processedMarkup;
input: "```\n_____\n```",
output: /^<pre><code>_____ \n<\/code><\/pre>$/
},
processedMarkup;
processedMarkup = converter.makeHtml(testPhrase.input);
processedMarkup.should.match(testPhrase.output);
@ -351,7 +352,7 @@ describe("Showdown client side converter", function () {
it("should show placeholder for image markdown", function () {
var testPhrases = [
{input: "![image and another,/ image](http://dsurl stuff)", output: /^<section.*?section>\n*$/},
{input: "![image and another,/ image](http://dsurl stuff)", output: /^<section.*?section>\n*$/},
{input: "![image and another,/ image]", output: /^<section.*?section>\n*$/},
{input: "![]()", output: /^<section.*?section>\n*$/},
{input: "![]", output: /^<section.*?section>\n*$/}
@ -367,15 +368,15 @@ describe("Showdown client side converter", function () {
it("should have placeholder with image ONLY if image URL is present and valid", function () {
var testPhrases = [
{
input: "![image stuff](http://dsurl.stuff/something.jpg)",
input: "![image stuff](http://dsurl.stuff/something.jpg)",
output: /^<section.*?<img class="js-upload-target.*?<\/section>$/
},
{input: "![]", output: /<img class="js-upload-target"/, not: true},
{input: "![]", output: /^<section.*?<\/section>$/},
{input: "![]()", output: /<img class="js-upload-target"/, not: true},
{input: "![]()", output: /^<section.*?<\/section>$/},
{input: "![]", output: /<img class="js-upload-target"/, not: true},
{input: "![]", output: /^<section.*?<\/section>$/}
{input: "![]", output: /<img class="js-upload-target"/, not: true},
{input: "![]", output: /^<section.*?<\/section>$/}
],
processedMarkup;
@ -390,29 +391,29 @@ describe("Showdown client side converter", function () {
});
/* No ref-style for now
it("should have placeholder with image if image reference is present", function () {
var testPhrases = [
{
input: "![alt][id]\n\n[id]: http://dsurl.stuff/something.jpg",
output: /^<section.*?<img class="js-upload-target.*?<\/section>$/
},
{input: "![][]", output: /^<section.*?<\/section>$/},
{input: "![][]", output: /<img class="js-upload-target"/, not: true},
{input: "![][id]", output: /^<section.*?<\/section>$/},
{input: "![][id]", output: /<img class="js-upload-target"/, not: true}
],
processedMarkup;
it("should have placeholder with image if image reference is present", function () {
var testPhrases = [
{
input: "![alt][id]\n\n[id]: http://dsurl.stuff/something.jpg",
output: /^<section.*?<img class="js-upload-target.*?<\/section>$/
},
{input: "![][]", output: /^<section.*?<\/section>$/},
{input: "![][]", output: /<img class="js-upload-target"/, not: true},
{input: "![][id]", output: /^<section.*?<\/section>$/},
{input: "![][id]", output: /<img class="js-upload-target"/, not: true}
],
processedMarkup;
testPhrases.forEach(function (testPhrase) {
processedMarkup = converter.makeHtml(testPhrase.input);
if (testPhrase.not) {
processedMarkup.should.not.match(testPhrase.output);
} else {
processedMarkup.should.match(testPhrase.output);
}
});
});
*/
testPhrases.forEach(function (testPhrase) {
processedMarkup = converter.makeHtml(testPhrase.input);
if (testPhrase.not) {
processedMarkup.should.not.match(testPhrase.output);
} else {
processedMarkup.should.match(testPhrase.output);
}
});
});
*/
it("should correctly output link and image markdown without autolinks", function () {
var testPhrases = [
@ -437,7 +438,7 @@ describe("Showdown client side converter", function () {
output: /^<section.*?((?!<a href=\'http:\/\/google.co.uk\/kitten.jpg\').)*<\/section>$/
},
{
input: "![image stuff](http://dsurl.stuff/something)",
input: "![image stuff](http://dsurl.stuff/something)",
output: /^<section.*?((?!<a href=\'http:\/\/dsurl.stuff\/something\').)*<\/section>$/
}
],

View file

@ -1,4 +1,4 @@
/*globals describe, before, beforeEach, it*/
/*globals describe, before, beforeEach, afterEach, it*/
var testUtils = require('../utils'),
should = require('should'),
sinon = require('sinon'),

View file

@ -81,7 +81,7 @@ describe("Mail", function () {
it('should setup SMTP transport on initialization', function (done) {
fakeConfig.mail = SMTP;
ghost.mail.init(ghost).then(function(){
ghost.mail.init(ghost).then(function () {
ghost.mail.should.have.property('transport');
ghost.mail.transport.transportType.should.eql('SMTP');
ghost.mail.transport.sendMail.should.be.a.function;
@ -91,7 +91,7 @@ describe("Mail", function () {
it('should setup sendmail transport on initialization', function (done) {
fakeConfig.mail = SENDMAIL;
ghost.mail.init(ghost).then(function(){
ghost.mail.init(ghost).then(function () {
ghost.mail.should.have.property('transport');
ghost.mail.transport.transportType.should.eql('SENDMAIL');
ghost.mail.transport.sendMail.should.be.a.function;
@ -101,7 +101,7 @@ describe("Mail", function () {
it('should fallback to sendmail if no config set', function (done) {
fakeConfig.mail = null;
ghost.mail.init(ghost).then(function(){
ghost.mail.init(ghost).then(function () {
ghost.mail.should.have.property('transport');
ghost.mail.transport.transportType.should.eql('SENDMAIL');
ghost.mail.transport.options.path.should.eql(fakeSendmail);
@ -111,7 +111,7 @@ describe("Mail", function () {
it('should fallback to sendmail if config is empty', function (done) {
fakeConfig.mail = {};
ghost.mail.init(ghost).then(function(){
ghost.mail.init(ghost).then(function () {
ghost.mail.should.have.property('transport');
ghost.mail.transport.transportType.should.eql('SENDMAIL');
ghost.mail.transport.options.path.should.eql(fakeSendmail);
@ -123,7 +123,7 @@ describe("Mail", function () {
fakeConfig.mail = {};
ghost.mail.detectSendmail.restore();
sandbox.stub(ghost.mail, "detectSendmail", when.reject);
ghost.mail.init(ghost).then(function(){
ghost.mail.init(ghost).then(function () {
should.not.exist(ghost.mail.transport);
done();
}).then(null, done);
@ -133,8 +133,10 @@ describe("Mail", function () {
fakeConfig.mail = {};
ghost.mail.detectSendmail.restore();
ghost.mail.isWindows.restore();
sandbox.stub(ghost.mail, 'isWindows', function(){ return true });
ghost.mail.init(ghost).then(function(){
sandbox.stub(ghost.mail, 'isWindows', function () {
return true;
});
ghost.mail.init(ghost).then(function () {
should.not.exist(ghost.mail.transport);
done();
}).then(null, done);
@ -143,8 +145,8 @@ describe("Mail", function () {
it('should fail to send messages when no transport is set', function (done) {
ghost.mail.detectSendmail.restore();
sandbox.stub(ghost.mail, "detectSendmail", when.reject);
ghost.mail.init(ghost).then(function(){
ghost.mail.send().then(function(){
ghost.mail.init(ghost).then(function () {
ghost.mail.send().then(function () {
should.fail();
done();
}, function (err) {
@ -168,5 +170,4 @@ describe("Mail", function () {
done();
});
});
});

View file

@ -10,10 +10,10 @@ var assert = require('assert'),
describe('Middleware', function () {
describe('auth', function() {
describe('auth', function () {
var req, res, ghost = new Ghost();
beforeEach(function() {
beforeEach(function () {
req = {
session: {}
};
@ -25,7 +25,7 @@ describe('Middleware', function () {
ghost.notifications = [];
});
it('should redirect to signin path', function(done) {
it('should redirect to signin path', function (done) {
req.path = '';
@ -35,7 +35,7 @@ describe('Middleware', function () {
});
it('should redirect to signin path with redirect paramater stripped of /ghost/', function(done) {
var path ='test/path/party';
var path = 'test/path/party';
req.path = '/ghost/' + path;
@ -44,8 +44,8 @@ describe('Middleware', function () {
return done();
});
it('should only add one message to the notification array', function(done) {
var path ='test/path/party';
it('should only add one message to the notification array', function (done) {
var path = 'test/path/party';
req.path = '/ghost/' + path;
@ -60,10 +60,10 @@ describe('Middleware', function () {
return done();
});
it('should call next if session user exists', function(done) {
it('should call next if session user exists', function (done) {
req.session.user = {};
middleware.auth(req, res, function(a) {
middleware.auth(req, res, function (a) {
should.not.exist(a);
assert(res.redirect.calledOnce.should.be.false);
return done();
@ -71,10 +71,10 @@ describe('Middleware', function () {
});
});
describe('authAPI', function() {
describe('authAPI', function () {
var req, res;
beforeEach(function() {
beforeEach(function () {
req = {
session: {}
};
@ -85,16 +85,16 @@ describe('Middleware', function () {
};
});
it('should return a json 401 error response', function(done) {
it('should return a json 401 error response', function (done) {
middleware.authAPI(req, res, null);
assert(res.json.calledWith(401, { error: 'Please sign in' }));
return done();
});
it('should call next if a user exists in session', function(done) {
it('should call next if a user exists in session', function (done) {
req.session.user = {};
middleware.authAPI(req, res, function(a) {
middleware.authAPI(req, res, function (a) {
should.not.exist(a);
assert(res.redirect.calledOnce.should.be.false);
return done();
@ -102,10 +102,10 @@ describe('Middleware', function () {
});
});
describe('redirectToDashboard', function() {
describe('redirectToDashboard', function () {
var req, res;
beforeEach(function() {
beforeEach(function () {
req = {
session: {}
};
@ -115,7 +115,7 @@ describe('Middleware', function () {
};
});
it('should redirect to dashboard', function(done) {
it('should redirect to dashboard', function (done) {
req.session.user = {};
middleware.redirectToDashboard(req, res, null);
@ -123,8 +123,8 @@ describe('Middleware', function () {
return done();
});
it('should call next if no user in session', function(done) {
middleware.redirectToDashboard(req, res, function(a) {
it('should call next if no user in session', function (done) {
middleware.redirectToDashboard(req, res, function (a) {
should.not.exist(a);
assert(res.redirect.calledOnce.should.be.false);
return done();
@ -132,10 +132,10 @@ describe('Middleware', function () {
});
});
describe('cleanNotifications', function() {
describe('cleanNotifications', function () {
var ghost = new Ghost();
beforeEach(function() {
beforeEach(function () {
ghost.notifications = [
{
status: 'passive',
@ -152,10 +152,10 @@ describe('Middleware', function () {
];
});
it('should clean all passive messages', function(done) {
middleware.cleanNotifications(null, null, function() {
it('should clean all passive messages', function (done) {
middleware.cleanNotifications(null, null, function () {
assert.equal(ghost.notifications.length, 1);
var passiveMsgs = _.filter(ghost.notifications, function(notification) {
var passiveMsgs = _.filter(ghost.notifications, function (notification) {
return notification.status === 'passive';
});
assert.equal(passiveMsgs.length, 0);
@ -164,17 +164,17 @@ describe('Middleware', function () {
});
});
describe('disableCachedResult', function() {
describe('disableCachedResult', function () {
var res;
beforeEach(function() {
beforeEach(function () {
res = {
set: sinon.spy()
};
});
it('should set correct cache headers', function(done) {
middleware.disableCachedResult(null, res, function() {
it('should set correct cache headers', function (done) {
middleware.disableCachedResult(null, res, function () {
assert(res.set.calledWith({
'Cache-Control': 'no-cache, must-revalidate',
'Expires': 'Sat, 26 Jul 1997 05:00:00 GMT'
@ -184,13 +184,13 @@ describe('Middleware', function () {
});
});
describe('whenEnabled', function() {
describe('whenEnabled', function () {
var cbFn, ghost = new Ghost();
beforeEach(function() {
beforeEach(function () {
cbFn = sinon.spy();
ghost.server = {
enabled: function(setting) {
enabled: function (setting) {
if (setting === 'enabled') {
return true;
} else {
@ -200,10 +200,10 @@ describe('Middleware', function () {
};
});
it('should call function if setting is enabled', function(done) {
it('should call function if setting is enabled', function (done) {
var req = 1, res = 2, next = 3;
middleware.whenEnabled('enabled', function(a, b, c) {
middleware.whenEnabled('enabled', function (a, b, c) {
assert.equal(a, 1);
assert.equal(b, 2);
assert.equal(c, 3);
@ -211,8 +211,8 @@ describe('Middleware', function () {
})(req, res, next);
});
it('should call next() if setting is disabled', function(done) {
middleware.whenEnabled('rando', cbFn)(null, null, function(a) {
it('should call next() if setting is disabled', function (done) {
middleware.whenEnabled('rando', cbFn)(null, null, function (a) {
should.not.exist(a);
cbFn.calledOnce.should.be.false;
return done();
@ -269,14 +269,13 @@ describe('Middleware', function () {
it('should call express.static if valid file type', function (done) {
var ghostStub = {
paths: function() {
return {activeTheme: 'ACTIVETHEME'};
}
};
var req = {
url: 'myvalidfile.css'
};
paths: function () {
return {activeTheme: 'ACTIVETHEME'};
}
},
req = {
url: 'myvalidfile.css'
};
middleware.staticTheme(ghostStub)(req, null, function (req, res, next) {
middleware.forwardToExpressStatic.calledOnce.should.be.true;

View file

@ -28,6 +28,7 @@ function _ConvertPhrase(testPhrase) {
describe("Github showdown extensions", function () {
/*jslint regexp: true */
it("should export an array of methods for processing", function () {
github.should.be.a.function;