mirror of
https://github.com/TryGhost/Ghost.git
synced 2023-12-13 21:00:40 +01:00
Use Promise support which was added in fs-extra 3.x
no issue - now that we use bluebird globally, we can use the promise support from fs-extra
This commit is contained in:
parent
d83f474ff8
commit
485c264c69
|
@ -39,9 +39,9 @@ class LocalFileStore extends StorageBase {
|
||||||
|
|
||||||
return this.getUniqueFileName(image, targetDir).then(function (filename) {
|
return this.getUniqueFileName(image, targetDir).then(function (filename) {
|
||||||
targetFilename = filename;
|
targetFilename = filename;
|
||||||
return Promise.promisify(fs.mkdirs)(targetDir);
|
return fs.mkdirs(targetDir);
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
return Promise.promisify(fs.copy)(image.path, targetFilename);
|
return fs.copy(image.path, targetFilename);
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
// The src for the image must be in URI format, not a file system path, which in Windows uses \
|
// The src for the image must be in URI format, not a file system path, which in Windows uses \
|
||||||
// For local file system storage can use relative path so add a slash
|
// For local file system storage can use relative path so add a slash
|
||||||
|
@ -60,12 +60,13 @@ class LocalFileStore extends StorageBase {
|
||||||
exists(fileName, targetDir) {
|
exists(fileName, targetDir) {
|
||||||
var filePath = path.join(targetDir || this.storagePath, fileName);
|
var filePath = path.join(targetDir || this.storagePath, fileName);
|
||||||
|
|
||||||
return new Promise(function (resolve) {
|
return fs.stat(filePath)
|
||||||
fs.stat(filePath, function (err) {
|
.then(function () {
|
||||||
var exists = !err;
|
return true;
|
||||||
resolve(exists);
|
})
|
||||||
|
.catch(function () {
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -38,7 +38,7 @@ db = {
|
||||||
.then(function successMessage(exportResult) {
|
.then(function successMessage(exportResult) {
|
||||||
var filename = path.resolve(urlService.utils.urlJoin(config.get('paths').contentPath, 'data', exportResult.filename));
|
var filename = path.resolve(urlService.utils.urlJoin(config.get('paths').contentPath, 'data', exportResult.filename));
|
||||||
|
|
||||||
return Promise.promisify(fs.writeFile)(filename, JSON.stringify(exportResult.data))
|
return fs.writeFile(filename, JSON.stringify(exportResult.data))
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return filename;
|
return filename;
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,7 +16,7 @@ let redirectsAPI,
|
||||||
_private.readRedirectsFile = function readRedirectsFile(customRedirectsPath) {
|
_private.readRedirectsFile = function readRedirectsFile(customRedirectsPath) {
|
||||||
let redirectsPath = customRedirectsPath || path.join(config.getContentPath('data'), 'redirects.json');
|
let redirectsPath = customRedirectsPath || path.join(config.getContentPath('data'), 'redirects.json');
|
||||||
|
|
||||||
return Promise.promisify(fs.readFile)(redirectsPath, 'utf-8')
|
return fs.readFile(redirectsPath, 'utf-8')
|
||||||
.then(function serveContent(content) {
|
.then(function serveContent(content) {
|
||||||
try {
|
try {
|
||||||
content = JSON.parse(content);
|
content = JSON.parse(content);
|
||||||
|
@ -56,29 +56,29 @@ redirectsAPI = {
|
||||||
|
|
||||||
return apiUtils.handlePermissions('redirects', 'upload')(options)
|
return apiUtils.handlePermissions('redirects', 'upload')(options)
|
||||||
.then(function backupOldRedirectsFile() {
|
.then(function backupOldRedirectsFile() {
|
||||||
return Promise.promisify(fs.pathExists)(redirectsPath)
|
return fs.pathExists(redirectsPath)
|
||||||
.then(function (exists) {
|
.then(function (exists) {
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.promisify(fs.pathExists)(backupRedirectsPath)
|
return fs.pathExists(backupRedirectsPath)
|
||||||
.then(function (exists) {
|
.then(function (exists) {
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.promisify(fs.unlink)(backupRedirectsPath);
|
return fs.unlink(backupRedirectsPath);
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return Promise.promisify(fs.move)(redirectsPath, backupRedirectsPath);
|
return fs.move(redirectsPath, backupRedirectsPath);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(function overrideFile() {
|
.then(function overrideFile() {
|
||||||
return _private.readRedirectsFile(options.path)
|
return _private.readRedirectsFile(options.path)
|
||||||
.then(function (content) {
|
.then(function (content) {
|
||||||
globalUtils.validateRedirects(content);
|
globalUtils.validateRedirects(content);
|
||||||
return Promise.promisify(fs.writeFile)(redirectsPath, JSON.stringify(content), 'utf-8');
|
return fs.writeFile(redirectsPath, JSON.stringify(content), 'utf-8');
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
// CASE: trigger that redirects are getting re-registered
|
// CASE: trigger that redirects are getting re-registered
|
||||||
|
|
|
@ -336,7 +336,7 @@ subscribers = {
|
||||||
};
|
};
|
||||||
}).finally(function () {
|
}).finally(function () {
|
||||||
// Remove uploaded file from tmp location
|
// Remove uploaded file from tmp location
|
||||||
return Promise.promisify(fs.unlink)(filePath);
|
return fs.unlink(filePath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ themes = {
|
||||||
// @TODO we should probably do this as part of saving the theme
|
// @TODO we should probably do this as part of saving the theme
|
||||||
// remove zip upload from multer
|
// remove zip upload from multer
|
||||||
// happens in background
|
// happens in background
|
||||||
Promise.promisify(fs.remove)(zip.path)
|
fs.remove(zip.path)
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
common.logging.error(new common.errors.GhostError({err: err}));
|
common.logging.error(new common.errors.GhostError({err: err}));
|
||||||
});
|
});
|
||||||
|
@ -152,7 +152,7 @@ themes = {
|
||||||
// remove extracted dir from gscan
|
// remove extracted dir from gscan
|
||||||
// happens in background
|
// happens in background
|
||||||
if (checkedTheme) {
|
if (checkedTheme) {
|
||||||
Promise.promisify(fs.remove)(checkedTheme.path)
|
fs.remove(checkedTheme.path)
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
common.logging.error(new common.errors.GhostError({err: err}));
|
common.logging.error(new common.errors.GhostError({err: err}));
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
var Promise = require('bluebird'),
|
var Promise = require('bluebird'),
|
||||||
fs = require('fs-extra'),
|
fs = require('fs-extra'),
|
||||||
pUnlink = Promise.promisify(fs.unlink),
|
|
||||||
storage = require('../adapters/storage'),
|
storage = require('../adapters/storage'),
|
||||||
upload;
|
upload;
|
||||||
|
|
||||||
|
@ -23,7 +22,7 @@ upload = {
|
||||||
|
|
||||||
return store.save(options).finally(function () {
|
return store.save(options).finally(function () {
|
||||||
// Remove uploaded file from tmp location
|
// Remove uploaded file from tmp location
|
||||||
return pUnlink(options.path);
|
return fs.unlink(options.path);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,7 @@ var fs = require('fs-extra'),
|
||||||
writeExportFile = function writeExportFile(exportResult) {
|
writeExportFile = function writeExportFile(exportResult) {
|
||||||
var filename = path.resolve(urlService.utils.urlJoin(config.get('paths').contentPath, 'data', exportResult.filename));
|
var filename = path.resolve(urlService.utils.urlJoin(config.get('paths').contentPath, 'data', exportResult.filename));
|
||||||
|
|
||||||
return Promise.promisify(fs.writeFile)(filename, JSON.stringify(exportResult.data)).return(filename);
|
return fs.writeFile(filename, JSON.stringify(exportResult.data)).return(filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,8 +14,9 @@ JSONHandler = {
|
||||||
// @TODO: Handle multiple JSON files
|
// @TODO: Handle multiple JSON files
|
||||||
var filePath = files[0].path;
|
var filePath = files[0].path;
|
||||||
|
|
||||||
return Promise.promisify(fs.readFile)(filePath).then(function (fileData) {
|
return fs.readFile(filePath).then(function (fileData) {
|
||||||
var importData;
|
var importData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
importData = JSON.parse(fileData);
|
importData = JSON.parse(fileData);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
var _ = require('lodash'),
|
var _ = require('lodash'),
|
||||||
Promise = require('bluebird'),
|
Promise = require('bluebird'),
|
||||||
fs = require('fs-extra'),
|
fs = require('fs-extra'),
|
||||||
moment = require('moment'),
|
moment = require('moment'),
|
||||||
|
|
||||||
featuredImageRegex = /^(!\[]\(([^)]*?)\)\s+)(?=#)/,
|
featuredImageRegex = /^(!\[]\(([^)]*?)\)\s+)(?=#)/,
|
||||||
titleRegex = /^#\s?([\w\W]*?)(?=\n)/,
|
titleRegex = /^#\s?([\w\W]*?)(?=\n)/,
|
||||||
|
@ -92,7 +92,7 @@ MarkdownHandler = {
|
||||||
ops = [];
|
ops = [];
|
||||||
|
|
||||||
_.each(files, function (file) {
|
_.each(files, function (file) {
|
||||||
ops.push(Promise.promisify(fs.readFile)(file.path).then(function (content) {
|
ops.push(fs.readFile(file.path).then(function (content) {
|
||||||
// normalize the file name
|
// normalize the file name
|
||||||
file.name = file.name.replace(startDirRegex, '');
|
file.name = file.name.replace(startDirRegex, '');
|
||||||
// don't include deleted posts
|
// don't include deleted posts
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
var _ = require('lodash').runInContext(),
|
var _ = require('lodash').runInContext(),
|
||||||
fs = require('fs-extra'),
|
fs = require('fs-extra'),
|
||||||
Promise = require('bluebird'),
|
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
htmlToText = require('html-to-text'),
|
htmlToText = require('html-to-text'),
|
||||||
urlService = require('../services/url'),
|
urlService = require('../services/url'),
|
||||||
|
@ -19,7 +18,7 @@ exports.generateContent = function generateContent(options) {
|
||||||
data = _.defaults(defaults, options.data);
|
data = _.defaults(defaults, options.data);
|
||||||
|
|
||||||
// read the proper email body template
|
// read the proper email body template
|
||||||
return Promise.promisify(fs.readFile)(path.join(templatesDir, options.template + '.html'), 'utf8')
|
return fs.readFile(path.join(templatesDir, options.template + '.html'), 'utf8')
|
||||||
.then(function (content) {
|
.then(function (content) {
|
||||||
var compiled,
|
var compiled,
|
||||||
htmlContent,
|
htmlContent,
|
||||||
|
|
|
@ -6,8 +6,7 @@ var fs = require('fs-extra'),
|
||||||
Promise = require('bluebird'),
|
Promise = require('bluebird'),
|
||||||
config = require('../config'),
|
config = require('../config'),
|
||||||
globalUtils = require('../utils'),
|
globalUtils = require('../utils'),
|
||||||
LocalFileStorage = require('../adapters/storage/LocalFileStorage'),
|
LocalFileStorage = require('../adapters/storage/LocalFileStorage');
|
||||||
remove = Promise.promisify(fs.remove);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @TODO: combine with loader.js?
|
* @TODO: combine with loader.js?
|
||||||
|
@ -35,7 +34,7 @@ class ThemeStorage extends LocalFileStorage {
|
||||||
zipPath = path.join(zipBasePath, zipName),
|
zipPath = path.join(zipBasePath, zipName),
|
||||||
stream;
|
stream;
|
||||||
|
|
||||||
Promise.promisify(fs.ensureDir)(zipBasePath)
|
fs.ensureDir(zipBasePath)
|
||||||
.then(function () {
|
.then(function () {
|
||||||
return Promise.promisify(globalUtils.zipFolder)(themePath, zipPath);
|
return Promise.promisify(globalUtils.zipFolder)(themePath, zipPath);
|
||||||
})
|
})
|
||||||
|
@ -53,13 +52,13 @@ class ThemeStorage extends LocalFileStorage {
|
||||||
next(err);
|
next(err);
|
||||||
})
|
})
|
||||||
.finally(function () {
|
.finally(function () {
|
||||||
remove(zipBasePath);
|
return fs.remove(zipBasePath);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(fileName) {
|
delete(fileName) {
|
||||||
return remove(path.join(this.storagePath, fileName));
|
return fs.remove(path.join(this.storagePath, fileName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
var Promise = require('bluebird'),
|
var Promise = require('bluebird'),
|
||||||
fs = require('fs-extra'),
|
fs = require('fs-extra'),
|
||||||
common = require('../../lib/common'),
|
common = require('../../lib/common');
|
||||||
readFile = Promise.promisify(fs.readFile);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse package.json and validate it has
|
* Parse package.json and validate it has
|
||||||
|
@ -13,7 +12,7 @@ var Promise = require('bluebird'),
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function parsePackageJson(path) {
|
function parsePackageJson(path) {
|
||||||
return readFile(path)
|
return fs.readFile(path)
|
||||||
.catch(function () {
|
.catch(function () {
|
||||||
var err = new Error(common.i18n.t('errors.utils.parsepackagejson.couldNotReadPackage'));
|
var err = new Error(common.i18n.t('errors.utils.parsepackagejson.couldNotReadPackage'));
|
||||||
err.context = path;
|
err.context = path;
|
||||||
|
|
|
@ -11,9 +11,6 @@ var Promise = require('bluebird'),
|
||||||
notAPackageRegex = /^\.|_messages|README.md|node_modules|bower_components/i,
|
notAPackageRegex = /^\.|_messages|README.md|node_modules|bower_components/i,
|
||||||
packageJSONPath = 'package.json',
|
packageJSONPath = 'package.json',
|
||||||
|
|
||||||
statFile = Promise.promisify(fs.stat),
|
|
||||||
readDir = Promise.promisify(fs.readdir),
|
|
||||||
|
|
||||||
readPackage,
|
readPackage,
|
||||||
readPackages,
|
readPackages,
|
||||||
processPackage;
|
processPackage;
|
||||||
|
@ -43,7 +40,7 @@ processPackage = function processPackage(absolutePath, packageName) {
|
||||||
|
|
||||||
readPackage = function readPackage(packagePath, packageName) {
|
readPackage = function readPackage(packagePath, packageName) {
|
||||||
var absolutePath = join(packagePath, packageName);
|
var absolutePath = join(packagePath, packageName);
|
||||||
return statFile(absolutePath)
|
return fs.stat(absolutePath)
|
||||||
.then(function (stat) {
|
.then(function (stat) {
|
||||||
if (!stat.isDirectory()) {
|
if (!stat.isDirectory()) {
|
||||||
return {};
|
return {};
|
||||||
|
@ -67,14 +64,14 @@ readPackage = function readPackage(packagePath, packageName) {
|
||||||
};
|
};
|
||||||
|
|
||||||
readPackages = function readPackages(packagePath) {
|
readPackages = function readPackages(packagePath) {
|
||||||
return readDir(packagePath)
|
return fs.readdir(packagePath)
|
||||||
.filter(function (packageName) {
|
.filter(function (packageName) {
|
||||||
// Filter out things which are not packages by regex
|
// Filter out things which are not packages by regex
|
||||||
if (packageName.match(notAPackageRegex)) {
|
if (packageName.match(notAPackageRegex)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check the remaining items to ensure they are a directory
|
// Check the remaining items to ensure they are a directory
|
||||||
return statFile(join(packagePath, packageName)).then(function (stat) {
|
return fs.stat(join(packagePath, packageName)).then(function (stat) {
|
||||||
return stat.isDirectory();
|
return stat.isDirectory();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
var should = require('should'),
|
var should = require('should'),
|
||||||
supertest = require('supertest'),
|
supertest = require('supertest'),
|
||||||
|
Promise = require('bluebird'),
|
||||||
testUtils = require('../../../utils'),
|
testUtils = require('../../../utils'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
sinon = require('sinon'),
|
sinon = require('sinon'),
|
||||||
|
@ -107,7 +108,7 @@ describe('DB API', function () {
|
||||||
|
|
||||||
it('export can be triggered by backup client', function (done) {
|
it('export can be triggered by backup client', function (done) {
|
||||||
backupQuery = '?client_id=' + backupClient.slug + '&client_secret=' + backupClient.secret;
|
backupQuery = '?client_id=' + backupClient.slug + '&client_secret=' + backupClient.secret;
|
||||||
fsStub = sandbox.stub(fs, 'writeFile').yields();
|
fsStub = sandbox.stub(fs, 'writeFile').resolves();
|
||||||
request.post(testUtils.API.getApiQuery('db/backup' + backupQuery))
|
request.post(testUtils.API.getApiQuery('db/backup' + backupQuery))
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
@ -124,7 +125,7 @@ describe('DB API', function () {
|
||||||
|
|
||||||
it('export can be triggered by backup client', function (done) {
|
it('export can be triggered by backup client', function (done) {
|
||||||
schedulerQuery = '?client_id=' + schedulerClient.slug + '&client_secret=' + schedulerClient.secret;
|
schedulerQuery = '?client_id=' + schedulerClient.slug + '&client_secret=' + schedulerClient.secret;
|
||||||
fsStub = sandbox.stub(fs, 'writeFile').yields();
|
fsStub = sandbox.stub(fs, 'writeFile').resolves();
|
||||||
request.post(testUtils.API.getApiQuery('db/backup' + schedulerQuery))
|
request.post(testUtils.API.getApiQuery('db/backup' + schedulerQuery))
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(403)
|
.expect(403)
|
||||||
|
|
|
@ -279,9 +279,7 @@ describe('Subscribers API', function () {
|
||||||
stub;
|
stub;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sandbox.stub(fs, 'unlink').callsFake(function (path, cb) {
|
sandbox.stub(fs, 'unlink').resolves();
|
||||||
cb();
|
|
||||||
});
|
|
||||||
sandbox.stub(apiUtils, 'checkFileExists').returns(true);
|
sandbox.stub(apiUtils, 'checkFileExists').returns(true);
|
||||||
stub = sandbox.stub(apiUtils, 'checkFileIsValid').returns(true);
|
stub = sandbox.stub(apiUtils, 'checkFileIsValid').returns(true);
|
||||||
sandbox.stub(globalUtils, 'readCSV').callsFake(function () {
|
sandbox.stub(globalUtils, 'readCSV').callsFake(function () {
|
||||||
|
|
|
@ -2,6 +2,7 @@ var should = require('should'), // jshint ignore:line
|
||||||
sinon = require('sinon'),
|
sinon = require('sinon'),
|
||||||
fs = require('fs-extra'),
|
fs = require('fs-extra'),
|
||||||
moment = require('moment'),
|
moment = require('moment'),
|
||||||
|
Promise = require('bluebird'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
common = require('../../../../server/lib/common'),
|
common = require('../../../../server/lib/common'),
|
||||||
LocalFileStore = require('../../../../server/adapters/storage/LocalFileStorage'),
|
LocalFileStore = require('../../../../server/adapters/storage/LocalFileStorage'),
|
||||||
|
@ -39,10 +40,10 @@ describe('Local File System Storage', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sandbox.stub(fs, 'mkdirs').yields();
|
sandbox.stub(fs, 'mkdirs').resolves();
|
||||||
sandbox.stub(fs, 'copy').yields();
|
sandbox.stub(fs, 'copy').resolves();
|
||||||
sandbox.stub(fs, 'stat').yields(true);
|
sandbox.stub(fs, 'stat').rejects();
|
||||||
sandbox.stub(fs, 'unlink').yields();
|
sandbox.stub(fs, 'unlink').resolves();
|
||||||
|
|
||||||
image = {
|
image = {
|
||||||
path: 'tmp/123456.jpg',
|
path: 'tmp/123456.jpg',
|
||||||
|
@ -111,13 +112,13 @@ describe('Local File System Storage', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can upload two different images with the same name without overwriting the first', function (done) {
|
it('can upload two different images with the same name without overwriting the first', function (done) {
|
||||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE.jpg')).yields(false);
|
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE.jpg')).resolves();
|
||||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-1.jpg')).yields(true);
|
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-1.jpg')).rejects();
|
||||||
|
|
||||||
// if on windows need to setup with back slashes
|
// if on windows need to setup with back slashes
|
||||||
// doesn't hurt for the test to cope with both
|
// doesn't hurt for the test to cope with both
|
||||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE.jpg')).yields(false);
|
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE.jpg')).resolves();
|
||||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-1.jpg')).yields(true);
|
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-1.jpg')).rejects();
|
||||||
|
|
||||||
localFileStore.save(image).then(function (url) {
|
localFileStore.save(image).then(function (url) {
|
||||||
url.should.equal('/content/images/2013/09/IMAGE-1.jpg');
|
url.should.equal('/content/images/2013/09/IMAGE-1.jpg');
|
||||||
|
@ -127,18 +128,18 @@ describe('Local File System Storage', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can upload five different images with the same name without overwriting the first', function (done) {
|
it('can upload five different images with the same name without overwriting the first', function (done) {
|
||||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE.jpg')).yields(false);
|
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE.jpg')).resolves();
|
||||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-1.jpg')).yields(false);
|
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-1.jpg')).resolves();
|
||||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-2.jpg')).yields(false);
|
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-2.jpg')).resolves();
|
||||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-3.jpg')).yields(false);
|
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-3.jpg')).resolves();
|
||||||
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-4.jpg')).yields(true);
|
fs.stat.withArgs(path.resolve('./content/images/2013/09/IMAGE-4.jpg')).rejects();
|
||||||
|
|
||||||
// windows setup
|
// windows setup
|
||||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE.jpg')).yields(false);
|
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE.jpg')).resolves();
|
||||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-1.jpg')).yields(false);
|
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-1.jpg')).resolves();
|
||||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-2.jpg')).yields(false);
|
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-2.jpg')).resolves();
|
||||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-3.jpg')).yields(false);
|
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-3.jpg')).resolves();
|
||||||
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-4.jpg')).yields(true);
|
fs.stat.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-4.jpg')).rejects();
|
||||||
|
|
||||||
localFileStore.save(image).then(function (url) {
|
localFileStore.save(image).then(function (url) {
|
||||||
url.should.equal('/content/images/2013/09/IMAGE-4.jpg');
|
url.should.equal('/content/images/2013/09/IMAGE-4.jpg');
|
||||||
|
|
|
@ -65,9 +65,9 @@ describe('Migrations', function () {
|
||||||
var exportStub, filenameStub, fsStub;
|
var exportStub, filenameStub, fsStub;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
exportStub = sandbox.stub(exporter, 'doExport').returns(new Promise.resolve());
|
exportStub = sandbox.stub(exporter, 'doExport').resolves();
|
||||||
filenameStub = sandbox.stub(exporter, 'fileName').returns(new Promise.resolve('test'));
|
filenameStub = sandbox.stub(exporter, 'fileName').resolves('test');
|
||||||
fsStub = sandbox.stub(fs, 'writeFile').yields();
|
fsStub = sandbox.stub(fs, 'writeFile').resolves();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create a backup JSON file', function (done) {
|
it('should create a backup JSON file', function (done) {
|
||||||
|
|
|
@ -344,10 +344,9 @@ fixtures = {
|
||||||
|
|
||||||
loadExportFixture: function loadExportFixture(filename, options) {
|
loadExportFixture: function loadExportFixture(filename, options) {
|
||||||
options = options || {lts: false};
|
options = options || {lts: false};
|
||||||
var filePath = this.getExportFixturePath(filename, options),
|
var filePath = this.getExportFixturePath(filename, options);
|
||||||
readFile = Promise.promisify(fs.readFile);
|
|
||||||
|
|
||||||
return readFile(filePath).then(function (fileContents) {
|
return fs.readFile(filePath).then(function (fileContents) {
|
||||||
var data;
|
var data;
|
||||||
|
|
||||||
// Parse the json data
|
// Parse the json data
|
||||||
|
|
Loading…
Reference in a new issue