timeago locale test

v1.18.x
Barış Soner Uşaklı 8 years ago
parent 8205d6c897
commit 29135dfed3

@ -97,9 +97,8 @@ file.exists = function (path, callback) {
if (err.code === 'ENOENT') {
return callback(null, false);
}
return callback(err);
}
return callback(null, true);
callback(err, true);
});
};

@ -1,7 +1,6 @@
'use strict';
var async = require('async');
var fs = require('fs');
var path = require('path');
var csrf = require('csurf');
var validator = require('validator');
@ -13,6 +12,7 @@ var plugins = require('../plugins');
var meta = require('../meta');
var user = require('../user');
var groups = require('../groups');
var file = require('../file');
var analytics = require('../analytics');
@ -143,24 +143,25 @@ middleware.applyBlacklist = function (req, res, next) {
});
};
middleware.processTimeagoLocales = function (req, res) {
middleware.processTimeagoLocales = function (req, res, next) {
var fallback = req.path.indexOf('-short') === -1 ? 'jquery.timeago.en.js' : 'jquery.timeago.en-short.js';
var localPath = path.join(__dirname, '../../public/vendor/jquery/timeago/locales', req.path);
var exists;
try {
exists = fs.accessSync(localPath, fs.F_OK | fs.R_OK);
} catch (e) {
exists = false;
}
async.waterfall([
function (next) {
file.exists(localPath, next);
},
function (exists, next) {
if (exists) {
res.status(200).sendFile(localPath, {
maxAge: req.app.enabled('cache') ? 5184000000 : 0,
});
next(null, localPath);
} else {
res.status(200).sendFile(path.join(__dirname, '../../public/vendor/jquery/timeago/locales', fallback), {
next(null, path.join(__dirname, '../../public/vendor/jquery/timeago/locales', fallback));
}
},
function (path) {
res.status(200).sendFile(path, {
maxAge: req.app.enabled('cache') ? 5184000000 : 0,
});
}
},
], next);
};

@ -1287,6 +1287,25 @@ describe('Controllers', function () {
});
});
describe('timeago locales', function () {
it('should load timeago locale', function (done) {
request(nconf.get('url') + '/assets/vendor/jquery/timeago/locales/jquery.timeago.af.js', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body.indexOf('Afrikaans') !== -1);
done();
});
});
it('should load timeago locale', function (done) {
request(nconf.get('url') + '/assets/vendor/jquery/timeago/locales/jquery.timeago.404.js', function (err, res, body) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert(body.indexOf('English') !== -1);
done();
});
});
});
after(function (done) {
var analytics = require('../src/analytics');

Loading…
Cancel
Save