From 457f36076567a40bce436ef742f8c12070ef13dc Mon Sep 17 00:00:00 2001 From: Harry Wolff Date: Tue, 2 Sep 2014 23:24:12 -0400 Subject: [PATCH] Updates image upload directories to be number based. resolves #2285 - Moves to using moment.format('MM') to use the date formatting of a month --- core/server/storage/base.js | 2 +- .../test/unit/storage_localfilesystem_spec.js | 38 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/core/server/storage/base.js b/core/server/storage/base.js index bd5cc922e1..aad1d0c773 100644 --- a/core/server/storage/base.js +++ b/core/server/storage/base.js @@ -6,7 +6,7 @@ function StorageBase() { StorageBase.prototype.getTargetDir = function (baseDir) { var m = moment(new Date().getTime()), - month = m.format('MMM'), + month = m.format('MM'), year = m.format('YYYY'); if (baseDir) { diff --git a/core/test/unit/storage_localfilesystem_spec.js b/core/test/unit/storage_localfilesystem_spec.js index 34899f17bf..21a0c7da74 100644 --- a/core/test/unit/storage_localfilesystem_spec.js +++ b/core/test/unit/storage_localfilesystem_spec.js @@ -53,7 +53,7 @@ describe('Local File System Storage', function () { it('should send correct path to image when date is in Sep 2013', function (done) { localfilesystem.save(image).then(function (url) { - url.should.equal('/content/images/2013/Sep/IMAGE.jpg'); + url.should.equal('/content/images/2013/09/IMAGE.jpg'); return done(); }).catch(done); }); @@ -61,7 +61,7 @@ describe('Local File System Storage', function () { it('should send correct path to image when original file has spaces', function (done) { image.name = 'AN IMAGE.jpg'; localfilesystem.save(image).then(function (url) { - url.should.equal('/content/images/2013/Sep/AN-IMAGE.jpg'); + url.should.equal('/content/images/2013/09/AN-IMAGE.jpg'); return done(); }).catch(done); }); @@ -70,7 +70,7 @@ describe('Local File System Storage', function () { // Jan 1 2014 12:00 this.clock = sinon.useFakeTimers(new Date(2014, 0, 1, 12).getTime()); localfilesystem.save(image).then(function (url) { - url.should.equal('/content/images/2014/Jan/IMAGE.jpg'); + url.should.equal('/content/images/2014/01/IMAGE.jpg'); return done(); }).catch(done); }); @@ -79,7 +79,7 @@ describe('Local File System Storage', function () { 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')); + fs.mkdirs.args[0][0].should.equal(path.resolve('./content/images/2013/09')); done(); }).catch(done); }); @@ -89,7 +89,7 @@ describe('Local File System Storage', function () { /*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')); + fs.copy.args[0][1].should.equal(path.resolve('./content/images/2013/09/IMAGE.jpg')); done(); }).catch(done); }); @@ -97,8 +97,8 @@ describe('Local File System Storage', function () { it('can upload two different images with the same name without overwriting the first', function (done) { // Sun Sep 08 2013 10:57 this.clock = sinon.useFakeTimers(new Date(2013, 8, 8, 10, 57).getTime()); - fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE.jpg')).yields(true); - fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE-1.jpg')).yields(false); + fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE.jpg')).yields(true); + fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE-1.jpg')).yields(false); // if on windows need to setup with back slashes // doesn't hurt for the test to cope with both @@ -106,7 +106,7 @@ describe('Local File System Storage', function () { fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-1.jpg')).yields(false); localfilesystem.save(image).then(function (url) { - url.should.equal('/content/images/2013/Sep/IMAGE-1.jpg'); + url.should.equal('/content/images/2013/09/IMAGE-1.jpg'); return done(); }).catch(done); }); @@ -114,11 +114,11 @@ describe('Local File System Storage', function () { it('can upload five different images with the same name without overwriting the first', function (done) { // Sun Sep 08 2013 10:57 this.clock = sinon.useFakeTimers(new Date(2013, 8, 8, 10, 57).getTime()); - fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE.jpg')).yields(true); - fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE-1.jpg')).yields(true); - fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE-2.jpg')).yields(true); - fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE-3.jpg')).yields(true); - fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE-4.jpg')).yields(false); + fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE.jpg')).yields(true); + fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE-1.jpg')).yields(true); + fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE-2.jpg')).yields(true); + fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE-3.jpg')).yields(true); + fs.exists.withArgs(path.resolve('./content/images/2013/09/IMAGE-4.jpg')).yields(false); // windows setup fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE.jpg')).yields(true); @@ -128,7 +128,7 @@ describe('Local File System Storage', function () { fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-4.jpg')).yields(false); localfilesystem.save(image).then(function (url) { - url.should.equal('/content/images/2013/Sep/IMAGE-4.jpg'); + url.should.equal('/content/images/2013/09/IMAGE-4.jpg'); return done(); }).catch(done); }); @@ -149,7 +149,7 @@ describe('Local File System Storage', function () { it('should send the correct path to image', function (done) { localfilesystem.save(image).then(function (url) { - url.should.equal('/content/images/2013/Sep/IMAGE.jpg'); + url.should.equal('/content/images/2013/09/IMAGE.jpg'); return done(); }).catch(done); }); @@ -169,19 +169,19 @@ describe('Local File System Storage', function () { it('should return url in proper format for windows', function (done) { path.sep = '\\'; - path.join.returns('content\\images\\2013\\Sep\\IMAGE.jpg'); + path.join.returns('content\\images\\2013\\09\\IMAGE.jpg'); localfilesystem.save(image).then(function (url) { if (truePathSep === '\\') { - url.should.equal('/content/images/2013/Sep/IMAGE.jpg'); + url.should.equal('/content/images/2013/09/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 // 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'); + path.normalize(url).should.equal('/content/images/2013/09/IMAGE.jpg'); } return done(); }).catch(done); }); }); -}); \ No newline at end of file +});