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') { if (err.code === 'ENOENT') {
return callback(null, false); return callback(null, false);
} }
return callback(err);
} }
return callback(null, true); callback(err, true);
}); });
}; };

@ -1,7 +1,6 @@
'use strict'; 'use strict';
var async = require('async'); var async = require('async');
var fs = require('fs');
var path = require('path'); var path = require('path');
var csrf = require('csurf'); var csrf = require('csurf');
var validator = require('validator'); var validator = require('validator');
@ -13,6 +12,7 @@ var plugins = require('../plugins');
var meta = require('../meta'); var meta = require('../meta');
var user = require('../user'); var user = require('../user');
var groups = require('../groups'); var groups = require('../groups');
var file = require('../file');
var analytics = require('../analytics'); 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 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 localPath = path.join(__dirname, '../../public/vendor/jquery/timeago/locales', req.path);
var exists;
try { async.waterfall([
exists = fs.accessSync(localPath, fs.F_OK | fs.R_OK); function (next) {
} catch (e) { file.exists(localPath, next);
exists = false; },
} function (exists, next) {
if (exists) {
if (exists) { next(null, localPath);
res.status(200).sendFile(localPath, { } else {
maxAge: req.app.enabled('cache') ? 5184000000 : 0, next(null, path.join(__dirname, '../../public/vendor/jquery/timeago/locales', fallback));
}); }
} else { },
res.status(200).sendFile(path.join(__dirname, '../../public/vendor/jquery/timeago/locales', fallback), { function (path) {
maxAge: req.app.enabled('cache') ? 5184000000 : 0, 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) { after(function (done) {
var analytics = require('../src/analytics'); var analytics = require('../src/analytics');

Loading…
Cancel
Save