-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from achingbrain/master
Allows specifying a directory to the provider configuration
- Loading branch information
Showing
8 changed files
with
122 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,11 @@ lib-cov | |
*.out | ||
*.pid | ||
*.gz | ||
*.iml | ||
|
||
pids | ||
logs | ||
results | ||
|
||
node_modules | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var attachments = require(__dirname + '/../../lib/localfs-provider'); | ||
var mongoose = require('mongoose'); | ||
var Schema = mongoose.Schema; | ||
var os = require("os"); | ||
|
||
var StubSchema = new Schema({ | ||
name: { | ||
type: String, | ||
required: true | ||
} | ||
}); | ||
|
||
StubSchema.plugin(attachments, { | ||
directory: os.tmpdir(), | ||
storage: { | ||
providerName: 'localfs' | ||
}, | ||
properties: { | ||
image: { | ||
styles: { | ||
image: { | ||
'$format': 'jpg' | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
module.exports = mongoose.model('Foo', StubSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var attachments = require(__dirname + '/../../lib/localfs-provider'); | ||
var mongoose = require('mongoose'); | ||
var Schema = mongoose.Schema; | ||
var os = require("os"); | ||
|
||
var StubSchema = new Schema({ | ||
name: { | ||
type: String, | ||
required: true | ||
} | ||
}); | ||
|
||
StubSchema.plugin(attachments, { | ||
directory: os.tmpdir(), | ||
storage: { | ||
providerName: 'localfs', | ||
options: { | ||
directory: os.tmpdir() + '/localfs-test' | ||
} | ||
}, | ||
properties: { | ||
image: { | ||
styles: { | ||
image: { | ||
'$format': 'jpg' | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
module.exports = mongoose.model('Bar', StubSchema); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var should = require('should'); | ||
var path = require('path'); | ||
var Foo = require(path.resolve(__dirname, './fixtures/StubSchema')); | ||
var Bar = require(path.resolve(__dirname, './fixtures/StubSchemaWithOverriddenDirectory')); | ||
var os = require('os'); | ||
|
||
describe('localfs', function() { | ||
it('should move an attachment to a specified directory', function (done) { | ||
var foo = new Foo(); | ||
foo.attach('image', { | ||
path: path.resolve(__dirname, './fixtures/node_js_logo.png') | ||
}, function(error) { | ||
if(error) throw error; | ||
|
||
foo.image.image.path.should.startWith(os.tmpdir()); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should use a separate directory for temporary files', function (done) { | ||
var bar = new Bar(); | ||
bar.attach('image', { | ||
path: path.resolve(__dirname, './fixtures/node_js_logo.png') | ||
}, function(error) { | ||
if(error) throw error; | ||
|
||
// the Bar schema uses os.tmpdir() for imagemagick temporary files and | ||
// os.tmpdir() + '/localfs-test' for the output directory | ||
path.dirname(bar.image.image.path).should.not.equal(os.tmpdir()); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); |