-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add propertyName to the attachment's defaultUrl
- allows multiple attachments with the same styles closes #1
- Loading branch information
Showing
4 changed files
with
57 additions
and
3 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
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,41 @@ | ||
var mongoose = require('mongoose'); | ||
var expect = require('chai').expect; | ||
var fs = require('fs'); | ||
var plugin = require('../lib/attachments'); | ||
|
||
var fakeProvider = function(){}; | ||
fakeProvider.prototype.getUrl = function(path){ | ||
return path; | ||
}; | ||
fakeProvider.prototype.createOrReplace = function(attachment, next){ | ||
attachment.defaultUrl = this.getUrl(attachment.path); | ||
next(null, attachment); | ||
}; | ||
|
||
plugin.registerStorageProvider('fakeProvider', fakeProvider); | ||
|
||
UserSchema = new mongoose.Schema({ }); | ||
UserSchema.plugin(plugin, { | ||
directory: process.cwd() + '/public/users', | ||
storage: { providerName: 'fakeProvider', options: { } }, | ||
properties: { | ||
profile: { styles: { original: { } } }, | ||
avatar: { styles: { original: { } } } | ||
} | ||
}); | ||
var User = mongoose.model('User', UserSchema); | ||
|
||
describe('path', function(){ | ||
it('adds the propertyName in the attached image path', function(done){ | ||
var user = new User({}); | ||
var path = { path: process.cwd() + '/test/fixtures/mongodb.png' }; | ||
user.attach('profile', path, function(err){ | ||
user.attach('avatar', path, function(err){ | ||
expect(user.avatar.original.defaultUrl).to.not.eql(user.profile.original.defaultUrl); | ||
expect(user.avatar.original.defaultUrl).to.include('users/avatar/' + user.id + '-original.png'); | ||
expect(user.profile.original.defaultUrl).to.include('users/profile/' + user.id + '-original.png'); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.