Merge pull request #1343 from strongloop/fix/app-getApp
Fix regression in Model.getApp()
This commit is contained in:
commit
ff5f507560
|
@ -388,9 +388,11 @@ module.exports = function(registry) {
|
|||
*/
|
||||
|
||||
Model.getApp = function(callback) {
|
||||
this._runWhenAttachedToApp(function(app) {
|
||||
assert(Model.app);
|
||||
callback(null, Model.app);
|
||||
var self = this;
|
||||
self._runWhenAttachedToApp(function(app) {
|
||||
assert(self.app);
|
||||
assert.equal(app, self.app);
|
||||
callback(null, app);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -618,4 +618,33 @@ describe.onServer('Remote Methods', function() {
|
|||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Model.getApp(cb)', function() {
|
||||
var app, TestModel;
|
||||
beforeEach(function setup() {
|
||||
app = loopback();
|
||||
TestModel = loopback.createModel('TestModelForGetApp'); // unique name
|
||||
app.dataSource('db', { connector: 'memory' });
|
||||
});
|
||||
|
||||
it('calls the callback when already attached', function(done) {
|
||||
app.model(TestModel, { dataSource: 'db' });
|
||||
TestModel.getApp(function(err, a) {
|
||||
if (err) return done(err);
|
||||
expect(a).to.equal(app);
|
||||
done();
|
||||
});
|
||||
// fails on time-out when not implemented correctly
|
||||
});
|
||||
|
||||
it('calls the callback after attached', function(done) {
|
||||
TestModel.getApp(function(err, a) {
|
||||
if (err) return done(err);
|
||||
expect(a).to.equal(app);
|
||||
done();
|
||||
});
|
||||
app.model(TestModel, { dataSource: 'db' });
|
||||
// fails on time-out when not implemented correctly
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue