Fix race condition where MyEmail model was not attached to the correct dataSource in tests
This commit is contained in:
parent
d6a4230aed
commit
a43d6004c1
|
@ -22,7 +22,7 @@ function MailConnector(settings) {
|
|||
var transports = settings.transports || [];
|
||||
this.transportsIndex = {};
|
||||
this.transports = [];
|
||||
|
||||
|
||||
transports.forEach(this.setupTransport.bind(this));
|
||||
}
|
||||
|
||||
|
@ -83,10 +83,9 @@ MailConnector.prototype.transportForName = function(name) {
|
|||
*/
|
||||
|
||||
MailConnector.prototype.defaultTransport = function() {
|
||||
return this.transports[0];
|
||||
return this.transports[0] || this.stubTransport;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send an email with the given `options`.
|
||||
*
|
||||
|
@ -110,6 +109,8 @@ Mailer.send = function (options, fn) {
|
|||
var dataSource = this.dataSource;
|
||||
var settings = dataSource && dataSource.settings;
|
||||
var connector = dataSource.connector;
|
||||
assert(connector, 'Cannot send mail without a connector!');
|
||||
|
||||
var transport = connector.transportForName(options.transport);
|
||||
|
||||
if(!transport) {
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
var loopback = require('../');
|
||||
var MyEmail = loopback.Email.extend('my-email');
|
||||
var MyEmail;
|
||||
var assert = require('assert');
|
||||
|
||||
describe('Email and SMTP', function () {
|
||||
|
||||
beforeEach(function() {
|
||||
MyEmail = loopback.Email.extend('my-email');
|
||||
loopback.autoAttach();
|
||||
});
|
||||
|
||||
it('should have a send method', function () {
|
||||
assert(typeof MyEmail.send === 'function');
|
||||
assert(typeof MyEmail.prototype.send === 'function');
|
||||
|
|
Loading…
Reference in New Issue