mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Cleaning up the unit tests
This commit is contained in:
parent
35f7d8ac9b
commit
0a319e48c5
@ -1,4 +1,5 @@
|
||||
/*globals describe, beforeEach, afterEach, it*/
|
||||
/*jshint expr:true*/
|
||||
var fs = require('fs-extra'),
|
||||
should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
@ -8,6 +9,9 @@ var fs = require('fs-extra'),
|
||||
// Stuff we are testing
|
||||
admin = require('../../server/controllers/admin');
|
||||
|
||||
// To stop jshint complaining
|
||||
should.equal(true, true);
|
||||
|
||||
describe('Admin Controller', function () {
|
||||
describe('upload', function () {
|
||||
|
||||
@ -17,7 +21,7 @@ describe('Admin Controller', function () {
|
||||
req = {
|
||||
files: {
|
||||
uploadimage: {
|
||||
path: "/tmp/TMPFILEID"
|
||||
path: '/tmp/TMPFILEID'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*globals describe, beforeEach, afterEach, before, it*/
|
||||
var fs = require('fs'),
|
||||
path = require('path'),
|
||||
/*globals describe, beforeEach, afterEach, it*/
|
||||
/*jshint expr:true*/
|
||||
var path = require('path'),
|
||||
EventEmitter = require('events').EventEmitter,
|
||||
should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
@ -8,7 +8,6 @@ var fs = require('fs'),
|
||||
when = require('when'),
|
||||
helpers = require('../../server/helpers'),
|
||||
filters = require('../../server/filters'),
|
||||
api = require('../../server/api'),
|
||||
|
||||
// Stuff we are testing
|
||||
AppProxy = require('../../server/apps/proxy'),
|
||||
@ -169,7 +168,8 @@ describe('Apps', function () {
|
||||
appProxy.filters.register('superSecretFilter', 5, filterStub);
|
||||
}
|
||||
|
||||
registerFilterWithoutPermission.should.throw('The App "TestApp" attempted to perform an action or access a resource (filters.superSecretFilter) without permission.');
|
||||
registerFilterWithoutPermission.should.throw('The App "TestApp" attempted to perform an action or access' +
|
||||
' a resource (filters.superSecretFilter) without permission.');
|
||||
|
||||
registerSpy.called.should.equal(false);
|
||||
});
|
||||
@ -222,7 +222,8 @@ describe('Apps', function () {
|
||||
appProxy.filters.deregister('superSecretFilter', 5, filterStub);
|
||||
}
|
||||
|
||||
deregisterFilterWithoutPermission.should.throw('The App "TestApp" attempted to perform an action or access a resource (filters.superSecretFilter) without permission.');
|
||||
deregisterFilterWithoutPermission.should.throw('The App "TestApp" attempted to perform an action or ' +
|
||||
'access a resource (filters.superSecretFilter) without permission.');
|
||||
|
||||
registerSpy.called.should.equal(false);
|
||||
});
|
||||
@ -260,7 +261,8 @@ describe('Apps', function () {
|
||||
appProxy.helpers.register('otherHelper', sandbox.stub().returns('test result'));
|
||||
}
|
||||
|
||||
registerWithoutPermissions.should.throw('The App "TestApp" attempted to perform an action or access a resource (helpers.otherHelper) without permission.');
|
||||
registerWithoutPermissions.should.throw('The App "TestApp" attempted to perform an action or access a ' +
|
||||
'resource (helpers.otherHelper) without permission.');
|
||||
|
||||
registerSpy.called.should.equal(false);
|
||||
});
|
||||
@ -294,8 +296,6 @@ describe('Apps', function () {
|
||||
it('does not allow apps to require blacklisted modules at top level', function () {
|
||||
var appBox = new AppSandbox(),
|
||||
badAppPath = path.join(__dirname, '..', 'utils', 'fixtures', 'app', 'badtop.js'),
|
||||
BadApp,
|
||||
app,
|
||||
loadApp = function () {
|
||||
appBox.loadApp(badAppPath);
|
||||
};
|
||||
@ -327,7 +327,6 @@ describe('Apps', function () {
|
||||
var appBox = new AppSandbox(),
|
||||
badAppPath = path.join(__dirname, '..', 'utils', 'fixtures', 'app', 'badrequire.js'),
|
||||
BadApp,
|
||||
app,
|
||||
loadApp = function () {
|
||||
BadApp = appBox.loadApp(badAppPath);
|
||||
};
|
||||
@ -339,7 +338,6 @@ describe('Apps', function () {
|
||||
var appBox = new AppSandbox(),
|
||||
badAppPath = path.join(__dirname, '..', 'utils', 'fixtures', 'app', 'badoutside.js'),
|
||||
BadApp,
|
||||
app,
|
||||
loadApp = function () {
|
||||
BadApp = appBox.loadApp(badAppPath);
|
||||
};
|
||||
@ -382,6 +380,7 @@ describe('Apps', function () {
|
||||
});
|
||||
|
||||
describe('Permissions', function () {
|
||||
/*jshint quotmark:false*/
|
||||
var noGhostPackageJson = {
|
||||
"name": "myapp",
|
||||
"version": "0.0.1",
|
||||
@ -469,6 +468,7 @@ describe('Apps', function () {
|
||||
sandbox.stub(perms, "getPackageContents").returns(when.reject(new Error('package.json file is malformed')));
|
||||
|
||||
perms.read().then(function (readPerms) {
|
||||
/*jshint unused:false*/
|
||||
done(new Error('should not resolve'));
|
||||
}).catch(function (err) {
|
||||
err.message.should.equal('package.json file is malformed');
|
||||
|
13
core/test/unit/bootstrap_spec.js
vendored
13
core/test/unit/bootstrap_spec.js
vendored
@ -1,12 +1,12 @@
|
||||
/*globals describe, it, beforeEach, afterEach */
|
||||
|
||||
/*jshint expr:true*/
|
||||
var should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
_ = require('lodash'),
|
||||
rewire = require("rewire"),
|
||||
rewire = require('rewire'),
|
||||
|
||||
// Thing we are testing
|
||||
defaultConfig = require('../../../config.example')[process.env.NODE_ENV],
|
||||
@ -17,7 +17,7 @@ describe('Bootstrap', function () {
|
||||
var sandbox,
|
||||
rejectMessage = bootstrap.__get__('rejectMessage'),
|
||||
overrideConfig = function (newConfig) {
|
||||
bootstrap.__set__("readConfigFile", sandbox.stub().returns(
|
||||
bootstrap.__set__('readConfigFile', sandbox.stub().returns(
|
||||
_.extend({}, defaultConfig, newConfig)
|
||||
));
|
||||
},
|
||||
@ -37,7 +37,7 @@ describe('Bootstrap', function () {
|
||||
// the test infrastructure is setup so that there is always config present,
|
||||
// but we want to overwrite the test to actually load config.example.js, so that any local changes
|
||||
// don't break the tests
|
||||
bootstrap.__set__("configFile", path.join(config().paths.appRoot, 'config.example.js'));
|
||||
bootstrap.__set__('configFile', path.join(config().paths.appRoot, 'config.example.js'));
|
||||
|
||||
bootstrap().then(function (config) {
|
||||
config.url.should.equal(defaultConfig.url);
|
||||
@ -73,8 +73,8 @@ describe('Bootstrap', function () {
|
||||
deferred.resolve();
|
||||
|
||||
// ensure that the file creation is a stub, the tests shouldn't really create a file
|
||||
bootstrap.__set__("writeConfigFile", resolvedPromise);
|
||||
bootstrap.__set__("validateConfigEnvironment", resolvedPromise);
|
||||
bootstrap.__set__('writeConfigFile', resolvedPromise);
|
||||
bootstrap.__set__('validateConfigEnvironment', resolvedPromise);
|
||||
|
||||
bootstrap().then(function () {
|
||||
existsStub.calledOnce.should.be.true;
|
||||
@ -254,6 +254,7 @@ describe('Bootstrap', function () {
|
||||
overrideConfig({ server: false });
|
||||
|
||||
bootstrap().then(function (localConfig) {
|
||||
/*jshint unused:false*/
|
||||
done(expectedError);
|
||||
}).catch(function (err) {
|
||||
should.exist(err);
|
||||
|
@ -1,12 +1,11 @@
|
||||
/*globals describe, it, beforeEach, afterEach */
|
||||
|
||||
/*jshint expr:true*/
|
||||
var should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
_ = require('lodash'),
|
||||
rewire = require("rewire"),
|
||||
rewire = require('rewire'),
|
||||
|
||||
testUtils = require('../utils'),
|
||||
|
||||
@ -16,6 +15,9 @@ var should = require('should'),
|
||||
config = rewire('../../server/config'),
|
||||
configUpdate = config.__get__('updateConfig');
|
||||
|
||||
// To stop jshint complaining
|
||||
should.equal(true, true);
|
||||
|
||||
describe('Config', function () {
|
||||
|
||||
describe('Theme', function () {
|
||||
@ -221,8 +223,8 @@ describe('Config', function () {
|
||||
permalinks: {value: '/:year/:month/:day/:slug/'}
|
||||
},
|
||||
today = new Date(),
|
||||
dd = ("0" + today.getDate()).slice(-2),
|
||||
mm = ("0" + (today.getMonth() + 1)).slice(-2),
|
||||
dd = ('0' + today.getDate()).slice(-2),
|
||||
mm = ('0' + (today.getMonth() + 1)).slice(-2),
|
||||
yyyy = today.getFullYear(),
|
||||
postLink = '/' + yyyy + '/' + mm + '/' + dd + '/short-and-sweet/';
|
||||
|
||||
@ -267,6 +269,7 @@ describe('Config', function () {
|
||||
settingsStub = sandbox.stub(settings, 'read', function () {
|
||||
return when({ settings: [{value: '/:slug/'}] });
|
||||
}),
|
||||
/*jshint unused:false*/
|
||||
testData = testUtils.DataGenerator.Content.posts[2],
|
||||
postLink = '/short-and-sweet/';
|
||||
|
||||
@ -304,10 +307,11 @@ describe('Config', function () {
|
||||
settingsStub = sandbox.stub(settings, 'read', function () {
|
||||
return when({ settings: [{value: '/:year/:month/:day/:slug/'}] });
|
||||
}),
|
||||
/*jshint unused:false*/
|
||||
testData = testUtils.DataGenerator.Content.posts[2],
|
||||
today = new Date(),
|
||||
dd = ("0" + today.getDate()).slice(-2),
|
||||
mm = ("0" + (today.getMonth() + 1)).slice(-2),
|
||||
dd = ('0' + today.getDate()).slice(-2),
|
||||
mm = ('0' + (today.getMonth() + 1)).slice(-2),
|
||||
yyyy = today.getFullYear(),
|
||||
postLink = '/' + yyyy + '/' + mm + '/' + dd + '/short-and-sweet/';
|
||||
|
||||
@ -344,6 +348,7 @@ describe('Config', function () {
|
||||
settingsStub = sandbox.stub(settings, 'read', function () {
|
||||
return when({ settings: [{value: '/:year/:month/:day/:slug/'}] });
|
||||
}),
|
||||
/*jshint unused:false*/
|
||||
testData = testUtils.DataGenerator.Content.posts[5],
|
||||
postLink = '/static-page-test/';
|
||||
|
||||
|
@ -1,47 +1,51 @@
|
||||
/*globals describe, before, beforeEach, afterEach, it*/
|
||||
var testUtils = require('../utils'),
|
||||
should = require('should'),
|
||||
/*globals describe, after, before, beforeEach, afterEach, it*/
|
||||
/*jshint expr:true*/
|
||||
var should = require('should'),
|
||||
when = require('when'),
|
||||
sinon = require('sinon'),
|
||||
express = require('express'),
|
||||
rewire = require('rewire')
|
||||
rewire = require('rewire'),
|
||||
|
||||
// Stuff we are testing
|
||||
|
||||
colors = require('colors'),
|
||||
errors = rewire('../../server/errors'),
|
||||
// storing current environment
|
||||
currentEnv = process.env.NODE_ENV;
|
||||
|
||||
// This is not useful but required for jshint
|
||||
colors.setTheme({silly: 'rainbow'});
|
||||
|
||||
describe('Error handling', function () {
|
||||
|
||||
// Just getting rid of jslint unused error
|
||||
should.exist(errors);
|
||||
|
||||
describe('Throwing', function () {
|
||||
it("throws error objects", function () {
|
||||
var toThrow = new Error("test1"),
|
||||
it('throws error objects', function () {
|
||||
var toThrow = new Error('test1'),
|
||||
runThrowError = function () {
|
||||
errors.throwError(toThrow);
|
||||
};
|
||||
|
||||
runThrowError.should['throw']("test1");
|
||||
runThrowError.should['throw']('test1');
|
||||
});
|
||||
|
||||
it("throws error strings", function () {
|
||||
var toThrow = "test2",
|
||||
it('throws error strings', function () {
|
||||
var toThrow = 'test2',
|
||||
runThrowError = function () {
|
||||
errors.throwError(toThrow);
|
||||
};
|
||||
|
||||
runThrowError.should['throw']("test2");
|
||||
runThrowError.should['throw']('test2');
|
||||
});
|
||||
|
||||
it("throws error even if nothing passed", function () {
|
||||
it('throws error even if nothing passed', function () {
|
||||
var runThrowError = function () {
|
||||
errors.throwError();
|
||||
};
|
||||
|
||||
runThrowError.should['throw']("An error occurred");
|
||||
runThrowError.should['throw']('An error occurred');
|
||||
});
|
||||
});
|
||||
|
||||
@ -51,7 +55,7 @@ describe('Error handling', function () {
|
||||
beforeEach(function () {
|
||||
logStub = sinon.stub(console, 'error');
|
||||
// give environment a value that will console log
|
||||
process.env.NODE_ENV = "development";
|
||||
process.env.NODE_ENV = 'development';
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
@ -88,7 +92,9 @@ describe('Error handling', function () {
|
||||
|
||||
// Calls log with message on Error objects
|
||||
logStub.calledOnce.should.be.true;
|
||||
logStub.calledWith('\nERROR:'.red, err.message.red, '\n', message.white, '\n', message.green, '\n', err.stack, '\n');
|
||||
logStub.calledWith(
|
||||
'\nERROR:'.red, err.message.red, '\n', message.white, '\n', message.green, '\n', err.stack, '\n'
|
||||
);
|
||||
});
|
||||
|
||||
it('logs errors from three string arguments', function () {
|
||||
@ -98,7 +104,9 @@ describe('Error handling', function () {
|
||||
|
||||
// Calls log with message on Error objects
|
||||
logStub.calledOnce.should.be.true;
|
||||
logStub.calledWith('\nERROR:'.red, message.red, '\n', message.white, '\n', message.green, '\n').should.be.true;
|
||||
logStub.calledWith(
|
||||
'\nERROR:'.red, message.red, '\n', message.white, '\n', message.green, '\n'
|
||||
).should.be.true;
|
||||
});
|
||||
|
||||
it('logs errors from an undefined error argument', function () {
|
||||
@ -109,7 +117,9 @@ describe('Error handling', function () {
|
||||
// Calls log with message on Error objects
|
||||
|
||||
logStub.calledOnce.should.be.true;
|
||||
logStub.calledWith('\nERROR:'.red, 'An unknown error occurred.'.red, '\n', message.white, '\n', message.green , '\n').should.be.true;
|
||||
logStub.calledWith(
|
||||
'\nERROR:'.red, 'An unknown error occurred.'.red, '\n', message.white, '\n', message.green , '\n'
|
||||
).should.be.true;
|
||||
});
|
||||
|
||||
it('logs errors from an undefined context argument', function () {
|
||||
@ -142,7 +152,9 @@ describe('Error handling', function () {
|
||||
// Calls log with message on Error objects
|
||||
|
||||
logStub.calledOnce.should.be.true;
|
||||
logStub.calledWith('\nERROR:'.red, 'An unknown error occurred.'.red, '\n', message.white, '\n', message.green, '\n').should.be.true;
|
||||
logStub.calledWith(
|
||||
'\nERROR:'.red, 'An unknown error occurred.'.red, '\n', message.white, '\n', message.green, '\n'
|
||||
).should.be.true;
|
||||
});
|
||||
|
||||
it('logs errors from a null context argument', function () {
|
||||
@ -220,7 +232,7 @@ describe('Error handling', function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
errors.updateActiveTheme('casper');
|
||||
});
|
||||
@ -242,6 +254,7 @@ describe('Error handling', function () {
|
||||
res = express.response;
|
||||
|
||||
sandbox.stub(express.response, 'render', function (view, options, fn) {
|
||||
/*jshint unused:false */
|
||||
view.should.match(/user-error\.hbs/);
|
||||
|
||||
// Test that the message is correct
|
||||
@ -250,7 +263,9 @@ describe('Error handling', function () {
|
||||
this.statusCode.should.equal(404);
|
||||
|
||||
// Test that the headers are correct
|
||||
this._headers['cache-control'].should.equal('no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
|
||||
this._headers['cache-control'].should.equal(
|
||||
'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
|
||||
);
|
||||
|
||||
done();
|
||||
});
|
||||
@ -269,6 +284,7 @@ describe('Error handling', function () {
|
||||
res = express.response;
|
||||
|
||||
sandbox.stub(express.response, 'render', function (view, options, fn) {
|
||||
/*jshint unused:false */
|
||||
view.should.match(/user-error\.hbs/);
|
||||
|
||||
// Test that the message is correct
|
||||
@ -277,7 +293,9 @@ describe('Error handling', function () {
|
||||
this.statusCode.should.equal(404);
|
||||
|
||||
// Test that the headers are correct
|
||||
this._headers['cache-control'].should.equal('no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
|
||||
this._headers['cache-control'].should.equal(
|
||||
'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
|
||||
);
|
||||
|
||||
done();
|
||||
});
|
||||
@ -298,6 +316,7 @@ describe('Error handling', function () {
|
||||
res = express.response;
|
||||
|
||||
sandbox.stub(express.response, 'render', function (view, options, fn) {
|
||||
/*jshint unused:false */
|
||||
view.should.match(/user-error\.hbs/);
|
||||
|
||||
// Test that the message is correct
|
||||
@ -306,7 +325,9 @@ describe('Error handling', function () {
|
||||
this.statusCode.should.equal(500);
|
||||
|
||||
// Test that the headers are correct
|
||||
this._headers['cache-control'].should.equal('no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
|
||||
this._headers['cache-control'].should.equal(
|
||||
'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
|
||||
);
|
||||
|
||||
done();
|
||||
});
|
||||
@ -325,6 +346,7 @@ describe('Error handling', function () {
|
||||
res = express.response;
|
||||
|
||||
sandbox.stub(express.response, 'render', function (view, options, fn) {
|
||||
/*jshint unused:false */
|
||||
view.should.match(/user-error\.hbs/);
|
||||
|
||||
// Test that the message is correct
|
||||
@ -333,7 +355,9 @@ describe('Error handling', function () {
|
||||
this.statusCode.should.equal(500);
|
||||
|
||||
// Test that the headers are correct
|
||||
this._headers['cache-control'].should.equal('no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0');
|
||||
this._headers['cache-control'].should.equal(
|
||||
'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
|
||||
);
|
||||
|
||||
done();
|
||||
});
|
||||
@ -346,7 +370,7 @@ describe('Error handling', function () {
|
||||
err.code = 500;
|
||||
errors.error500(err, req, res, null);
|
||||
});
|
||||
|
||||
|
||||
it('Renders custom error template if one exists', function(done){
|
||||
var code = 404,
|
||||
error = {message:'Custom view test'},
|
||||
@ -355,9 +379,11 @@ describe('Error handling', function () {
|
||||
},
|
||||
res = {
|
||||
status: function(code) {
|
||||
/*jshint unused:false*/
|
||||
return this;
|
||||
},
|
||||
render: function(view, model, fn){
|
||||
/*jshint unused:false*/
|
||||
view.should.eql('error');
|
||||
errors.updateActiveTheme('casper');
|
||||
done();
|
||||
|
@ -1,18 +1,16 @@
|
||||
/*globals describe, before, beforeEach, afterEach, it*/
|
||||
var testUtils = require('../utils'),
|
||||
should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
_ = require("lodash"),
|
||||
errors = require('../../server/errors'),
|
||||
/*jshint expr:true*/
|
||||
var testUtils = require('../utils'),
|
||||
should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
_ = require('lodash'),
|
||||
|
||||
// Stuff we are testing
|
||||
migration = require('../../server/data/migration'),
|
||||
versioning = require('../../server/data/versioning'),
|
||||
exporter = require('../../server/data/export'),
|
||||
Settings = require('../../server/models/settings').Settings;
|
||||
versioning = require('../../server/data/versioning'),
|
||||
exporter = require('../../server/data/export');
|
||||
|
||||
describe("Exporter", function () {
|
||||
describe('Exporter', function () {
|
||||
|
||||
should.exist(exporter);
|
||||
|
||||
@ -38,23 +36,23 @@ describe("Exporter", function () {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it("exports data", function (done) {
|
||||
it('exports data', function (done) {
|
||||
// Stub migrations to return 000 as the current database version
|
||||
var versioningStub = sandbox.stub(versioning, "getDatabaseVersion", function () {
|
||||
return when.resolve("003");
|
||||
var versioningStub = sandbox.stub(versioning, 'getDatabaseVersion', function () {
|
||||
return when.resolve('003');
|
||||
});
|
||||
|
||||
exporter().then(function (exportData) {
|
||||
var tables = ['posts', 'users', 'roles', 'roles_users', 'permissions', 'permissions_roles', 'permissions_users',
|
||||
'settings', 'tags', 'posts_tags'];
|
||||
var tables = ['posts', 'users', 'roles', 'roles_users', 'permissions', 'permissions_roles',
|
||||
'permissions_users', 'settings', 'tags', 'posts_tags'];
|
||||
|
||||
should.exist(exportData);
|
||||
|
||||
should.exist(exportData.meta);
|
||||
should.exist(exportData.data);
|
||||
|
||||
exportData.meta.version.should.equal("003");
|
||||
_.findWhere(exportData.data.settings, {key: "databaseVersion"}).value.should.equal("003");
|
||||
exportData.meta.version.should.equal('003');
|
||||
_.findWhere(exportData.data.settings, {key: 'databaseVersion'}).value.should.equal('003');
|
||||
|
||||
_.each(tables, function (name) {
|
||||
should.exist(exportData.data[name]);
|
||||
|
@ -1,15 +1,14 @@
|
||||
/*globals describe, before, beforeEach, afterEach, it*/
|
||||
var testUtils = require('../utils'),
|
||||
should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
path = require('path'),
|
||||
_ = require('lodash'),
|
||||
/*globals describe, beforeEach, afterEach, it*/
|
||||
/*jshint expr:true*/
|
||||
var should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
_ = require('lodash'),
|
||||
|
||||
// Stuff we are testing
|
||||
Filters = require('../../server/filters').Filters;
|
||||
|
||||
describe("Filters", function () {
|
||||
describe('Filters', function () {
|
||||
|
||||
var filters, sandbox;
|
||||
|
||||
@ -23,7 +22,7 @@ describe("Filters", function () {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
it("can register filters with specific priority", function () {
|
||||
it('can register filters with specific priority', function () {
|
||||
var filterName = 'test',
|
||||
filterPriority = 9,
|
||||
testFilterHandler = sandbox.spy();
|
||||
@ -36,7 +35,7 @@ describe("Filters", function () {
|
||||
filters.filterCallbacks[filterName][filterPriority].should.include(testFilterHandler);
|
||||
});
|
||||
|
||||
it("can register filters with default priority", function () {
|
||||
it('can register filters with default priority', function () {
|
||||
var filterName = 'test',
|
||||
defaultPriority = 5,
|
||||
testFilterHandler = sandbox.spy();
|
||||
@ -49,7 +48,7 @@ describe("Filters", function () {
|
||||
filters.filterCallbacks[filterName][defaultPriority].should.include(testFilterHandler);
|
||||
});
|
||||
|
||||
it("can register filters with priority null with default priority", function () {
|
||||
it('can register filters with priority null with default priority', function () {
|
||||
var filterName = 'test',
|
||||
defaultPriority = 5,
|
||||
testFilterHandler = sandbox.spy();
|
||||
@ -62,7 +61,7 @@ describe("Filters", function () {
|
||||
filters.filterCallbacks[filterName][defaultPriority].should.include(testFilterHandler);
|
||||
});
|
||||
|
||||
it("executes filters in priority order", function (done) {
|
||||
it('executes filters in priority order', function (done) {
|
||||
var filterName = 'testpriority',
|
||||
testFilterHandler1 = sandbox.spy(),
|
||||
testFilterHandler2 = sandbox.spy(),
|
||||
@ -83,7 +82,7 @@ describe("Filters", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("executes filters that return a promise", function (done) {
|
||||
it('executes filters that return a promise', function (done) {
|
||||
var filterName = 'testprioritypromise',
|
||||
testFilterHandler1 = sinon.spy(function (args) {
|
||||
return when.promise(function (resolve) {
|
||||
@ -128,7 +127,7 @@ describe("Filters", function () {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it("executes filters with a context", function (done) {
|
||||
it('executes filters with a context', function (done) {
|
||||
var filterName = 'textContext',
|
||||
testFilterHandler1 = sinon.spy(function (args, context) {
|
||||
args.context1 = _.isObject(context);
|
||||
|
@ -1,4 +1,5 @@
|
||||
/*globals describe, beforeEach, afterEach, it*/
|
||||
/*jshint expr:true*/
|
||||
var assert = require('assert'),
|
||||
moment = require('moment'),
|
||||
should = require('should'),
|
||||
@ -11,10 +12,12 @@ var assert = require('assert'),
|
||||
api = require('../../server/api'),
|
||||
frontend = rewire('../../server/controllers/frontend');
|
||||
|
||||
// To stop jshint complaining
|
||||
should.equal(true, true);
|
||||
|
||||
describe('Frontend Controller', function () {
|
||||
|
||||
var ghost,
|
||||
sandbox,
|
||||
var sandbox,
|
||||
apiSettingsStub,
|
||||
adminEditPagePath = '/ghost/editor/';
|
||||
|
||||
@ -183,7 +186,7 @@ describe('Frontend Controller', function () {
|
||||
};
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox.stub(api.posts, 'browse', function (args) {
|
||||
sandbox.stub(api.posts, 'browse', function () {
|
||||
return when({
|
||||
posts: mockPosts,
|
||||
meta: {
|
||||
|
@ -1,11 +1,11 @@
|
||||
/*globals describe, beforeEach, it*/
|
||||
/*globals describe, beforeEach, afterEach, it*/
|
||||
/*jshint expr:true*/
|
||||
var testUtils = require('../utils'),
|
||||
should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
assert = require('assert'),
|
||||
_ = require("lodash"),
|
||||
errors = require('../../server/errors'),
|
||||
_ = require('lodash'),
|
||||
|
||||
// Stuff we are testing
|
||||
knex = require('../../server/models/base').knex,
|
||||
@ -16,11 +16,9 @@ var testUtils = require('../utils'),
|
||||
Importer000 = require('../../server/data/import/000'),
|
||||
Importer001 = require('../../server/data/import/001'),
|
||||
Importer002 = require('../../server/data/import/002'),
|
||||
Importer003 = require('../../server/data/import/003'),
|
||||
fixtures = require('../../server/data/fixtures'),
|
||||
Settings = require('../../server/models/settings').Settings;
|
||||
Importer003 = require('../../server/data/import/003');
|
||||
|
||||
describe("Import", function () {
|
||||
describe('Import', function () {
|
||||
|
||||
should.exist(exporter);
|
||||
should.exist(importer);
|
||||
@ -39,13 +37,13 @@ describe("Import", function () {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
it("resolves 000", function (done) {
|
||||
var importStub = sandbox.stub(Importer000, "importData", function () {
|
||||
it('resolves 000', function (done) {
|
||||
var importStub = sandbox.stub(Importer000, 'importData', function () {
|
||||
return when.resolve();
|
||||
}),
|
||||
fakeData = { test: true };
|
||||
|
||||
importer("000", fakeData).then(function () {
|
||||
importer('000', fakeData).then(function () {
|
||||
importStub.calledWith(fakeData).should.equal(true);
|
||||
|
||||
importStub.restore();
|
||||
@ -54,13 +52,13 @@ describe("Import", function () {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it("resolves 001", function (done) {
|
||||
var importStub = sandbox.stub(Importer001, "importData", function () {
|
||||
it('resolves 001', function (done) {
|
||||
var importStub = sandbox.stub(Importer001, 'importData', function () {
|
||||
return when.resolve();
|
||||
}),
|
||||
fakeData = { test: true };
|
||||
|
||||
importer("001", fakeData).then(function () {
|
||||
importer('001', fakeData).then(function () {
|
||||
importStub.calledWith(fakeData).should.equal(true);
|
||||
|
||||
importStub.restore();
|
||||
@ -69,13 +67,13 @@ describe("Import", function () {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it("resolves 002", function (done) {
|
||||
var importStub = sandbox.stub(Importer002, "importData", function () {
|
||||
it('resolves 002', function (done) {
|
||||
var importStub = sandbox.stub(Importer002, 'importData', function () {
|
||||
return when.resolve();
|
||||
}),
|
||||
fakeData = { test: true };
|
||||
|
||||
importer("002", fakeData).then(function () {
|
||||
importer('002', fakeData).then(function () {
|
||||
importStub.calledWith(fakeData).should.equal(true);
|
||||
|
||||
importStub.restore();
|
||||
@ -84,13 +82,13 @@ describe("Import", function () {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it("resolves 003", function (done) {
|
||||
var importStub = sandbox.stub(Importer003, "importData", function () {
|
||||
it('resolves 003', function (done) {
|
||||
var importStub = sandbox.stub(Importer003, 'importData', function () {
|
||||
return when.resolve();
|
||||
}),
|
||||
fakeData = { test: true };
|
||||
|
||||
importer("003", fakeData).then(function () {
|
||||
importer('003', fakeData).then(function () {
|
||||
importStub.calledWith(fakeData).should.equal(true);
|
||||
|
||||
importStub.restore();
|
||||
@ -99,7 +97,7 @@ describe("Import", function () {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
describe("000", function () {
|
||||
describe('000', function () {
|
||||
should.exist(Importer000);
|
||||
|
||||
beforeEach(function (done) {
|
||||
@ -112,23 +110,23 @@ describe("Import", function () {
|
||||
});
|
||||
|
||||
|
||||
it("imports data from 000", function (done) {
|
||||
it('imports data from 000', function (done) {
|
||||
var exportData,
|
||||
versioningStub = sandbox.stub(versioning, "getDatabaseVersion", function () {
|
||||
return when.resolve("000");
|
||||
versioningStub = sandbox.stub(versioning, 'getDatabaseVersion', function () {
|
||||
return when.resolve('000');
|
||||
});
|
||||
|
||||
testUtils.loadExportFixture('export-000').then(function (exported) {
|
||||
exportData = exported;
|
||||
|
||||
return importer("000", exportData);
|
||||
return importer('000', exportData);
|
||||
}).then(function () {
|
||||
// Grab the data from tables
|
||||
return when.all([
|
||||
knex("users").select(),
|
||||
knex("posts").select(),
|
||||
knex("settings").select(),
|
||||
knex("tags").select()
|
||||
knex('users').select(),
|
||||
knex('posts').select(),
|
||||
knex('settings').select(),
|
||||
knex('tags').select()
|
||||
]);
|
||||
}).then(function (importedData) {
|
||||
should.exist(importedData);
|
||||
@ -147,7 +145,7 @@ describe("Import", function () {
|
||||
|
||||
// test settings
|
||||
settings.length.should.be.above(0, 'Wrong number of settings');
|
||||
_.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version');
|
||||
_.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version');
|
||||
|
||||
// test tags
|
||||
tags.length.should.equal(exportData.data.tags.length, 'no new tags');
|
||||
@ -159,7 +157,7 @@ describe("Import", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("001", function () {
|
||||
describe('001', function () {
|
||||
should.exist(Importer001);
|
||||
|
||||
beforeEach(function (done) {
|
||||
@ -171,7 +169,7 @@ describe("Import", function () {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it("safely imports data from 001", function (done) {
|
||||
it('safely imports data from 001', function (done) {
|
||||
var exportData,
|
||||
timestamp = 1349928000000;
|
||||
|
||||
@ -183,14 +181,14 @@ describe("Import", function () {
|
||||
exportData.data.posts[0].updated_at = timestamp;
|
||||
exportData.data.posts[0].published_at = timestamp;
|
||||
|
||||
return importer("001", exportData);
|
||||
return importer('001', exportData);
|
||||
}).then(function () {
|
||||
// Grab the data from tables
|
||||
return when.all([
|
||||
knex("users").select(),
|
||||
knex("posts").select(),
|
||||
knex("settings").select(),
|
||||
knex("tags").select()
|
||||
knex('users').select(),
|
||||
knex('posts').select(),
|
||||
knex('settings').select(),
|
||||
knex('tags').select()
|
||||
]);
|
||||
}).then(function (importedData) {
|
||||
should.exist(importedData);
|
||||
@ -219,14 +217,14 @@ describe("Import", function () {
|
||||
|
||||
// test settings
|
||||
settings.length.should.be.above(0, 'Wrong number of settings');
|
||||
_.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version');
|
||||
_.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version');
|
||||
|
||||
// activeTheme should NOT have been overridden
|
||||
_.findWhere(settings, {key: "activeTheme"}).value.should.equal("casper", 'Wrong theme');
|
||||
_.findWhere(settings, {key: 'activeTheme'}).value.should.equal('casper', 'Wrong theme');
|
||||
|
||||
// email address should have been overridden
|
||||
exportEmail = _.findWhere(exportData.data.settings, {key: "email"}).value;
|
||||
_.findWhere(settings, {key: "email"}).value.should.equal(exportEmail, 'Wrong email in settings');
|
||||
exportEmail = _.findWhere(exportData.data.settings, {key: 'email'}).value;
|
||||
_.findWhere(settings, {key: 'email'}).value.should.equal(exportEmail, 'Wrong email in settings');
|
||||
|
||||
// test tags
|
||||
tags.length.should.equal(exportData.data.tags.length, 'no new tags');
|
||||
@ -244,7 +242,7 @@ describe("Import", function () {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it("doesn't import invalid post data from 001", function (done) {
|
||||
it('doesn\'t import invalid post data from 001', function (done) {
|
||||
var exportData;
|
||||
|
||||
|
||||
@ -254,7 +252,7 @@ describe("Import", function () {
|
||||
//change title to 151 characters
|
||||
exportData.data.posts[0].title = new Array(152).join('a');
|
||||
exportData.data.posts[0].tags = 'Tag';
|
||||
return importer("001", exportData);
|
||||
return importer('001', exportData);
|
||||
}).then(function () {
|
||||
(1).should.eql(0, 'Data import should not resolve promise.');
|
||||
}, function (error) {
|
||||
@ -263,10 +261,10 @@ describe("Import", function () {
|
||||
error[0].type.should.eql('ValidationError');
|
||||
|
||||
when.all([
|
||||
knex("users").select(),
|
||||
knex("posts").select(),
|
||||
knex("settings").select(),
|
||||
knex("tags").select()
|
||||
knex('users').select(),
|
||||
knex('posts').select(),
|
||||
knex('settings').select(),
|
||||
knex('tags').select()
|
||||
]).then(function (importedData) {
|
||||
should.exist(importedData);
|
||||
|
||||
@ -284,7 +282,7 @@ describe("Import", function () {
|
||||
|
||||
// test settings
|
||||
settings.length.should.be.above(0, 'Wrong number of settings');
|
||||
_.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version');
|
||||
_.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version');
|
||||
|
||||
// test tags
|
||||
tags.length.should.equal(exportData.data.tags.length, 'no new tags');
|
||||
@ -295,14 +293,14 @@ describe("Import", function () {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it("doesn't import invalid settings data from 001", function (done) {
|
||||
it('doesn\'t import invalid settings data from 001', function (done) {
|
||||
var exportData;
|
||||
|
||||
testUtils.loadExportFixture('export-001').then(function (exported) {
|
||||
exportData = exported;
|
||||
//change to blank settings key
|
||||
exportData.data.settings[3].key = null;
|
||||
return importer("001", exportData);
|
||||
return importer('001', exportData);
|
||||
}).then(function () {
|
||||
(1).should.eql(0, 'Data import should not resolve promise.');
|
||||
}, function (error) {
|
||||
@ -311,10 +309,10 @@ describe("Import", function () {
|
||||
error[0].type.should.eql('ValidationError');
|
||||
|
||||
when.all([
|
||||
knex("users").select(),
|
||||
knex("posts").select(),
|
||||
knex("settings").select(),
|
||||
knex("tags").select()
|
||||
knex('users').select(),
|
||||
knex('posts').select(),
|
||||
knex('settings').select(),
|
||||
knex('tags').select()
|
||||
]).then(function (importedData) {
|
||||
should.exist(importedData);
|
||||
|
||||
@ -332,7 +330,7 @@ describe("Import", function () {
|
||||
|
||||
// test settings
|
||||
settings.length.should.be.above(0, 'Wrong number of settings');
|
||||
_.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version');
|
||||
_.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version');
|
||||
|
||||
// test tags
|
||||
tags.length.should.equal(exportData.data.tags.length, 'no new tags');
|
||||
@ -344,7 +342,7 @@ describe("Import", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("002", function () {
|
||||
describe('002', function () {
|
||||
should.exist(Importer002);
|
||||
|
||||
beforeEach(function (done) {
|
||||
@ -356,7 +354,7 @@ describe("Import", function () {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it("safely imports data from 002", function (done) {
|
||||
it('safely imports data from 002', function (done) {
|
||||
var exportData,
|
||||
timestamp = 1349928000000;
|
||||
|
||||
@ -368,14 +366,14 @@ describe("Import", function () {
|
||||
exportData.data.posts[0].updated_at = timestamp;
|
||||
exportData.data.posts[0].published_at = timestamp;
|
||||
|
||||
return importer("002", exportData);
|
||||
return importer('002', exportData);
|
||||
}).then(function () {
|
||||
// Grab the data from tables
|
||||
return when.all([
|
||||
knex("users").select(),
|
||||
knex("posts").select(),
|
||||
knex("settings").select(),
|
||||
knex("tags").select()
|
||||
knex('users').select(),
|
||||
knex('posts').select(),
|
||||
knex('settings').select(),
|
||||
knex('tags').select()
|
||||
]);
|
||||
}).then(function (importedData) {
|
||||
should.exist(importedData);
|
||||
@ -404,14 +402,14 @@ describe("Import", function () {
|
||||
|
||||
// test settings
|
||||
settings.length.should.be.above(0, 'Wrong number of settings');
|
||||
_.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version');
|
||||
_.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version');
|
||||
|
||||
// activeTheme should NOT have been overridden
|
||||
_.findWhere(settings, {key: "activeTheme"}).value.should.equal("casper", 'Wrong theme');
|
||||
_.findWhere(settings, {key: 'activeTheme'}).value.should.equal('casper', 'Wrong theme');
|
||||
|
||||
// email address should have been overridden
|
||||
exportEmail = _.findWhere(exportData.data.settings, {key: "email"}).value;
|
||||
_.findWhere(settings, {key: "email"}).value.should.equal(exportEmail, 'Wrong email in settings');
|
||||
exportEmail = _.findWhere(exportData.data.settings, {key: 'email'}).value;
|
||||
_.findWhere(settings, {key: 'email'}).value.should.equal(exportEmail, 'Wrong email in settings');
|
||||
|
||||
// test tags
|
||||
tags.length.should.equal(exportData.data.tags.length, 'no new tags');
|
||||
@ -431,7 +429,7 @@ describe("Import", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("doesn't import invalid post data from 002", function (done) {
|
||||
it('doesn\'t import invalid post data from 002', function (done) {
|
||||
var exportData;
|
||||
|
||||
|
||||
@ -441,7 +439,7 @@ describe("Import", function () {
|
||||
//change title to 151 characters
|
||||
exportData.data.posts[0].title = new Array(152).join('a');
|
||||
exportData.data.posts[0].tags = 'Tag';
|
||||
return importer("002", exportData);
|
||||
return importer('002', exportData);
|
||||
}).then(function () {
|
||||
(1).should.eql(0, 'Data import should not resolve promise.');
|
||||
}, function (error) {
|
||||
@ -450,10 +448,10 @@ describe("Import", function () {
|
||||
error[0].type.should.eql('ValidationError');
|
||||
|
||||
when.all([
|
||||
knex("users").select(),
|
||||
knex("posts").select(),
|
||||
knex("settings").select(),
|
||||
knex("tags").select()
|
||||
knex('users').select(),
|
||||
knex('posts').select(),
|
||||
knex('settings').select(),
|
||||
knex('tags').select()
|
||||
]).then(function (importedData) {
|
||||
should.exist(importedData);
|
||||
|
||||
@ -471,7 +469,7 @@ describe("Import", function () {
|
||||
|
||||
// test settings
|
||||
settings.length.should.be.above(0, 'Wrong number of settings');
|
||||
_.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version');
|
||||
_.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version');
|
||||
|
||||
// test tags
|
||||
tags.length.should.equal(exportData.data.tags.length, 'no new tags');
|
||||
@ -482,14 +480,14 @@ describe("Import", function () {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it("doesn't import invalid settings data from 002", function (done) {
|
||||
it('doesn\'t import invalid settings data from 002', function (done) {
|
||||
var exportData;
|
||||
|
||||
testUtils.loadExportFixture('export-002').then(function (exported) {
|
||||
exportData = exported;
|
||||
//change to blank settings key
|
||||
exportData.data.settings[3].key = null;
|
||||
return importer("002", exportData);
|
||||
return importer('002', exportData);
|
||||
}).then(function () {
|
||||
(1).should.eql(0, 'Data import should not resolve promise.');
|
||||
}, function (error) {
|
||||
@ -498,10 +496,10 @@ describe("Import", function () {
|
||||
error[0].type.should.eql('ValidationError');
|
||||
|
||||
when.all([
|
||||
knex("users").select(),
|
||||
knex("posts").select(),
|
||||
knex("settings").select(),
|
||||
knex("tags").select()
|
||||
knex('users').select(),
|
||||
knex('posts').select(),
|
||||
knex('settings').select(),
|
||||
knex('tags').select()
|
||||
]).then(function (importedData) {
|
||||
should.exist(importedData);
|
||||
|
||||
@ -519,7 +517,7 @@ describe("Import", function () {
|
||||
|
||||
// test settings
|
||||
settings.length.should.be.above(0, 'Wrong number of settings');
|
||||
_.findWhere(settings, {key: "databaseVersion"}).value.should.equal("003", 'Wrong database version');
|
||||
_.findWhere(settings, {key: 'databaseVersion'}).value.should.equal('003', 'Wrong database version');
|
||||
|
||||
// test tags
|
||||
tags.length.should.equal(exportData.data.tags.length, 'no new tags');
|
||||
@ -531,7 +529,7 @@ describe("Import", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("003", function () {
|
||||
describe('003', function () {
|
||||
should.exist(Importer003);
|
||||
|
||||
beforeEach(function (done) {
|
||||
@ -543,25 +541,25 @@ describe("Import", function () {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it("safely imports data from 003", function (done) {
|
||||
it('safely imports data from 003', function (done) {
|
||||
var exportData;
|
||||
|
||||
testUtils.loadExportFixture('export-003').then(function (exported) {
|
||||
exportData = exported;
|
||||
return importer("003", exportData);
|
||||
return importer('003', exportData);
|
||||
}).then(function () {
|
||||
// Grab the data from tables
|
||||
return when.all([
|
||||
knex("apps").select(),
|
||||
knex("app_settings").select()
|
||||
knex('apps').select(),
|
||||
knex('app_settings').select()
|
||||
]);
|
||||
}).then(function (importedData) {
|
||||
should.exist(importedData);
|
||||
|
||||
importedData.length.should.equal(2, 'Did not get data successfully');
|
||||
|
||||
var apps = importedData[0],
|
||||
app_settings = importedData[1];
|
||||
var apps = importedData[0];
|
||||
// app_settings = importedData[1];
|
||||
|
||||
// test apps
|
||||
apps.length.should.equal(exportData.data.apps.length, 'imported apps');
|
||||
|
@ -1,11 +1,10 @@
|
||||
/*globals describe, beforeEach, afterEach, it*/
|
||||
/*jshint expr:true*/
|
||||
var should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
_ = require("lodash"),
|
||||
cp = require('child_process'),
|
||||
rewire = require("rewire"),
|
||||
testUtils = require('../utils'),
|
||||
_ = require('lodash'),
|
||||
rewire = require('rewire'),
|
||||
|
||||
// Stuff we are testing
|
||||
mailer = rewire('../../server/mail'),
|
||||
@ -38,7 +37,7 @@ SENDMAIL = {
|
||||
}
|
||||
};
|
||||
|
||||
describe("Mail", function () {
|
||||
describe('Mail', function () {
|
||||
var overrideConfig = function (newConfig) {
|
||||
mailer.__set__('config', sandbox.stub().returns(
|
||||
_.extend({}, defaultConfig, newConfig)
|
||||
@ -56,11 +55,11 @@ describe("Mail", function () {
|
||||
|
||||
config = sinon.stub().returns(fakeConfig);
|
||||
|
||||
sandbox.stub(mailer, "isWindows", function () {
|
||||
sandbox.stub(mailer, 'isWindows', function () {
|
||||
return false;
|
||||
});
|
||||
|
||||
sandbox.stub(mailer, "detectSendmail", function () {
|
||||
sandbox.stub(mailer, 'detectSendmail', function () {
|
||||
return when.resolve(fakeSendmail);
|
||||
});
|
||||
});
|
||||
@ -119,7 +118,7 @@ describe("Mail", function () {
|
||||
it('should disable transport if config is empty & sendmail not found', function (done) {
|
||||
overrideConfig({mail: {}});
|
||||
mailer.detectSendmail.restore();
|
||||
sandbox.stub(mailer, "detectSendmail", when.reject);
|
||||
sandbox.stub(mailer, 'detectSendmail', when.reject);
|
||||
mailer.init().then(function () {
|
||||
should.not.exist(mailer.transport);
|
||||
done();
|
||||
@ -141,7 +140,7 @@ describe("Mail", function () {
|
||||
|
||||
it('should fail to send messages when no transport is set', function (done) {
|
||||
mailer.detectSendmail.restore();
|
||||
sandbox.stub(mailer, "detectSendmail", when.reject);
|
||||
sandbox.stub(mailer, 'detectSendmail', when.reject);
|
||||
mailer.init().then(function () {
|
||||
mailer.send().then(function () {
|
||||
should.fail();
|
||||
|
@ -1,10 +1,9 @@
|
||||
/*globals describe, beforeEach, afterEach, it*/
|
||||
/*jshint expr:true*/
|
||||
var assert = require('assert'),
|
||||
should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
_ = require('lodash'),
|
||||
express = require('express'),
|
||||
api = require('../../server/api'),
|
||||
middleware = require('../../server/middleware').middleware;
|
||||
|
||||
@ -178,7 +177,10 @@ describe('Middleware', function () {
|
||||
middleware.cacheControl('private')(null, res, function (a) {
|
||||
should.not.exist(a);
|
||||
res.set.calledOnce.should.be.true;
|
||||
res.set.calledWith({'Cache-Control': 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'});
|
||||
res.set.calledWith({
|
||||
'Cache-Control':
|
||||
'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -275,16 +277,12 @@ describe('Middleware', function () {
|
||||
});
|
||||
|
||||
it('should call express.static if valid file type', function (done) {
|
||||
var ghostStub = {
|
||||
paths: function () {
|
||||
return {activeTheme: 'ACTIVETHEME'};
|
||||
}
|
||||
},
|
||||
req = {
|
||||
var req = {
|
||||
url: 'myvalidfile.css'
|
||||
};
|
||||
|
||||
middleware.staticTheme(null)(req, null, function (reqArg, res, next) {
|
||||
/*jshint unused:false */
|
||||
middleware.forwardToExpressStatic.calledOnce.should.be.true;
|
||||
assert.deepEqual(middleware.forwardToExpressStatic.args[0][0], req);
|
||||
done();
|
||||
|
@ -1,10 +1,10 @@
|
||||
/*globals describe, before, beforeEach, afterEach, it*/
|
||||
var testUtils = require('../utils'),
|
||||
should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
_ = require("lodash"),
|
||||
errors = require('../../server/errors'),
|
||||
/*globals describe, before, beforeEach, afterEach, after, it*/
|
||||
/*jshint expr:true*/
|
||||
var testUtils = require('../utils'),
|
||||
should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
_ = require('lodash'),
|
||||
|
||||
// Stuff we are testing
|
||||
permissions = require('../../server/permissions'),
|
||||
@ -39,22 +39,22 @@ describe('Permissions', function () {
|
||||
});
|
||||
|
||||
var testPerms = [
|
||||
{ act: "edit", obj: "post" },
|
||||
{ act: "edit", obj: "tag" },
|
||||
{ act: "edit", obj: "user" },
|
||||
{ act: "edit", obj: "page" },
|
||||
{ act: "add", obj: "post" },
|
||||
{ act: "add", obj: "user" },
|
||||
{ act: "add", obj: "page" },
|
||||
{ act: "remove", obj: "post" },
|
||||
{ act: "remove", obj: "user" }
|
||||
{ act: 'edit', obj: 'post' },
|
||||
{ act: 'edit', obj: 'tag' },
|
||||
{ act: 'edit', obj: 'user' },
|
||||
{ act: 'edit', obj: 'page' },
|
||||
{ act: 'add', obj: 'post' },
|
||||
{ act: 'add', obj: 'user' },
|
||||
{ act: 'add', obj: 'page' },
|
||||
{ act: 'remove', obj: 'post' },
|
||||
{ act: 'remove', obj: 'user' }
|
||||
],
|
||||
currTestPermId = 1,
|
||||
|
||||
createPermission = function (name, act, obj) {
|
||||
if (!name) {
|
||||
currTestPermId += 1;
|
||||
name = "test" + currTestPermId;
|
||||
name = 'test' + currTestPermId;
|
||||
}
|
||||
|
||||
var newPerm = {
|
||||
@ -131,7 +131,7 @@ describe('Permissions', function () {
|
||||
it('can add user permissions', function (done) {
|
||||
UserProvider.findOne({id: 1}, { withRelated: ['permissions']}).then(function (testUser) {
|
||||
var testPermission = new Models.Permission({
|
||||
name: "test edit posts",
|
||||
name: 'test edit posts',
|
||||
action_type: 'edit',
|
||||
object_type: 'post'
|
||||
});
|
||||
@ -154,8 +154,8 @@ describe('Permissions', function () {
|
||||
|
||||
it('can add role permissions', function (done) {
|
||||
var testRole = new Models.Role({
|
||||
name: "test2",
|
||||
description: "test2 description"
|
||||
name: 'test2',
|
||||
description: 'test2 description'
|
||||
});
|
||||
|
||||
testRole.save(null, {user: 1})
|
||||
@ -164,7 +164,7 @@ describe('Permissions', function () {
|
||||
})
|
||||
.then(function () {
|
||||
var rolePermission = new Models.Permission({
|
||||
name: "test edit posts",
|
||||
name: 'test edit posts',
|
||||
action_type: 'edit',
|
||||
object_type: 'post'
|
||||
});
|
||||
@ -227,7 +227,7 @@ describe('Permissions', function () {
|
||||
|
||||
it('allows edit post with permission', function (done) {
|
||||
var fakePost = {
|
||||
id: "1"
|
||||
id: '1'
|
||||
};
|
||||
|
||||
createTestPermissions()
|
||||
@ -237,9 +237,9 @@ describe('Permissions', function () {
|
||||
})
|
||||
.then(function (foundUser) {
|
||||
var newPerm = new Models.Permission({
|
||||
name: "test3 edit post",
|
||||
action_type: "edit",
|
||||
object_type: "post"
|
||||
name: 'test3 edit post',
|
||||
action_type: 'edit',
|
||||
object_type: 'post'
|
||||
});
|
||||
|
||||
return newPerm.save(null, {user: 1}).then(function () {
|
||||
@ -281,7 +281,8 @@ describe('Permissions', function () {
|
||||
})
|
||||
.then(function () {
|
||||
permissableStub.restore();
|
||||
permissableStub.calledWith(123, { user: testUser.id, app: null, internal: false }).should.equal(true);
|
||||
permissableStub.calledWith(123, { user: testUser.id, app: null, internal: false })
|
||||
.should.equal(true);
|
||||
|
||||
done();
|
||||
})
|
||||
@ -310,16 +311,17 @@ describe('Permissions', function () {
|
||||
.then(function () {
|
||||
|
||||
permissableStub.restore();
|
||||
done(new Error("Allowed testUser to edit post"));
|
||||
done(new Error('Allowed testUser to edit post'));
|
||||
})
|
||||
.catch(function () {
|
||||
permissableStub.calledWith(123, { user: testUser.id, app: null, internal: false }).should.equal(true);
|
||||
permissableStub.calledWith(123, { user: testUser.id, app: null, internal: false })
|
||||
.should.equal(true);
|
||||
permissableStub.restore();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("can get effective user permissions", function (done) {
|
||||
it('can get effective user permissions', function (done) {
|
||||
effectivePerms.user(1).then(function (effectivePermissions) {
|
||||
should.exist(effectivePermissions);
|
||||
|
||||
@ -349,9 +351,9 @@ describe('Permissions', function () {
|
||||
return UserProvider.findOne({id: 1})
|
||||
.then(function (foundUser) {
|
||||
var newPerm = new Models.Permission({
|
||||
name: "app test edit post",
|
||||
action_type: "edit",
|
||||
object_type: "post"
|
||||
name: 'app test edit post',
|
||||
action_type: 'edit',
|
||||
object_type: 'post'
|
||||
});
|
||||
|
||||
return newPerm.save(null, {user: 1}).then(function () {
|
||||
@ -372,7 +374,8 @@ describe('Permissions', function () {
|
||||
return results;
|
||||
})
|
||||
.catch(function (err) {
|
||||
done(new Error("Did not allow user 1 to edit post 1"));
|
||||
/*jshint unused:false */
|
||||
done(new Error('Did not allow user 1 to edit post 1'));
|
||||
});
|
||||
})
|
||||
.then(function (results) {
|
||||
@ -384,7 +387,7 @@ describe('Permissions', function () {
|
||||
.edit
|
||||
.post(updatedPost.id)
|
||||
.then(function () {
|
||||
done(new Error("Allowed an edit of post 1"));
|
||||
done(new Error('Allowed an edit of post 1'));
|
||||
}).catch(done);
|
||||
}).catch(done);
|
||||
});
|
||||
@ -397,7 +400,7 @@ describe('Permissions', function () {
|
||||
done();
|
||||
})
|
||||
.catch(function () {
|
||||
done(new Error("Allowed an edit of post 1"));
|
||||
done(new Error('Allowed an edit of post 1'));
|
||||
});
|
||||
});
|
||||
|
||||
@ -406,7 +409,7 @@ describe('Permissions', function () {
|
||||
.edit
|
||||
.post(1)
|
||||
.then(function () {
|
||||
done(new Error("Should not allow editing post"));
|
||||
done(new Error('Should not allow editing post'));
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
@ -420,7 +423,7 @@ describe('Permissions', function () {
|
||||
done();
|
||||
})
|
||||
.catch(function () {
|
||||
done(new Error("Should allow editing post with 'internal'"));
|
||||
done(new Error('Should allow editing post with "internal"'));
|
||||
});
|
||||
});
|
||||
|
||||
@ -433,7 +436,7 @@ describe('Permissions', function () {
|
||||
done();
|
||||
})
|
||||
.catch(function () {
|
||||
done(new Error("Should allow editing post with { internal: true }"));
|
||||
done(new Error('Should allow editing post with { internal: true }'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,10 +1,9 @@
|
||||
/*globals describe, beforeEach, afterEach, it*/
|
||||
var testUtils = require('../utils'),
|
||||
should = require('should'),
|
||||
/*globals describe, beforeEach, afterEach, before, after, it*/
|
||||
/*jshint expr:true*/
|
||||
var should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
_ = require('lodash'),
|
||||
path = require('path'),
|
||||
rewire = require('rewire'),
|
||||
moment = require('moment'),
|
||||
Polyglot = require('node-polyglot'),
|
||||
@ -33,7 +32,7 @@ describe('Core Helpers', function () {
|
||||
var adminHbs = hbs.create();
|
||||
helpers = rewire('../../server/helpers');
|
||||
sandbox = sinon.sandbox.create();
|
||||
apiStub = sandbox.stub(api.settings, 'read', function (arg) {
|
||||
apiStub = sandbox.stub(api.settings, 'read', function () {
|
||||
return when({
|
||||
settings: [{value: 'casper'}]
|
||||
});
|
||||
@ -81,7 +80,7 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('can render content', function () {
|
||||
var html = "Hello World",
|
||||
var html = 'Hello World',
|
||||
rendered = helpers.content.call({html: html});
|
||||
|
||||
should.exist(rendered);
|
||||
@ -89,87 +88,88 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('can truncate html by word', function () {
|
||||
var html = "<p>Hello <strong>World! It's me!</strong></p>",
|
||||
var html = '<p>Hello <strong>World! It\'s me!</strong></p>',
|
||||
rendered = (
|
||||
helpers.content
|
||||
.call(
|
||||
{html: html},
|
||||
{"hash": {"words": 2}}
|
||||
{'hash': {'words': 2}}
|
||||
)
|
||||
);
|
||||
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal("<p>Hello <strong>World</strong></p>");
|
||||
rendered.string.should.equal('<p>Hello <strong>World</strong></p>');
|
||||
});
|
||||
|
||||
it('can truncate html to 0 words', function () {
|
||||
var html = "<p>Hello <strong>World! It's me!</strong></p>",
|
||||
var html = '<p>Hello <strong>World! It\'s me!</strong></p>',
|
||||
rendered = (
|
||||
helpers.content
|
||||
.call(
|
||||
{html: html},
|
||||
{"hash": {"words": "0"}}
|
||||
{'hash': {'words': '0'}}
|
||||
)
|
||||
);
|
||||
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal("<p></p>");
|
||||
rendered.string.should.equal('<p></p>');
|
||||
});
|
||||
|
||||
it('can truncate html to 0 words, leaving image tag if it is first', function () {
|
||||
var html = "<p><img src='example.jpg' />Hello <strong>World! It's me!</strong></p>",
|
||||
var html = '<p><img src="example.jpg" />Hello <strong>World! It\'s me!</strong></p>',
|
||||
rendered = (
|
||||
helpers.content
|
||||
.call(
|
||||
{html: html},
|
||||
{"hash": {"words": "0"}}
|
||||
{'hash': {'words': '0'}}
|
||||
)
|
||||
);
|
||||
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal("<p><img src='example.jpg' /></p>");
|
||||
rendered.string.should.equal('<p><img src="example.jpg" /></p>');
|
||||
});
|
||||
|
||||
it('can truncate html to 0 words, leaving image tag if it is first and if it has an alt text with a single quote in the string', function () {
|
||||
var html = "<p><img src='example.jpg' alt=\"It's me!\" />Hello <strong>World! It's me!</strong></p>",
|
||||
it('can truncate html to 0 words, leaving first image tag & if alt text has a single quote', function () {
|
||||
var html = '<p><img src="example.jpg" alt="It\'s me!" />Hello <strong>World! It\'s me!</strong></p>',
|
||||
rendered = (
|
||||
helpers.content
|
||||
.call(
|
||||
{ html: html },
|
||||
{ "hash": { "words": "0" } }
|
||||
{ 'hash': { 'words': '0' } }
|
||||
)
|
||||
);
|
||||
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal("<p><img src='example.jpg' alt=\"It's me!\" /></p>");
|
||||
rendered.string.should.equal('<p><img src="example.jpg" alt="It\'s me!" /></p>');
|
||||
});
|
||||
|
||||
it('can truncate html to 0 words, leaving image tag if it is first and if it has an alt text with a double quote in the string', function () {
|
||||
var html = "<p><img src='example.jpg' alt='A double quote is \"' />Hello <strong>World! It's me!</strong></p>",
|
||||
it('can truncate html to 0 words, leaving first image tag & if alt text has a double quote', function () {
|
||||
var html = '<p><img src="example.jpg" alt="A double quote is \'" />' +
|
||||
'Hello <strong>World! It\'s me!</strong></p>',
|
||||
rendered = (
|
||||
helpers.content
|
||||
.call(
|
||||
{ html: html },
|
||||
{ "hash": { "words": "0" } }
|
||||
{ 'hash': { 'words': '0' } }
|
||||
)
|
||||
);
|
||||
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal("<p><img src='example.jpg' alt='A double quote is \"' /></p>");
|
||||
rendered.string.should.equal('<p><img src="example.jpg" alt="A double quote is \'" /></p>');
|
||||
});
|
||||
|
||||
it('can truncate html by character', function () {
|
||||
var html = "<p>Hello <strong>World! It's me!</strong></p>",
|
||||
var html = '<p>Hello <strong>World! It\'s me!</strong></p>',
|
||||
rendered = (
|
||||
helpers.content
|
||||
.call(
|
||||
{html: html},
|
||||
{"hash": {"characters": 8}}
|
||||
{'hash': {'characters': 8}}
|
||||
)
|
||||
);
|
||||
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal("<p>Hello <strong>Wo</strong></p>");
|
||||
rendered.string.should.equal('<p>Hello <strong>Wo</strong></p>');
|
||||
});
|
||||
});
|
||||
|
||||
@ -179,18 +179,18 @@ describe('Core Helpers', function () {
|
||||
should.exist(handlebars.helpers.author);
|
||||
});
|
||||
|
||||
it("Returns the full name of the author from the context", function () {
|
||||
var data = {"author": {"name": "abc123"}},
|
||||
it('Returns the full name of the author from the context', function () {
|
||||
var data = {'author': {'name': 'abc123'}},
|
||||
result = helpers.author.call(data);
|
||||
|
||||
String(result).should.equal("abc123");
|
||||
String(result).should.equal('abc123');
|
||||
});
|
||||
|
||||
it("Returns a blank string where author data is missing", function () {
|
||||
var data = {"author": null},
|
||||
it('Returns a blank string where author data is missing', function () {
|
||||
var data = {'author': null},
|
||||
result = helpers.author.call(data);
|
||||
|
||||
String(result).should.equal("");
|
||||
String(result).should.equal('');
|
||||
});
|
||||
|
||||
});
|
||||
@ -202,8 +202,8 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('can escape URI', function () {
|
||||
var uri = "$pecial!Charact3r(De[iver]y)Foo #Bar",
|
||||
expected = "%24pecial!Charact3r(De%5Biver%5Dy)Foo%20%23Bar",
|
||||
var uri = '$pecial!Charact3r(De[iver]y)Foo #Bar',
|
||||
expected = '%24pecial!Charact3r(De%5Biver%5Dy)Foo%20%23Bar',
|
||||
escaped = handlebars.helpers.encode(uri);
|
||||
|
||||
should.exist(escaped);
|
||||
@ -218,7 +218,7 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('can render excerpt', function () {
|
||||
var html = "Hello World",
|
||||
var html = 'Hello World',
|
||||
rendered = helpers.excerpt.call({html: html});
|
||||
|
||||
should.exist(rendered);
|
||||
@ -226,12 +226,12 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('does not output HTML', function () {
|
||||
var html = '<p>There are <br />10<br> types<br/> of people in <img src="a">the world:'
|
||||
+ '<img src=b alt=\"c\"> those who <img src="@" onclick="javascript:alert(\'hello\');">'
|
||||
+ "understand trinary</p>, those who don't <div style='' class=~/'-,._?!|#>and"
|
||||
+ "< test > those<<< test >>> who mistake it <for> binary.",
|
||||
expected = "There are 10 types of people in the world: those who understand trinary, those who don't "
|
||||
+ "and those>> who mistake it <for> binary.",
|
||||
var html = '<p>There are <br />10<br> types<br/> of people in <img src="a">the world:' +
|
||||
'<img src=b alt="c"> those who <img src="@" onclick="javascript:alert(\'hello\');">' +
|
||||
'understand trinary</p>, those who don\'t <div style="" class=~/\'-,._?!|#>and' +
|
||||
'< test > those<<< test >>> who mistake it <for> binary.',
|
||||
expected = 'There are 10 types of people in the world: those who understand trinary, those who ' +
|
||||
'don\'t and those>> who mistake it <for> binary.',
|
||||
rendered = helpers.excerpt.call({html: html});
|
||||
|
||||
should.exist(rendered);
|
||||
@ -240,12 +240,12 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('can truncate html by word', function () {
|
||||
var html = "<p>Hello <strong>World! It's me!</strong></p>",
|
||||
expected = "Hello World",
|
||||
var html = '<p>Hello <strong>World! It\'s me!</strong></p>',
|
||||
expected = 'Hello World',
|
||||
rendered = (
|
||||
helpers.excerpt.call(
|
||||
{html: html},
|
||||
{"hash": {"words": "2"}}
|
||||
{'hash': {'words': '2'}}
|
||||
)
|
||||
);
|
||||
|
||||
@ -254,12 +254,12 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('can truncate html with non-ascii characters by word', function () {
|
||||
var html = "<p>Едквюэ опортэат <strong>праэчынт ючю но, квуй эю</strong></p>",
|
||||
expected = "Едквюэ опортэат",
|
||||
var html = '<p>Едквюэ опортэат <strong>праэчынт ючю но, квуй эю</strong></p>',
|
||||
expected = 'Едквюэ опортэат',
|
||||
rendered = (
|
||||
helpers.excerpt.call(
|
||||
{html: html},
|
||||
{"hash": {"words": "2"}}
|
||||
{'hash': {'words': '2'}}
|
||||
)
|
||||
);
|
||||
|
||||
@ -268,12 +268,12 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('can truncate html by character', function () {
|
||||
var html = "<p>Hello <strong>World! It's me!</strong></p>",
|
||||
expected = "Hello Wo",
|
||||
var html = '<p>Hello <strong>World! It\'s me!</strong></p>',
|
||||
expected = 'Hello Wo',
|
||||
rendered = (
|
||||
helpers.excerpt.call(
|
||||
{html: html},
|
||||
{"hash": {"characters": "8"}}
|
||||
{'hash': {'characters': '8'}}
|
||||
)
|
||||
);
|
||||
|
||||
@ -404,7 +404,7 @@ describe('Core Helpers', function () {
|
||||
|
||||
it('returns meta tag string', function (done) {
|
||||
configUpdate({url: 'http://testurl.com/'});
|
||||
helpers.ghost_head.call({version: "0.3.0"}).then(function (rendered) {
|
||||
helpers.ghost_head.call({version: '0.3.0'}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal('<meta name="generator" content="Ghost 0.3" />\n' +
|
||||
'<link rel="alternate" type="application/rss+xml" title="Ghost" href="/rss/">\n' +
|
||||
@ -416,7 +416,7 @@ describe('Core Helpers', function () {
|
||||
|
||||
it('returns meta tag string even if version is invalid', function (done) {
|
||||
configUpdate({url: 'http://testurl.com/'});
|
||||
helpers.ghost_head.call({version: "0.9"}).then(function (rendered) {
|
||||
helpers.ghost_head.call({version: '0.9'}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal('<meta name="generator" content="Ghost 0.9" />\n' +
|
||||
'<link rel="alternate" type="application/rss+xml" title="Ghost" href="/rss/">\n' +
|
||||
@ -428,7 +428,7 @@ describe('Core Helpers', function () {
|
||||
|
||||
it('returns correct rss url with subdirectory', function (done) {
|
||||
configUpdate({url: 'http://testurl.com/blog/'});
|
||||
helpers.ghost_head.call({version: "0.3.0"}).then(function (rendered) {
|
||||
helpers.ghost_head.call({version: '0.3.0'}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal('<meta name="generator" content="Ghost 0.3" />\n' +
|
||||
'<link rel="alternate" type="application/rss+xml" title="Ghost" href="/blog/rss/">\n' +
|
||||
@ -440,7 +440,7 @@ describe('Core Helpers', function () {
|
||||
|
||||
it('returns canonical URL', function (done) {
|
||||
configUpdate({url: 'http://testurl.com'});
|
||||
helpers.ghost_head.call({version: "0.3.0", relativeUrl: '/about/'}).then(function (rendered) {
|
||||
helpers.ghost_head.call({version: '0.3.0', relativeUrl: '/about/'}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.string.should.equal('<meta name="generator" content="Ghost 0.3" />\n' +
|
||||
'<link rel="alternate" type="application/rss+xml" title="Ghost" href="/rss/">\n' +
|
||||
@ -552,7 +552,9 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('should return the slug with a prefix slash if the context is a post', function (done) {
|
||||
helpers.url.call({html: 'content', markdown: "ff", title: "title", slug: "slug", created_at: new Date(0)}).then(function (rendered) {
|
||||
helpers.url.call({
|
||||
html: 'content', markdown: 'ff', title: 'title', slug: 'slug', created_at: new Date(0)
|
||||
}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.should.equal('/slug/');
|
||||
done();
|
||||
@ -563,7 +565,7 @@ describe('Core Helpers', function () {
|
||||
configUpdate({ url: 'http://testurl.com/' });
|
||||
|
||||
helpers.url.call(
|
||||
{html: 'content', markdown: "ff", title: "title", slug: "slug", created_at: new Date(0)},
|
||||
{html: 'content', markdown: 'ff', title: 'title', slug: 'slug', created_at: new Date(0)},
|
||||
{hash: { absolute: 'true'}}
|
||||
).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
@ -573,7 +575,9 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('should return the slug with a prefixed /tag/ if the context is a tag', function (done) {
|
||||
helpers.url.call({name: 'the tag', slug: "the-tag", description: null, parent_id: null}).then(function (rendered) {
|
||||
helpers.url.call({
|
||||
name: 'the tag', slug: 'the-tag', description: null, parent_id: null
|
||||
}).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
rendered.should.equal('/tag/the-tag/');
|
||||
done();
|
||||
@ -600,7 +604,7 @@ describe('Core Helpers', function () {
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('Page Url Helper', function () {
|
||||
it('has loaded page_url helper', function () {
|
||||
should.exist(handlebars.helpers.page_url);
|
||||
@ -693,7 +697,7 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Pagination helper", function () {
|
||||
describe('Pagination helper', function () {
|
||||
var paginationRegex = /class="pagination"/,
|
||||
newerRegex = /class="newer-posts"/,
|
||||
olderRegex = /class="older-posts"/,
|
||||
@ -707,7 +711,7 @@ describe('Core Helpers', function () {
|
||||
var runHelper = function (data) {
|
||||
return function () {
|
||||
helpers.pagination.call(data);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
runHelper('not an object').should.throwError('pagination data is not an object or is a function');
|
||||
@ -715,7 +719,9 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('can render single page with no pagination necessary', function () {
|
||||
var rendered = helpers.pagination.call({pagination: {page: 1, prev: null, next: null, limit: 15, total: 8, pages: 1}, tag: {slug: 'slug'}});
|
||||
var rendered = helpers.pagination.call({
|
||||
pagination: {page: 1, prev: null, next: null, limit: 15, total: 8, pages: 1}, tag: {slug: 'slug'}
|
||||
});
|
||||
should.exist(rendered);
|
||||
// strip out carriage returns and compare.
|
||||
rendered.string.should.match(paginationRegex);
|
||||
@ -726,7 +732,9 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('can render first page of many with older posts link', function () {
|
||||
var rendered = helpers.pagination.call({pagination: {page: 1, prev: null, next: 2, limit: 15, total: 8, pages: 3}});
|
||||
var rendered = helpers.pagination.call({
|
||||
pagination: {page: 1, prev: null, next: 2, limit: 15, total: 8, pages: 3}
|
||||
});
|
||||
should.exist(rendered);
|
||||
|
||||
rendered.string.should.match(paginationRegex);
|
||||
@ -737,7 +745,9 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('can render middle pages of many with older and newer posts link', function () {
|
||||
var rendered = helpers.pagination.call({pagination: {page: 2, prev: 1, next: 3, limit: 15, total: 8, pages: 3}});
|
||||
var rendered = helpers.pagination.call({
|
||||
pagination: {page: 2, prev: 1, next: 3, limit: 15, total: 8, pages: 3}
|
||||
});
|
||||
should.exist(rendered);
|
||||
|
||||
rendered.string.should.match(paginationRegex);
|
||||
@ -748,7 +758,9 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
it('can render last page of many with newer posts link', function () {
|
||||
var rendered = helpers.pagination.call({pagination: {page: 3, prev: 2, next: null, limit: 15, total: 8, pages: 3}});
|
||||
var rendered = helpers.pagination.call({
|
||||
pagination: {page: 3, prev: 2, next: null, limit: 15, total: 8, pages: 3}
|
||||
});
|
||||
should.exist(rendered);
|
||||
|
||||
rendered.string.should.match(paginationRegex);
|
||||
@ -791,7 +803,7 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("tags helper", function () {
|
||||
describe('tags helper', function () {
|
||||
|
||||
it('has loaded tags helper', function () {
|
||||
should.exist(handlebars.helpers.tags);
|
||||
@ -801,7 +813,7 @@ describe('Core Helpers', function () {
|
||||
var tags = [{name: 'foo'}, {name: 'bar'}],
|
||||
rendered = handlebars.helpers.tags.call(
|
||||
{tags: tags},
|
||||
{"hash": {autolink: 'false'}}
|
||||
{'hash': {autolink: 'false'}}
|
||||
);
|
||||
should.exist(rendered);
|
||||
|
||||
@ -812,7 +824,7 @@ describe('Core Helpers', function () {
|
||||
var tags = [{name: 'haunted'}, {name: 'ghost'}],
|
||||
rendered = handlebars.helpers.tags.call(
|
||||
{tags: tags},
|
||||
{"hash": {separator: '|', autolink: 'false'}}
|
||||
{'hash': {separator: '|', autolink: 'false'}}
|
||||
);
|
||||
|
||||
should.exist(rendered);
|
||||
@ -824,7 +836,7 @@ describe('Core Helpers', function () {
|
||||
var tags = [{name: 'haunted'}, {name: 'ghost'}],
|
||||
rendered = handlebars.helpers.tags.call(
|
||||
{tags: tags},
|
||||
{"hash": {prefix: 'on ', autolink: 'false'}}
|
||||
{'hash': {prefix: 'on ', autolink: 'false'}}
|
||||
);
|
||||
|
||||
should.exist(rendered);
|
||||
@ -836,7 +848,7 @@ describe('Core Helpers', function () {
|
||||
var tags = [{name: 'haunted'}, {name: 'ghost'}],
|
||||
rendered = handlebars.helpers.tags.call(
|
||||
{tags: tags},
|
||||
{"hash": {suffix: ' forever', autolink: 'false'}}
|
||||
{'hash': {suffix: ' forever', autolink: 'false'}}
|
||||
);
|
||||
|
||||
should.exist(rendered);
|
||||
@ -848,7 +860,7 @@ describe('Core Helpers', function () {
|
||||
var tags = [{name: 'haunted'}, {name: 'ghost'}],
|
||||
rendered = handlebars.helpers.tags.call(
|
||||
{tags: tags},
|
||||
{"hash": {suffix: ' forever', prefix: 'on ', autolink: 'false'}}
|
||||
{'hash': {suffix: ' forever', prefix: 'on ', autolink: 'false'}}
|
||||
);
|
||||
|
||||
should.exist(rendered);
|
||||
@ -860,7 +872,7 @@ describe('Core Helpers', function () {
|
||||
var tags = [{name: 'haunted'}, {name: 'ghost'}],
|
||||
rendered = handlebars.helpers.tags.call(
|
||||
{tags: tags},
|
||||
{"hash": {suffix: ' •', prefix: '… ', autolink: 'false'}}
|
||||
{'hash': {suffix: ' •', prefix: '… ', autolink: 'false'}}
|
||||
);
|
||||
|
||||
should.exist(rendered);
|
||||
@ -871,7 +883,7 @@ describe('Core Helpers', function () {
|
||||
it('does not add prefix or suffix if no tags exist', function () {
|
||||
var rendered = handlebars.helpers.tags.call(
|
||||
{},
|
||||
{"hash": {prefix: 'on ', suffix: ' forever', autolink: 'false'}}
|
||||
{'hash': {prefix: 'on ', suffix: ' forever', autolink: 'false'}}
|
||||
);
|
||||
|
||||
should.exist(rendered);
|
||||
@ -883,7 +895,7 @@ describe('Core Helpers', function () {
|
||||
var tags = [{name: 'foo', slug: 'foo-bar'}, {name: 'bar', slug: 'bar'}],
|
||||
rendered = handlebars.helpers.tags.call(
|
||||
{tags: tags},
|
||||
{"hash": {}}
|
||||
{'hash': {}}
|
||||
);
|
||||
should.exist(rendered);
|
||||
|
||||
@ -891,7 +903,7 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("meta_title helper", function () {
|
||||
describe('meta_title helper', function () {
|
||||
|
||||
it('has loaded meta_title helper', function () {
|
||||
should.exist(handlebars.helpers.meta_title);
|
||||
@ -915,7 +927,7 @@ describe('Core Helpers', function () {
|
||||
done();
|
||||
}).then(null, done);
|
||||
});
|
||||
|
||||
|
||||
it('can return escaped title of a post', function (done) {
|
||||
var post = {relativeUrl: '/nice-escaped-post', post: {title: 'Post Title "</>'}};
|
||||
helpers.meta_title.call(post).then(function (rendered) {
|
||||
@ -937,7 +949,7 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("meta_description helper", function () {
|
||||
describe('meta_description helper', function () {
|
||||
|
||||
it('has loaded meta_description helper', function () {
|
||||
should.exist(handlebars.helpers.meta_description);
|
||||
@ -951,7 +963,7 @@ describe('Core Helpers', function () {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
|
||||
it('can return empty description on post', function (done) {
|
||||
var post = {relativeUrl: '/nice-post', post: {title: 'Post Title'}};
|
||||
helpers.meta_description.call(post).then(function (rendered) {
|
||||
@ -964,7 +976,7 @@ describe('Core Helpers', function () {
|
||||
|
||||
});
|
||||
|
||||
describe("asset helper", function () {
|
||||
describe('asset helper', function () {
|
||||
var rendered,
|
||||
configOriginal;
|
||||
|
||||
@ -985,9 +997,9 @@ describe('Core Helpers', function () {
|
||||
should.exist(handlebars.helpers.asset);
|
||||
});
|
||||
|
||||
it("handles favicon correctly", function () {
|
||||
it('handles favicon correctly', function () {
|
||||
// with ghost set
|
||||
rendered = helpers.asset('favicon.ico', {"hash": {ghost: 'true'}});
|
||||
rendered = helpers.asset('favicon.ico', {'hash': {ghost: 'true'}});
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal('/favicon.ico');
|
||||
|
||||
@ -1001,7 +1013,7 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
// with subdirectory
|
||||
rendered = helpers.asset('favicon.ico', {"hash": {ghost: 'true'}});
|
||||
rendered = helpers.asset('favicon.ico', {'hash': {ghost: 'true'}});
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal('/blog/favicon.ico');
|
||||
|
||||
@ -1013,7 +1025,7 @@ describe('Core Helpers', function () {
|
||||
|
||||
it('handles shared assets correctly', function () {
|
||||
// with ghost set
|
||||
rendered = helpers.asset('shared/asset.js', {"hash": {ghost: 'true'}});
|
||||
rendered = helpers.asset('shared/asset.js', {'hash': {ghost: 'true'}});
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal('/shared/asset.js?v=abc');
|
||||
|
||||
@ -1027,7 +1039,7 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
// with subdirectory
|
||||
rendered = helpers.asset('shared/asset.js', {"hash": {ghost: 'true'}});
|
||||
rendered = helpers.asset('shared/asset.js', {'hash': {ghost: 'true'}});
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal('/blog/shared/asset.js?v=abc');
|
||||
|
||||
@ -1039,7 +1051,7 @@ describe('Core Helpers', function () {
|
||||
|
||||
it('handles admin assets correctly', function () {
|
||||
// with ghost set
|
||||
rendered = helpers.asset('js/asset.js', {"hash": {ghost: 'true'}});
|
||||
rendered = helpers.asset('js/asset.js', {'hash': {ghost: 'true'}});
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal('/ghost/js/asset.js?v=abc');
|
||||
|
||||
@ -1048,7 +1060,7 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
// with subdirectory
|
||||
rendered = helpers.asset('js/asset.js', {"hash": {ghost: 'true'}});
|
||||
rendered = helpers.asset('js/asset.js', {'hash': {ghost: 'true'}});
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal('/blog/ghost/js/asset.js?v=abc');
|
||||
});
|
||||
@ -1081,7 +1093,7 @@ describe('Core Helpers', function () {
|
||||
// to test the output of the helper against static strings instead
|
||||
// of calling moment(). Without timezone support the output of this
|
||||
// helper may differ depending on what timezone the tests are run in.
|
||||
|
||||
|
||||
it('creates properly formatted date strings', function () {
|
||||
var testDates = [
|
||||
'2013-12-31T11:28:58.593Z',
|
||||
@ -1205,7 +1217,7 @@ describe('Core Helpers', function () {
|
||||
context = 'hello world this is ghost'.split(' ');
|
||||
|
||||
rendered = helpers.foreach.call(_this, context, options);
|
||||
rendered.should.equal('hello\n\world\nthis\nis\nghost\n');
|
||||
rendered.should.equal('hello\nworld\nthis\nis\nghost\n');
|
||||
|
||||
// test with context as an object
|
||||
|
||||
@ -1218,7 +1230,7 @@ describe('Core Helpers', function () {
|
||||
};
|
||||
|
||||
rendered = helpers.foreach.call(_this, context, options);
|
||||
rendered.should.equal('hello\n\world\nthis\nis\nghost\n');
|
||||
rendered.should.equal('hello\nworld\nthis\nis\nghost\n');
|
||||
});
|
||||
|
||||
it('should return the correct result when private data is supplied', function () {
|
||||
@ -1249,7 +1261,7 @@ describe('Core Helpers', function () {
|
||||
result[4].should.equal('ghost,false,false,false,true,false,true');
|
||||
});
|
||||
|
||||
it('should return the correct result when private data is supplied and there are multiple columns', function () {
|
||||
it('should return the correct result when private data is supplied & there are multiple columns', function () {
|
||||
var options = {},
|
||||
context = [],
|
||||
_this = {},
|
||||
@ -1327,7 +1339,7 @@ describe('Core Helpers', function () {
|
||||
var args = arguments;
|
||||
return function () {
|
||||
helperMissing.apply(null, args);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
runHelper('test helper').should.not.throwError();
|
||||
@ -1336,7 +1348,7 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
// ## Admin only helpers
|
||||
describe("ghostScriptTags helper", function () {
|
||||
describe('ghostScriptTags helper', function () {
|
||||
var rendered,
|
||||
configOriginal;
|
||||
|
||||
@ -1431,26 +1443,26 @@ describe('Core Helpers', function () {
|
||||
// no trailing slash
|
||||
configUpdate({url: 'http://testurl.com'});
|
||||
|
||||
rendered = helpers.admin_url({"hash": {absolute: true}});
|
||||
rendered = helpers.admin_url({'hash': {absolute: true}});
|
||||
should.exist(rendered);
|
||||
rendered.should.equal('http://testurl.com/ghost');
|
||||
|
||||
// test trailing slash
|
||||
configUpdate({url: 'http://testurl.com/'});
|
||||
rendered = helpers.admin_url({"hash": {absolute: true}});
|
||||
rendered = helpers.admin_url({'hash': {absolute: true}});
|
||||
should.exist(rendered);
|
||||
rendered.should.equal('http://testurl.com/ghost');
|
||||
});
|
||||
|
||||
it('should output absolute path with subdirectory', function () {
|
||||
configUpdate({url: 'http://testurl.com/blog'});
|
||||
rendered = helpers.admin_url({"hash": {absolute: true}});
|
||||
rendered = helpers.admin_url({'hash': {absolute: true}});
|
||||
should.exist(rendered);
|
||||
rendered.should.equal('http://testurl.com/blog/ghost');
|
||||
});
|
||||
|
||||
it('should output the path to frontend if frontend is set', function () {
|
||||
rendered = helpers.admin_url({"hash": {frontend: true}});
|
||||
rendered = helpers.admin_url({'hash': {frontend: true}});
|
||||
should.exist(rendered);
|
||||
rendered.should.equal('/');
|
||||
});
|
||||
@ -1458,32 +1470,32 @@ describe('Core Helpers', function () {
|
||||
it('should output the absolute path to frontend if both are set', function () {
|
||||
configUpdate({url: 'http://testurl.com'});
|
||||
|
||||
rendered = helpers.admin_url({"hash": {frontend: true, absolute: true}});
|
||||
rendered = helpers.admin_url({'hash': {frontend: true, absolute: true}});
|
||||
should.exist(rendered);
|
||||
rendered.should.equal('http://testurl.com/');
|
||||
|
||||
configUpdate({url: 'http://testurl.com/'});
|
||||
rendered = helpers.admin_url({"hash": {frontend: true, absolute: true}});
|
||||
rendered = helpers.admin_url({'hash': {frontend: true, absolute: true}});
|
||||
should.exist(rendered);
|
||||
rendered.should.equal('http://testurl.com/');
|
||||
});
|
||||
|
||||
it('should output the path to frontend with subdirectory', function () {
|
||||
configUpdate({url: 'http://testurl.com/blog/'});
|
||||
rendered = helpers.admin_url({"hash": {frontend: true}});
|
||||
rendered = helpers.admin_url({'hash': {frontend: true}});
|
||||
should.exist(rendered);
|
||||
rendered.should.equal('/blog/');
|
||||
});
|
||||
|
||||
it('should output the absolute path to frontend with subdirectory', function () {
|
||||
configUpdate({url: 'http://testurl.com/blog/'});
|
||||
rendered = helpers.admin_url({"hash": {frontend: true, absolute: true}});
|
||||
rendered = helpers.admin_url({'hash': {frontend: true, absolute: true}});
|
||||
should.exist(rendered);
|
||||
rendered.should.equal('http://testurl.com/blog/');
|
||||
});
|
||||
});
|
||||
describe('updateNotification', function () {
|
||||
it('outputs a correctly formatted notification when db version is higher than package version', function (done) {
|
||||
it('outputs a correctly formatted notification when db version is higher than pkg version', function (done) {
|
||||
var defaultOutput = '<div class="notification-success">' +
|
||||
'A new version of Ghost is available! Hot damn. ' +
|
||||
'<a href="http://ghost.org/download">Upgrade now</a></div>',
|
||||
@ -1514,7 +1526,7 @@ describe('Core Helpers', function () {
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('does NOT output a correctly formatted notification when db version equals package version', function (done) {
|
||||
it('does NOT output a correctly formatted notification when db version equals pkg version', function (done) {
|
||||
apiStub.restore();
|
||||
apiStub = sandbox.stub(api.settings, 'read', function () {
|
||||
return when({ settings: [{value: packageInfo.version}] });
|
||||
@ -1581,7 +1593,7 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
_.extend(cfg, configStub);
|
||||
|
||||
|
||||
helpers.__set__('config', cfg);
|
||||
|
||||
fileStorage = helpers.file_storage();
|
||||
@ -1614,7 +1626,7 @@ describe('Core Helpers', function () {
|
||||
});
|
||||
|
||||
_.extend(cfg, configStub);
|
||||
|
||||
|
||||
helpers.__set__('config', cfg);
|
||||
|
||||
apps = helpers.apps();
|
||||
|
@ -1,20 +1,14 @@
|
||||
/*globals describe, beforeEach, it*/
|
||||
var testUtils = require('../utils'),
|
||||
should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
_ = require('lodash'),
|
||||
path = require('path'),
|
||||
/*globals describe, it*/
|
||||
/*jshint expr:true*/
|
||||
var should = require('should'),
|
||||
hbs = require('express-hbs'),
|
||||
|
||||
// Stuff we are testing
|
||||
config = require('../../server/config'),
|
||||
api = require('../../server/api'),
|
||||
template = require('../../server/helpers/template');
|
||||
|
||||
describe('Helpers Template', function () {
|
||||
|
||||
it("can execute a template", function () {
|
||||
it('can execute a template', function () {
|
||||
hbs.registerPartial('test', '<h1>Hello {{name}}</h1>');
|
||||
|
||||
var safeString = template.execute('test', {name: 'world'});
|
||||
|
@ -1,9 +1,7 @@
|
||||
/*globals describe, beforeEach, it*/
|
||||
var net = require('net'),
|
||||
assert = require('assert'),
|
||||
should = require('should'),
|
||||
/*globals describe, it*/
|
||||
/*jshint expr:true*/
|
||||
var should = require('should'),
|
||||
request = require('request'),
|
||||
server = require('../../server'),
|
||||
config = require('../../../config');
|
||||
|
||||
describe('Server', function () {
|
||||
@ -14,10 +12,10 @@ describe('Server', function () {
|
||||
|
||||
it('should not start a connect server when required', function (done) {
|
||||
request(url, function (error, response, body) {
|
||||
assert.equal(response, undefined);
|
||||
assert.equal(body, undefined);
|
||||
assert.notEqual(error, undefined);
|
||||
assert.equal(error.code, 'ECONNREFUSED');
|
||||
should(response).equal(undefined);
|
||||
should(body).equal(undefined);
|
||||
should(error).not.equal(undefined);
|
||||
should(error.code).equal('ECONNREFUSED');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -5,8 +5,8 @@
|
||||
*/
|
||||
|
||||
/*globals describe, it */
|
||||
var testUtils = require('../utils'),
|
||||
should = require('should'),
|
||||
/*jshint expr:true*/
|
||||
var should = require('should'),
|
||||
|
||||
// Stuff we are testing
|
||||
Showdown = require('showdown'),
|
||||
@ -15,43 +15,46 @@ var testUtils = require('../utils'),
|
||||
|
||||
converter = new Showdown.converter({extensions: [ghostimagepreview, ghostgfm]});
|
||||
|
||||
describe("Showdown client side converter", function () {
|
||||
// To stop jshint complaining
|
||||
should.equal(true, true);
|
||||
|
||||
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>$/},
|
||||
it('should replace showdown strike through with html', function () {
|
||||
var testPhrase = {input: '~~foo_bar~~', output: /^<p><del>foo_bar<\/del><\/p>$/},
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
|
||||
// The image is the entire markup, so the image box should be too
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
|
||||
it("should not touch single underscores inside words", function () {
|
||||
var testPhrase = {input: "foo_bar", output: /^<p>foo_bar<\/p>$/},
|
||||
it('should not touch single underscores inside words', function () {
|
||||
var testPhrase = {input: 'foo_bar', output: /^<p>foo_bar<\/p>$/},
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
|
||||
// Currently failing - fixing this causes other issues
|
||||
// it("should not create italic words between lines", function () {
|
||||
// var testPhrase = {input: "foo_bar\nbar_foo", output: /^<p>foo_bar <br \/>\nbar_foo<\/p>$/},
|
||||
// it('should not create italic words between lines', function () {
|
||||
// var testPhrase = {input: 'foo_bar\nbar_foo', output: /^<p>foo_bar <br \/>\nbar_foo<\/p>$/},
|
||||
// processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
//
|
||||
// processedMarkup.should.match(testPhrase.output);
|
||||
// });
|
||||
|
||||
it("should not touch underscores in code blocks", function () {
|
||||
var testPhrase = {input: " foo_bar_baz", output: /^<pre><code>foo_bar_baz\n<\/code><\/pre>$/},
|
||||
it('should not touch underscores in code blocks', function () {
|
||||
var testPhrase = {input: ' foo_bar_baz', output: /^<pre><code>foo_bar_baz\n<\/code><\/pre>$/},
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
|
||||
it("should not touch underscores in pre blocks", function () {
|
||||
it('should not touch underscores in pre blocks', function () {
|
||||
var testPhrases = [
|
||||
{input: "<pre>\nfoo_bar_baz\n</pre>", output: /^<pre>\nfoo_bar_baz\n<\/pre>$/},
|
||||
{input: "<pre>foo_bar_baz</pre>", output: /^<pre>foo_bar_baz<\/pre>$/}
|
||||
{input: '<pre>\nfoo_bar_baz\n</pre>', output: /^<pre>\nfoo_bar_baz\n<\/pre>$/},
|
||||
{input: '<pre>foo_bar_baz</pre>', output: /^<pre>foo_bar_baz<\/pre>$/}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
@ -61,9 +64,9 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should not escape double underscores at the beginning of a line", function () {
|
||||
it('should not escape double underscores at the beginning of a line', function () {
|
||||
var testPhrases = [
|
||||
{input: "\n__test__\n", output: /^<p><strong>test<\/strong><\/p>$/}
|
||||
{input: '\n__test__\n', output: /^<p><strong>test<\/strong><\/p>$/}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
@ -73,10 +76,35 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should not treat pre blocks with pre-text differently", function () {
|
||||
it('should not treat pre blocks with pre-text differently', function () {
|
||||
var testPhrases = [
|
||||
{input: "<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n</pre>", output: /^<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n<\/pre>$/},
|
||||
{input: "hmm<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n</pre>", output: /^<p>hmm<\/p>\n\n<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n<\/pre>$/}
|
||||
{
|
||||
input: '<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n</pre>',
|
||||
output: /^<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n<\/pre>$/
|
||||
},
|
||||
{
|
||||
input: 'hmm<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n</pre>',
|
||||
output: /^<p>hmm<\/p>\n\n<pre>\nthis is `a\\_test` and this\\_too and finally_this_is\n<\/pre>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
});
|
||||
|
||||
it('should escape two or more underscores inside words', function () {
|
||||
var testPhrases = [
|
||||
{input: 'foo_bar_baz', output: /^<p>foo_bar_baz<\/p>$/},
|
||||
{input: 'foo_bar_baz_bat', output: /^<p>foo_bar_baz_bat<\/p>$/},
|
||||
{input: 'foo_bar_baz_bat_boo', output: /^<p>foo_bar_baz_bat_boo<\/p>$/},
|
||||
{input: 'FOO_BAR', output: /^<p>FOO_BAR<\/p>$/},
|
||||
{input: 'FOO_BAR_BAZ', output: /^<p>FOO_BAR_BAZ<\/p>$/},
|
||||
{input: 'FOO_bar_BAZ_bat', output: /^<p>FOO_bar_BAZ_bat<\/p>$/},
|
||||
{input: 'FOO_bar_BAZ_bat_BOO', output: /^<p>FOO_bar_BAZ_bat_BOO<\/p>$/},
|
||||
{input: 'foo_BAR_baz_BAT_boo', output: /^<p>foo_BAR_baz_BAT_boo<\/p>$/}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
@ -86,16 +114,12 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should escape two or more underscores inside words", function () {
|
||||
it('should turn newlines into br tags in simple cases', function () {
|
||||
var testPhrases = [
|
||||
{input: "foo_bar_baz", output: /^<p>foo_bar_baz<\/p>$/},
|
||||
{input: "foo_bar_baz_bat", output: /^<p>foo_bar_baz_bat<\/p>$/},
|
||||
{input: "foo_bar_baz_bat_boo", output: /^<p>foo_bar_baz_bat_boo<\/p>$/},
|
||||
{input: "FOO_BAR", output: /^<p>FOO_BAR<\/p>$/},
|
||||
{input: "FOO_BAR_BAZ", output: /^<p>FOO_BAR_BAZ<\/p>$/},
|
||||
{input: "FOO_bar_BAZ_bat", output: /^<p>FOO_bar_BAZ_bat<\/p>$/},
|
||||
{input: "FOO_bar_BAZ_bat_BOO", output: /^<p>FOO_bar_BAZ_bat_BOO<\/p>$/},
|
||||
{input: "foo_BAR_baz_BAT_boo", output: /^<p>foo_BAR_baz_BAT_boo<\/p>$/}
|
||||
{input: 'fizz\nbuzz', output: /^<p>fizz <br \/>\nbuzz<\/p>$/},
|
||||
{input: 'Hello world\nIt is a fine day', output: /^<p>Hello world <br \/>\nIt is a fine day<\/p>$/},
|
||||
{input: '\'first\nsecond', output: /^<p>\'first <br \/>\nsecond<\/p>$/},
|
||||
{input: '\'first\nsecond', output: /^<p>\'first <br \/>\nsecond<\/p>$/}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
@ -105,14 +129,18 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should turn newlines into br tags in simple cases", function () {
|
||||
it('should convert newlines in all groups', function () {
|
||||
var testPhrases = [
|
||||
{input: "fizz\nbuzz", output: /^<p>fizz <br \/>\nbuzz<\/p>$/},
|
||||
{input: "Hello world\nIt is a fine day", output: /^<p>Hello world <br \/>\nIt is a fine day<\/p>$/},
|
||||
{input: "\"first\nsecond", output: /^<p>\"first <br \/>\nsecond<\/p>$/},
|
||||
{input: "\'first\nsecond", output: /^<p>\'first <br \/>\nsecond<\/p>$/}
|
||||
],
|
||||
processedMarkup;
|
||||
{
|
||||
input: 'ruby\npython\nerlang',
|
||||
output: /^<p>ruby <br \/>\npython <br \/>\nerlang<\/p>$/
|
||||
},
|
||||
{
|
||||
input: 'Hello world\nIt is a fine day\nout',
|
||||
output: /^<p>Hello world <br \/>\nIt is a fine day <br \/>\nout<\/p>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
@ -120,27 +148,14 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should convert newlines in all groups", function () {
|
||||
var testPhrases = [
|
||||
{input: "ruby\npython\nerlang", output: /^<p>ruby <br \/>\npython <br \/>\nerlang<\/p>$/},
|
||||
{input: "Hello world\nIt is a fine day\nout", output: /^<p>Hello world <br \/>\nIt is a fine day <br \/>\nout<\/p>$/}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
});
|
||||
|
||||
it("should convert newlines in even long groups", function () {
|
||||
it('should convert newlines in even long groups', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "ruby\npython\nerlang\ngo",
|
||||
input: 'ruby\npython\nerlang\ngo',
|
||||
output: /^<p>ruby <br \/>\npython <br \/>\nerlang <br \/>\ngo<\/p>$/
|
||||
},
|
||||
{
|
||||
input: "Hello world\nIt is a fine day\noutside\nthe window",
|
||||
input: 'Hello world\nIt is a fine day\noutside\nthe window',
|
||||
output: /^<p>Hello world <br \/>\nIt is a fine day <br \/>\noutside <br \/>\nthe window<\/p>$/
|
||||
}
|
||||
],
|
||||
@ -152,14 +167,14 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should not convert newlines in lists", function () {
|
||||
it('should not convert newlines in lists', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "#fizz\n# buzz\n### baz",
|
||||
input: '#fizz\n# buzz\n### baz',
|
||||
output: /^<h1 id="fizz">fizz<\/h1>\n\n<h1 id="buzz">buzz<\/h1>\n\n<h3 id="baz">baz<\/h3>$/
|
||||
},
|
||||
{
|
||||
input: "* foo\n* bar",
|
||||
input: '* foo\n* bar',
|
||||
output: /^<ul>\n<li>foo<\/li>\n<li>bar<\/li>\n<\/ul>$/
|
||||
}
|
||||
],
|
||||
@ -171,46 +186,46 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should auto-link URL in text with markdown syntax", function () {
|
||||
it('should auto-link URL in text with markdown syntax', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "http://google.co.uk",
|
||||
output: /^<p><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: "https://atest.com/fizz/buzz?baz=fizzbuzz",
|
||||
output: /^<p><a href=\'https:\/\/atest.com\/fizz\/buzz\?baz=fizzbuzz\'>https:\/\/atest.com\/fizz\/buzz\?baz=fizzbuzz<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: "Some [ text (http://www.google.co.uk) some other text",
|
||||
output: /^<p>Some \[ text \(<a href=\'http:\/\/www.google.co.uk\'>http:\/\/www.google.co.uk<\/a>\) some other text<\/p>$/
|
||||
},
|
||||
{
|
||||
input: ">http://google.co.uk",
|
||||
output: /^<blockquote>\n <p><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/p>\n<\/blockquote>$/
|
||||
},
|
||||
{
|
||||
input: "> http://google.co.uk",
|
||||
output: /^<blockquote>\n <p><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/p>\n<\/blockquote>$/
|
||||
},
|
||||
{
|
||||
input: "<>>> http://google.co.uk",
|
||||
output: /^<p><>>> <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: "<strong>http://google.co.uk",
|
||||
output: /^<p><strong><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: "# http://google.co.uk",
|
||||
output: /^<h1 id="httpgooglecouk"><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/h1>$/
|
||||
},
|
||||
{
|
||||
input: "* http://google.co.uk",
|
||||
output: /^<ul>\n<li><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/li>\n<\/ul>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
{
|
||||
input: 'http://google.co.uk',
|
||||
output: /^<p><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: 'https://atest.com/fizz/buzz?baz=fizzbuzz',
|
||||
output: /^<p><a href=\'https:\/\/atest.com\/fizz\/buzz\?baz=fizzbuzz\'>https:\/\/atest.com\/fizz\/buzz\?baz=fizzbuzz<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: 'Some [ text (http://www.google.co.uk) some other text',
|
||||
output: /^<p>Some \[ text \(<a href=\'http:\/\/www.google.co.uk\'>http:\/\/www.google.co.uk<\/a>\) some other text<\/p>$/
|
||||
},
|
||||
{
|
||||
input: '>http://google.co.uk',
|
||||
output: /^<blockquote>\n <p><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/p>\n<\/blockquote>$/
|
||||
},
|
||||
{
|
||||
input: '> http://google.co.uk',
|
||||
output: /^<blockquote>\n <p><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/p>\n<\/blockquote>$/
|
||||
},
|
||||
{
|
||||
input: '<>>> http://google.co.uk',
|
||||
output: /^<p><>>> <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: '<strong>http://google.co.uk',
|
||||
output: /^<p><strong><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: '# http://google.co.uk',
|
||||
output: /^<h1 id="httpgooglecouk"><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/h1>$/
|
||||
},
|
||||
{
|
||||
input: '* http://google.co.uk',
|
||||
output: /^<ul>\n<li><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/li>\n<\/ul>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
@ -218,22 +233,22 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should convert reference format URL", function () {
|
||||
it('should convert reference format URL', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "[Google][1]\n\n[1]: http://google.co.uk",
|
||||
output: /^<p><a href="http:\/\/google.co.uk">Google<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: "[Google][1]\n\n[1]: http://google.co.uk \"some text\"",
|
||||
output: /^<p><a href="http:\/\/google.co.uk" title="some text">Google<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: "[http://google.co.uk]: http://google.co.uk\n\n[Hello][http://google.co.uk]",
|
||||
output: /^<p><a href="http:\/\/google.co.uk">Hello<\/a><\/p>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
{
|
||||
input: '[Google][1]\n\n[1]: http://google.co.uk',
|
||||
output: /^<p><a href="http:\/\/google.co.uk">Google<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: '[Google][1]\n\n[1]: http://google.co.uk \"some text\"',
|
||||
output: /^<p><a href="http:\/\/google.co.uk" title="some text">Google<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: '[http://google.co.uk]: http://google.co.uk\n\n[Hello][http://google.co.uk]',
|
||||
output: /^<p><a href="http:\/\/google.co.uk">Hello<\/a><\/p>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
@ -242,18 +257,18 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
|
||||
/* No ref-style for now
|
||||
it("should convert reference format image", function () {
|
||||
it('should convert reference format image', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "![Google][1]\n\n[1]: http://dsurl.stuff/something.jpg",
|
||||
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\"",
|
||||
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]",
|
||||
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>$/
|
||||
}
|
||||
],
|
||||
@ -266,30 +281,30 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
*/
|
||||
|
||||
it("should NOT auto-link URL in HTML", function () {
|
||||
it('should NOT auto-link URL in HTML', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: '<img src="http://placekitten.com/50">',
|
||||
output: /^<p><img src=\"http:\/\/placekitten.com\/50\"><\/p>$/
|
||||
},
|
||||
{
|
||||
input: '<img src="http://placekitten.com/50" />',
|
||||
output: /^<p><img src=\"http:\/\/placekitten.com\/50\" \/><\/p>$/
|
||||
},
|
||||
{
|
||||
input: '<script type="text/javascript" src="http://google.co.uk"></script>',
|
||||
output: /^<script type=\"text\/javascript\" src=\"http:\/\/google.co.uk\"><\/script>$/
|
||||
},
|
||||
{
|
||||
input: '<a href="http://facebook.com">http://google.co.uk</a>',
|
||||
output: /^<p><a href=\"http:\/\/facebook.com\">http:\/\/google.co.uk<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: '<a href="http://facebook.com">test</a> http://google.co.uk',
|
||||
output: /^<p><a href=\"http:\/\/facebook.com\">test<\/a> <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/p>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
{
|
||||
input: '<img src="http://placekitten.com/50">',
|
||||
output: /^<p><img src=\"http:\/\/placekitten.com\/50\"><\/p>$/
|
||||
},
|
||||
{
|
||||
input: '<img src="http://placekitten.com/50" />',
|
||||
output: /^<p><img src=\"http:\/\/placekitten.com\/50\" \/><\/p>$/
|
||||
},
|
||||
{
|
||||
input: '<script type="text/javascript" src="http://google.co.uk"></script>',
|
||||
output: /^<script type=\"text\/javascript\" src=\"http:\/\/google.co.uk\"><\/script>$/
|
||||
},
|
||||
{
|
||||
input: '<a href="http://facebook.com">http://google.co.uk</a>',
|
||||
output: /^<p><a href=\"http:\/\/facebook.com\">http:\/\/google.co.uk<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: '<a href="http://facebook.com">test</a> http://google.co.uk',
|
||||
output: /^<p><a href=\"http:\/\/facebook.com\">test<\/a> <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a><\/p>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
@ -297,9 +312,9 @@ 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```",
|
||||
input: '```\n_____\n```',
|
||||
output: /^<pre><code>_____ \n<\/code><\/pre>$/
|
||||
},
|
||||
processedMarkup;
|
||||
@ -308,21 +323,71 @@ describe("Showdown client side converter", function () {
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
|
||||
it("should NOT auto-link URLS inside of code/pre blocks", function () {
|
||||
it('should NOT auto-link URLS inside of code/pre blocks', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "```\nurl: http://google.co.uk\n```",
|
||||
output: /^<pre><code>url: http:\/\/google.co.uk \n<\/code><\/pre>$/
|
||||
},
|
||||
{
|
||||
input: "`url: http://google.co.uk`",
|
||||
output: /^<p><code>url: http:\/\/google.co.uk<\/code><\/p>$/
|
||||
},
|
||||
{
|
||||
input: "Hello type some `url: http://google.co.uk` stuff",
|
||||
output: /^<p>Hello type some <code>url: http:\/\/google.co.uk<\/code> stuff<\/p>$/
|
||||
}
|
||||
{
|
||||
input: '```\nurl: http://google.co.uk\n```',
|
||||
output: /^<pre><code>url: http:\/\/google.co.uk \n<\/code><\/pre>$/
|
||||
},
|
||||
{
|
||||
input: '`url: http://google.co.uk`',
|
||||
output: /^<p><code>url: http:\/\/google.co.uk<\/code><\/p>$/
|
||||
},
|
||||
{
|
||||
input: 'Hello type some `url: http://google.co.uk` stuff',
|
||||
output: /^<p>Hello type some <code>url: http:\/\/google.co.uk<\/code> stuff<\/p>$/
|
||||
}
|
||||
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not display anything for reference URL', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: '[1]: http://www.google.co.uk',
|
||||
output: /^$/
|
||||
},
|
||||
{
|
||||
input: '[http://www.google.co.uk]: http://www.google.co.uk',
|
||||
output: /^$/
|
||||
},
|
||||
{
|
||||
input: '[1]: http://dsurl.stuff/something.jpg',
|
||||
output: /^$/
|
||||
},
|
||||
{
|
||||
input: '[1]:http://www.google.co.uk',
|
||||
output: /^$/
|
||||
},
|
||||
{
|
||||
input: ' [1]:http://www.google.co.uk',
|
||||
output: /^$/
|
||||
},
|
||||
{
|
||||
input: '',
|
||||
output: /^$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
});
|
||||
|
||||
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]', output: /^<section.*?section>\n*$/},
|
||||
{input: '![]()', output: /^<section.*?section>\n*$/},
|
||||
{input: '![]', output: /^<section.*?section>\n*$/}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
@ -332,68 +397,18 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should not display anything for reference URL", function () {
|
||||
it('should have placeholder with image ONLY if image URL is present and valid', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "[1]: http://www.google.co.uk",
|
||||
output: /^$/
|
||||
},
|
||||
{
|
||||
input: "[http://www.google.co.uk]: http://www.google.co.uk",
|
||||
output: /^$/
|
||||
},
|
||||
{
|
||||
input: "[1]: http://dsurl.stuff/something.jpg",
|
||||
output: /^$/
|
||||
},
|
||||
{
|
||||
input: "[1]:http://www.google.co.uk",
|
||||
output: /^$/
|
||||
},
|
||||
{
|
||||
input: " [1]:http://www.google.co.uk",
|
||||
output: /^$/
|
||||
},
|
||||
{
|
||||
input: "",
|
||||
output: /^$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
});
|
||||
|
||||
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]", output: /^<section.*?section>\n*$/},
|
||||
{input: "![]()", output: /^<section.*?section>\n*$/},
|
||||
{input: "![]", output: /^<section.*?section>\n*$/}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
});
|
||||
|
||||
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>$/},
|
||||
{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;
|
||||
|
||||
@ -408,16 +423,16 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
|
||||
/* No ref-style for now
|
||||
it("should have placeholder with image if image reference is present", function () {
|
||||
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",
|
||||
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}
|
||||
{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;
|
||||
|
||||
@ -432,34 +447,34 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
*/
|
||||
|
||||
it("should correctly output link and image markdown without autolinks", function () {
|
||||
it('should correctly output link and image markdown without autolinks', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "[1](http://google.co.uk)",
|
||||
output: /^<p><a href="http:\/\/google.co.uk">1<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: " [1](http://google.co.uk)",
|
||||
output: /^<p><a href="http:\/\/google.co.uk">1<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: "[http://google.co.uk](http://google.co.uk)",
|
||||
output: /^<p><a href="http:\/\/google.co.uk">http:\/\/google.co.uk<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: "[http://google.co.uk][id]\n\n[id]: http://google.co.uk",
|
||||
output: /^<p><a href="http:\/\/google.co.uk">http:\/\/google.co.uk<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: "![http://google.co.uk/kitten.jpg](http://google.co.uk/kitten.jpg)",
|
||||
output: /^<section.*?((?!<a href=\'http:\/\/google.co.uk\/kitten.jpg\').)*<\/section>$/
|
||||
},
|
||||
{
|
||||
input: "![image stuff](http://dsurl.stuff/something)",
|
||||
output: /^<section.*?((?!<a href=\'http:\/\/dsurl.stuff\/something\').)*<\/section>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
{
|
||||
input: '[1](http://google.co.uk)',
|
||||
output: /^<p><a href="http:\/\/google.co.uk">1<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: ' [1](http://google.co.uk)',
|
||||
output: /^<p><a href="http:\/\/google.co.uk">1<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: '[http://google.co.uk](http://google.co.uk)',
|
||||
output: /^<p><a href="http:\/\/google.co.uk">http:\/\/google.co.uk<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: '[http://google.co.uk][id]\n\n[id]: http://google.co.uk',
|
||||
output: /^<p><a href="http:\/\/google.co.uk">http:\/\/google.co.uk<\/a><\/p>$/
|
||||
},
|
||||
{
|
||||
input: '![http://google.co.uk/kitten.jpg](http://google.co.uk/kitten.jpg)',
|
||||
output: /^<section.*?((?!<a href=\'http:\/\/google.co.uk\/kitten.jpg\').)*<\/section>$/
|
||||
},
|
||||
{
|
||||
input: '![image stuff](http://dsurl.stuff/something)',
|
||||
output: /^<section.*?((?!<a href=\'http:\/\/dsurl.stuff\/something\').)*<\/section>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
@ -467,34 +482,34 @@ describe("Showdown client side converter", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should output block HTML untouched", function () {
|
||||
it('should output block HTML untouched', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "<table class=\"test\">\n <tr>\n <td>Foo</td>\n </tr>\n <tr>\n <td>Bar</td>\n </tr>\n</table>",
|
||||
input: '<table class=\"test\">\n <tr>\n <td>Foo</td>\n </tr>\n <tr>\n <td>Bar</td>\n </tr>\n</table>',
|
||||
output: /^<table class=\"test\"> \n <tr>\n <td>Foo<\/td>\n <\/tr>\n <tr>\n <td>Bar<\/td>\n <\/tr>\n<\/table>$/
|
||||
},
|
||||
{
|
||||
input: "<hr />",
|
||||
input: '<hr />',
|
||||
output: /^<hr \/>$/
|
||||
},
|
||||
{ // audio isn't counted as a block tag by showdown so gets wrapped in <p></p>
|
||||
input: "<audio class=\"podcastplayer\" controls>\n <source src=\"foobar.mp3\" type=\"audio/mp3\" preload=\"none\"></source>\n <source src=\"foobar.off\" type=\"audio/ogg\" preload=\"none\"></source>\n</audio>",
|
||||
input: '<audio class=\"podcastplayer\" controls>\n <source src=\"foobar.mp3\" type=\"audio/mp3\" preload=\"none\"></source>\n <source src=\"foobar.off\" type=\"audio/ogg\" preload=\"none\"></source>\n</audio>',
|
||||
output: /^<audio class=\"podcastplayer\" controls> \n <source src=\"foobar.mp3\" type=\"audio\/mp3\" preload=\"none\"><\/source>\n <source src=\"foobar.off\" type=\"audio\/ogg\" preload=\"none\"><\/source>\n<\/audio>$/,
|
||||
}
|
||||
];
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
var processedMarkup = converter.makeHtml(testPhrase.input);
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Waiting for showdown typography to be updated
|
||||
// it("should correctly convert quotes to curly quotes", function () {
|
||||
// it('should correctly convert quotes to curly quotes', function () {
|
||||
// var testPhrases = [
|
||||
// {
|
||||
// input: "Hello world\nIt's a fine day\nout",
|
||||
// input: 'Hello world\nIt's a fine day\nout',
|
||||
// output: /^<p>Hello world <br \/>\nIt’s a fine day <br \/>\nout<\/p>$/}
|
||||
// ];
|
||||
//
|
||||
|
@ -4,12 +4,15 @@
|
||||
*/
|
||||
|
||||
/*globals describe, it */
|
||||
var testUtils = require('../utils'),
|
||||
should = require('should'),
|
||||
/*jshint expr:true*/
|
||||
var should = require('should'),
|
||||
|
||||
// Stuff we are testing
|
||||
ghostgfm = require('../../shared/lib/showdown/extensions/ghostgfm');
|
||||
|
||||
// To stop jshint complaining
|
||||
should.equal(true, true);
|
||||
|
||||
function _ExecuteExtension(ext, text) {
|
||||
if (ext.regex) {
|
||||
var re = new RegExp(ext.regex, 'g');
|
||||
@ -26,30 +29,30 @@ function _ConvertPhrase(testPhrase) {
|
||||
}
|
||||
|
||||
|
||||
describe("Ghost GFM showdown extension", function () {
|
||||
describe('Ghost GFM showdown extension', function () {
|
||||
/*jslint regexp: true */
|
||||
|
||||
it("should export an array of methods for processing", function () {
|
||||
it('should export an array of methods for processing', function () {
|
||||
ghostgfm.should.be.a.function;
|
||||
ghostgfm().should.be.an.Array;
|
||||
|
||||
ghostgfm().forEach(function (processor) {
|
||||
processor.should.be.an.Object;
|
||||
processor.should.have.property("type");
|
||||
processor.should.have.property('type');
|
||||
processor.type.should.be.a.String;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it("should replace showdown strike through with html", function () {
|
||||
var testPhrase = {input: "~T~Tfoo_bar~T~T", output: /<del>foo_bar<\/del>/},
|
||||
it('should replace showdown strike through with html', function () {
|
||||
var testPhrase = {input: '~T~Tfoo_bar~T~T', output: /<del>foo_bar<\/del>/},
|
||||
processedMarkup = _ConvertPhrase(testPhrase.input);
|
||||
|
||||
// The image is the entire markup, so the image box should be too
|
||||
processedMarkup.should.match(testPhrase.output);
|
||||
});
|
||||
|
||||
it("should allow 4 underscores", function () {
|
||||
it('should allow 4 underscores', function () {
|
||||
var testPhrase = {input: 'Ghost ____', output: /Ghost\s(?:_){4}$/},
|
||||
processedMarkup = _ConvertPhrase(testPhrase.input);
|
||||
|
||||
@ -57,70 +60,70 @@ describe("Ghost GFM showdown extension", function () {
|
||||
});
|
||||
|
||||
|
||||
it("should auto-link URL in text with markdown syntax", function () {
|
||||
it('should auto-link URL in text with markdown syntax', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "http://google.co.uk",
|
||||
output: /^<a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: "https://atest.com/fizz/buzz?baz=fizzbuzz",
|
||||
output: /^<a href=\'https:\/\/atest.com\/fizz\/buzz\?baz=fizzbuzz\'>https:\/\/atest.com\/fizz\/buzz\?baz=fizzbuzz<\/a>$/
|
||||
},
|
||||
{
|
||||
input: "Some text http://www.google.co.uk some other text",
|
||||
output: /^Some text <a href=\'http:\/\/www.google.co.uk\'>http:\/\/www.google.co.uk<\/a> some other text$/
|
||||
},
|
||||
{
|
||||
input: "Some [ text http://www.google.co.uk some other text",
|
||||
output: /^Some \[ text <a href=\'http:\/\/www.google.co.uk\'>http:\/\/www.google.co.uk<\/a> some other text$/
|
||||
},
|
||||
{
|
||||
input: "Some [ text (http://www.google.co.uk) some other text",
|
||||
output: /^Some \[ text \(<a href=\'http:\/\/www.google.co.uk\'>http:\/\/www.google.co.uk<\/a>\) some other text$/
|
||||
},
|
||||
{
|
||||
input: " http://google.co.uk ",
|
||||
output: /^ <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a> $/
|
||||
},
|
||||
{
|
||||
input: ">http://google.co.uk",
|
||||
output: /^><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: "> http://google.co.uk",
|
||||
output: /^> <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: "<>>> http://google.co.uk",
|
||||
output: /^<>>> <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: "<>>>http://google.co.uk",
|
||||
output: /^<>>><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: "<some text>>>http://google.co.uk",
|
||||
output: /^<some text>>><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: "<strong>http://google.co.uk",
|
||||
output: /^<strong><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: "# http://google.co.uk",
|
||||
output: /^# <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: "#http://google.co.uk",
|
||||
output: /^#<a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: "* http://google.co.uk",
|
||||
output: /^\* <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
{
|
||||
input: 'http://google.co.uk',
|
||||
output: /^<a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: 'https://atest.com/fizz/buzz?baz=fizzbuzz',
|
||||
output: /^<a href=\'https:\/\/atest.com\/fizz\/buzz\?baz=fizzbuzz\'>https:\/\/atest.com\/fizz\/buzz\?baz=fizzbuzz<\/a>$/
|
||||
},
|
||||
{
|
||||
input: 'Some text http://www.google.co.uk some other text',
|
||||
output: /^Some text <a href=\'http:\/\/www.google.co.uk\'>http:\/\/www.google.co.uk<\/a> some other text$/
|
||||
},
|
||||
{
|
||||
input: 'Some [ text http://www.google.co.uk some other text',
|
||||
output: /^Some \[ text <a href=\'http:\/\/www.google.co.uk\'>http:\/\/www.google.co.uk<\/a> some other text$/
|
||||
},
|
||||
{
|
||||
input: 'Some [ text (http://www.google.co.uk) some other text',
|
||||
output: /^Some \[ text \(<a href=\'http:\/\/www.google.co.uk\'>http:\/\/www.google.co.uk<\/a>\) some other text$/
|
||||
},
|
||||
{
|
||||
input: ' http://google.co.uk ',
|
||||
output: /^ <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a> $/
|
||||
},
|
||||
{
|
||||
input: '>http://google.co.uk',
|
||||
output: /^><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: '> http://google.co.uk',
|
||||
output: /^> <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: '<>>> http://google.co.uk',
|
||||
output: /^<>>> <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: '<>>>http://google.co.uk',
|
||||
output: /^<>>><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: '<some text>>>http://google.co.uk',
|
||||
output: /^<some text>>><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: '<strong>http://google.co.uk',
|
||||
output: /^<strong><a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: '# http://google.co.uk',
|
||||
output: /^# <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: '#http://google.co.uk',
|
||||
output: /^#<a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: '* http://google.co.uk',
|
||||
output: /^\* <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = _ConvertPhrase(testPhrase.input);
|
||||
@ -128,30 +131,30 @@ describe("Ghost GFM showdown extension", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should NOT auto-link URL in HTML", function () {
|
||||
it('should NOT auto-link URL in HTML', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: '<img src="http://placekitten.com/50">',
|
||||
output: /^<img src=\"http:\/\/placekitten.com\/50\">$/
|
||||
},
|
||||
{
|
||||
input: '<img src="http://placekitten.com/50" />',
|
||||
output: /^<img src=\"http:\/\/placekitten.com\/50\" \/>$/
|
||||
},
|
||||
{
|
||||
input: '<script type="text/javascript" src="http://google.co.uk"></script>',
|
||||
output: /^<script type=\"text\/javascript\" src=\"http:\/\/google.co.uk\"><\/script>$/
|
||||
},
|
||||
{
|
||||
input: '<a href="http://facebook.com">http://google.co.uk</a>',
|
||||
output: /^<a href=\"http:\/\/facebook.com\">http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: '<a href="http://facebook.com">test</a> http://google.co.uk',
|
||||
output: /^<a href=\"http:\/\/facebook.com\">test<\/a> <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
{
|
||||
input: '<img src="http://placekitten.com/50">',
|
||||
output: /^<img src=\"http:\/\/placekitten.com\/50\">$/
|
||||
},
|
||||
{
|
||||
input: '<img src="http://placekitten.com/50" />',
|
||||
output: /^<img src=\"http:\/\/placekitten.com\/50\" \/>$/
|
||||
},
|
||||
{
|
||||
input: '<script type="text/javascript" src="http://google.co.uk"></script>',
|
||||
output: /^<script type=\"text\/javascript\" src=\"http:\/\/google.co.uk\"><\/script>$/
|
||||
},
|
||||
{
|
||||
input: '<a href="http://facebook.com">http://google.co.uk</a>',
|
||||
output: /^<a href=\"http:\/\/facebook.com\">http:\/\/google.co.uk<\/a>$/
|
||||
},
|
||||
{
|
||||
input: '<a href="http://facebook.com">test</a> http://google.co.uk',
|
||||
output: /^<a href="http:\/\/facebook.com">test<\/a> <a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = _ConvertPhrase(testPhrase.input);
|
||||
@ -159,34 +162,34 @@ describe("Ghost GFM showdown extension", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should NOT auto-link reference URL", function () {
|
||||
it('should NOT auto-link reference URL', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "[1]: http://www.google.co.uk",
|
||||
output: /^\n\n\[1\]: http:\/\/www.google.co.uk$/
|
||||
},
|
||||
{
|
||||
input: "[http://www.google.co.uk]: http://www.google.co.uk",
|
||||
output: /^\n\n\[http:\/\/www.google.co.uk]: http:\/\/www.google.co.uk$/
|
||||
},
|
||||
{
|
||||
input: "[1]: http://dsurl.stuff/something.jpg",
|
||||
output: /^\n\n\[1\]: http:\/\/dsurl.stuff\/something.jpg$/
|
||||
},
|
||||
{
|
||||
input: "[1]:http://www.google.co.uk",
|
||||
output: /^\n\n\[1\]:http:\/\/www.google.co.uk$/
|
||||
},
|
||||
{
|
||||
input: " [1]:http://www.google.co.uk",
|
||||
output: /^\n\n \[1\]:http:\/\/www.google.co.uk$/
|
||||
},
|
||||
{
|
||||
input: "[http://www.google.co.uk]: http://www.google.co.uk",
|
||||
output: /^\n\n\[http:\/\/www.google.co.uk\]: http:\/\/www.google.co.uk$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
{
|
||||
input: '[1]: http://www.google.co.uk',
|
||||
output: /^\n\n\[1\]: http:\/\/www.google.co.uk$/
|
||||
},
|
||||
{
|
||||
input: '[http://www.google.co.uk]: http://www.google.co.uk',
|
||||
output: /^\n\n\[http:\/\/www.google.co.uk]: http:\/\/www.google.co.uk$/
|
||||
},
|
||||
{
|
||||
input: '[1]: http://dsurl.stuff/something.jpg',
|
||||
output: /^\n\n\[1\]: http:\/\/dsurl.stuff\/something.jpg$/
|
||||
},
|
||||
{
|
||||
input: '[1]:http://www.google.co.uk',
|
||||
output: /^\n\n\[1\]:http:\/\/www.google.co.uk$/
|
||||
},
|
||||
{
|
||||
input: ' [1]:http://www.google.co.uk',
|
||||
output: /^\n\n \[1\]:http:\/\/www.google.co.uk$/
|
||||
},
|
||||
{
|
||||
input: '[http://www.google.co.uk]: http://www.google.co.uk',
|
||||
output: /^\n\n\[http:\/\/www.google.co.uk\]: http:\/\/www.google.co.uk$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = _ConvertPhrase(testPhrase.input);
|
||||
@ -194,38 +197,38 @@ describe("Ghost GFM showdown extension", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should NOT auto-link URL in link or image markdown", function () {
|
||||
it('should NOT auto-link URL in link or image markdown', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "[1](http://google.co.uk)",
|
||||
output: /^\[1\]\(http:\/\/google.co.uk\)$/
|
||||
},
|
||||
{
|
||||
input: " [1](http://google.co.uk)",
|
||||
output: /^ \[1\]\(http:\/\/google.co.uk\)$/
|
||||
},
|
||||
{
|
||||
input: "[http://google.co.uk](http://google.co.uk)",
|
||||
output: /^\[http:\/\/google.co.uk\]\(http:\/\/google.co.uk\)$/
|
||||
},
|
||||
{
|
||||
input: "[http://google.co.uk][id]",
|
||||
output: /^\[http:\/\/google.co.uk\]\[id\]$/
|
||||
},
|
||||
{
|
||||
input: "![1](http://google.co.uk/kitten.jpg)",
|
||||
output: /^<img src=\"http:\/\/google.co.uk\/kitten.jpg\" alt=\"1\" \/>$/
|
||||
},
|
||||
{
|
||||
input: " ![1](http://google.co.uk/kitten.jpg)",
|
||||
output: /^ !\[1\]\(http:\/\/google.co.uk\/kitten.jpg\)$/
|
||||
},
|
||||
{
|
||||
input: "![http://google.co.uk/kitten.jpg](http://google.co.uk/kitten.jpg)",
|
||||
output: /^<img src=\"http:\/\/google.co.uk\/kitten.jpg\" alt=\"http:\/\/google.co.uk\/kitten.jpg\" \/>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
{
|
||||
input: '[1](http://google.co.uk)',
|
||||
output: /^\[1\]\(http:\/\/google.co.uk\)$/
|
||||
},
|
||||
{
|
||||
input: ' [1](http://google.co.uk)',
|
||||
output: /^ \[1\]\(http:\/\/google.co.uk\)$/
|
||||
},
|
||||
{
|
||||
input: '[http://google.co.uk](http://google.co.uk)',
|
||||
output: /^\[http:\/\/google.co.uk\]\(http:\/\/google.co.uk\)$/
|
||||
},
|
||||
{
|
||||
input: '[http://google.co.uk][id]',
|
||||
output: /^\[http:\/\/google.co.uk\]\[id\]$/
|
||||
},
|
||||
{
|
||||
input: '![1](http://google.co.uk/kitten.jpg)',
|
||||
output: /^<img src=\"http:\/\/google.co.uk\/kitten.jpg\" alt=\"1\" \/>$/
|
||||
},
|
||||
{
|
||||
input: ' ![1](http://google.co.uk/kitten.jpg)',
|
||||
output: /^ !\[1\]\(http:\/\/google.co.uk\/kitten.jpg\)$/
|
||||
},
|
||||
{
|
||||
input: '![http://google.co.uk/kitten.jpg](http://google.co.uk/kitten.jpg)',
|
||||
output: /^<img src=\"http:\/\/google.co.uk\/kitten.jpg\" alt=\"http:\/\/google.co.uk\/kitten.jpg\" \/>$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = _ConvertPhrase(testPhrase.input);
|
||||
@ -234,18 +237,19 @@ describe("Ghost GFM showdown extension", function () {
|
||||
});
|
||||
|
||||
// behaviour if you add a gap between [] and ()
|
||||
it("should auto-link if markdown is invalid", function () {
|
||||
it('should auto-link if markdown is invalid', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "[1] (http://google.co.uk)",
|
||||
output: /^\[1\] \(<a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>\)$/
|
||||
},
|
||||
{
|
||||
input: "![1] (http://google.co.uk/kitten.jpg)",
|
||||
output: /^!\[1\] \(<a href=\'http:\/\/google.co.uk\/kitten.jpg\'>http:\/\/google.co.uk\/kitten.jpg<\/a>\)$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
{
|
||||
input: '[1] (http://google.co.uk)',
|
||||
output: /^\[1\] \(<a href=\'http:\/\/google.co.uk\'>http:\/\/google.co.uk<\/a>\)$/
|
||||
},
|
||||
{
|
||||
input: '![1] (http://google.co.uk/kitten.jpg)',
|
||||
output:
|
||||
/^!\[1\] \(<a href=\'http:\/\/google.co.uk\/kitten.jpg\'>http:\/\/google.co.uk\/kitten.jpg<\/a>\)$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = _ConvertPhrase(testPhrase.input);
|
||||
@ -253,14 +257,14 @@ describe("Ghost GFM showdown extension", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should not output image if there is no src", function () {
|
||||
it('should not output image if there is no src', function () {
|
||||
var testPhrases = [
|
||||
{
|
||||
input: "![anything here]()",
|
||||
output: /^$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
{
|
||||
input: '![anything here]()',
|
||||
output: /^$/
|
||||
}
|
||||
],
|
||||
processedMarkup;
|
||||
|
||||
testPhrases.forEach(function (testPhrase) {
|
||||
processedMarkup = _ConvertPhrase(testPhrase.input);
|
||||
|
@ -6,41 +6,44 @@
|
||||
*/
|
||||
|
||||
/*globals describe, it */
|
||||
var testUtils = require('../utils'),
|
||||
should = require('should'),
|
||||
/*jshint expr:true*/
|
||||
var should = require('should'),
|
||||
|
||||
// Stuff we are testing
|
||||
ghostimagepreview = require('../../shared/lib/showdown/extensions/ghostimagepreview');
|
||||
|
||||
describe("Ghost Image Preview showdown extension", function () {
|
||||
// To stop jshint complaining
|
||||
should.equal(true, true);
|
||||
|
||||
it("should export an array of methods for processing", function () {
|
||||
describe('Ghost Image Preview showdown extension', function () {
|
||||
|
||||
it('should export an array of methods for processing', function () {
|
||||
|
||||
ghostimagepreview.should.be.a.function;
|
||||
ghostimagepreview().should.be.an.instanceof(Array);
|
||||
|
||||
ghostimagepreview().forEach(function (processor) {
|
||||
processor.should.be.an.Object;
|
||||
processor.should.have.property("type");
|
||||
processor.should.have.property("filter");
|
||||
processor.should.have.property('type');
|
||||
processor.should.have.property('filter');
|
||||
processor.type.should.be.a.String;
|
||||
processor.filter.should.be.a.function;
|
||||
});
|
||||
});
|
||||
|
||||
it("should accurately detect images in markdown", function () {
|
||||
it('should accurately detect images in markdown', function () {
|
||||
[
|
||||
"![]",
|
||||
"![]()",
|
||||
"![image and another,/ image]",
|
||||
"![image and another,/ image]()",
|
||||
"![image and another,/ image](http://dsurl.stuff)",
|
||||
"![](http://dsurl.stuff)"
|
||||
'![]',
|
||||
'![]()',
|
||||
'![image and another,/ image]',
|
||||
'![image and another,/ image]()',
|
||||
'![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) {
|
||||
@ -54,13 +57,13 @@ describe("Ghost Image Preview showdown extension", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should correctly include an image", function () {
|
||||
it('should correctly include an image', function () {
|
||||
[
|
||||
"![image and another,/ image](http://dsurl.stuff)",
|
||||
"![](http://dsurl.stuff)"
|
||||
'![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) {
|
||||
|
@ -1,12 +1,15 @@
|
||||
/*globals describe, beforeEach, afterEach, it*/
|
||||
var fs = require('fs-extra'),
|
||||
path = require('path'),
|
||||
should = require('should'),
|
||||
config = require('../../server/config'),
|
||||
sinon = require('sinon'),
|
||||
when = require('when'),
|
||||
/*jshint expr:true*/
|
||||
var fs = require('fs-extra'),
|
||||
path = require('path'),
|
||||
should = require('should'),
|
||||
config = require('../../server/config'),
|
||||
sinon = require('sinon'),
|
||||
localfilesystem = require('../../server/storage/localfilesystem');
|
||||
|
||||
// To stop jshint complaining
|
||||
should.equal(true, true);
|
||||
|
||||
describe('Local File System Storage', function () {
|
||||
|
||||
var image;
|
||||
@ -18,9 +21,9 @@ describe('Local File System Storage', function () {
|
||||
sinon.stub(fs, 'unlink').yields();
|
||||
|
||||
image = {
|
||||
path: "tmp/123456.jpg",
|
||||
name: "IMAGE.jpg",
|
||||
type: "image/jpeg"
|
||||
path: 'tmp/123456.jpg',
|
||||
name: 'IMAGE.jpg',
|
||||
type: 'image/jpeg'
|
||||
};
|
||||
|
||||
// Sat Sep 07 2013 21:24
|
||||
@ -61,6 +64,7 @@ describe('Local File System Storage', function () {
|
||||
|
||||
it('should create month and year directory', function (done) {
|
||||
localfilesystem.save(image).then(function (url) {
|
||||
/*jshint unused:false*/
|
||||
fs.mkdirs.calledOnce.should.be.true;
|
||||
fs.mkdirs.args[0][0].should.equal(path.resolve('./content/images/2013/Sep'));
|
||||
done();
|
||||
@ -69,6 +73,7 @@ describe('Local File System Storage', function () {
|
||||
|
||||
it('should copy temp file to new location', function (done) {
|
||||
localfilesystem.save(image).then(function (url) {
|
||||
/*jshint unused:false*/
|
||||
fs.copy.calledOnce.should.be.true;
|
||||
fs.copy.args[0][0].should.equal('tmp/123456.jpg');
|
||||
fs.copy.args[0][1].should.equal(path.resolve('./content/images/2013/Sep/IMAGE.jpg'));
|
||||
@ -78,6 +83,7 @@ describe('Local File System Storage', function () {
|
||||
|
||||
it('should not leave temporary file when uploading', function (done) {
|
||||
localfilesystem.save(image).then(function (url) {
|
||||
/*jshint unused:false*/
|
||||
fs.unlink.calledOnce.should.be.true;
|
||||
fs.unlink.args[0][0].should.equal('tmp/123456.jpg');
|
||||
done();
|
||||
@ -165,7 +171,7 @@ describe('Local File System Storage', function () {
|
||||
url.should.equal('/content/images/2013/Sep/IMAGE.jpg');
|
||||
} else {
|
||||
// if this unit test is run on an OS that uses forward slash separators,
|
||||
// localfilesystem.save() will use a path.relative() call on
|
||||
// localfilesystem.save() will use a path.relative() call on
|
||||
// one path with backslash separators and one path with forward
|
||||
// slashes and it returns a path that needs to be normalized
|
||||
path.normalize(url).should.equal('/content/images/2013/Sep/IMAGE.jpg');
|
||||
|
@ -1,8 +1,7 @@
|
||||
/*globals describe, beforeEach, afterEach, it*/
|
||||
var assert = require('assert'),
|
||||
http = require('http'),
|
||||
nock = require('nock'),
|
||||
settings = require('../../server/api').settings;
|
||||
/*jshint expr:true*/
|
||||
var nock = require('nock'),
|
||||
settings = require('../../server/api').settings,
|
||||
should = require('should'),
|
||||
sinon = require('sinon'),
|
||||
testUtils = require('../utils'),
|
||||
@ -11,13 +10,16 @@ var assert = require('assert'),
|
||||
// storing current environment
|
||||
currentEnv = process.env.NODE_ENV;
|
||||
|
||||
// To stop jshint complaining
|
||||
should.equal(true, true);
|
||||
|
||||
describe('XMLRPC', function () {
|
||||
var sandbox;
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox = sinon.sandbox.create();
|
||||
// give environment a value that will ping
|
||||
process.env.NODE_ENV = "production";
|
||||
process.env.NODE_ENV = 'production';
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
@ -34,6 +36,7 @@ describe('XMLRPC', function () {
|
||||
settingsStub = sandbox.stub(settings, 'read', function () {
|
||||
return when({ settings: [{value: '/:slug/'}] });
|
||||
});
|
||||
/*jshint unused:false */
|
||||
|
||||
xmlrpc.ping(testPost).then(function () {
|
||||
ping1.isDone().should.be.true;
|
||||
|
Loading…
Reference in New Issue
Block a user