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 || [];
|
var transports = settings.transports || [];
|
||||||
this.transportsIndex = {};
|
this.transportsIndex = {};
|
||||||
this.transports = [];
|
this.transports = [];
|
||||||
|
|
||||||
transports.forEach(this.setupTransport.bind(this));
|
transports.forEach(this.setupTransport.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,10 +83,9 @@ MailConnector.prototype.transportForName = function(name) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MailConnector.prototype.defaultTransport = function() {
|
MailConnector.prototype.defaultTransport = function() {
|
||||||
return this.transports[0];
|
return this.transports[0] || this.stubTransport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send an email with the given `options`.
|
* Send an email with the given `options`.
|
||||||
*
|
*
|
||||||
|
@ -110,6 +109,8 @@ Mailer.send = function (options, fn) {
|
||||||
var dataSource = this.dataSource;
|
var dataSource = this.dataSource;
|
||||||
var settings = dataSource && dataSource.settings;
|
var settings = dataSource && dataSource.settings;
|
||||||
var connector = dataSource.connector;
|
var connector = dataSource.connector;
|
||||||
|
assert(connector, 'Cannot send mail without a connector!');
|
||||||
|
|
||||||
var transport = connector.transportForName(options.transport);
|
var transport = connector.transportForName(options.transport);
|
||||||
|
|
||||||
if(!transport) {
|
if(!transport) {
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
var loopback = require('../');
|
var loopback = require('../');
|
||||||
var MyEmail = loopback.Email.extend('my-email');
|
var MyEmail;
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
|
||||||
describe('Email and SMTP', function () {
|
describe('Email and SMTP', function () {
|
||||||
|
beforeEach(function() {
|
||||||
|
MyEmail = loopback.Email.extend('my-email');
|
||||||
|
loopback.autoAttach();
|
||||||
|
});
|
||||||
|
|
||||||
it('should have a send method', function () {
|
it('should have a send method', function () {
|
||||||
assert(typeof MyEmail.send === 'function');
|
assert(typeof MyEmail.send === 'function');
|
||||||
assert(typeof MyEmail.prototype.send === 'function');
|
assert(typeof MyEmail.prototype.send === 'function');
|
||||||
|
|
Loading…
Reference in New Issue