Skip to content

Commit

Permalink
Fix regression in Model.getApp()
Browse files Browse the repository at this point in the history
This patch fixes the method Model.getApp() that started to report
the following error after b61fae5 was landed:

assert.js:88
  throw new assert.AssertionError({
        ^
AssertionError: undefined == true
    at loopback/loopback/lib/model.js:392:7
    at EventEmitter.<anonymous> (loopback/loopback/lib/model.js:222:9)
    at EventEmitter.g (events.js:257:16)
    at emitOne (events.js:77:13)
    at EventEmitter.emit (events.js:166:7)
    at EventEmitter.app.model (loopback/loopback/lib/application.js:157:9)
  • Loading branch information
Miroslav Bajtoš committed Apr 28, 2015
1 parent f93590d commit b6b76d5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};

Expand Down
29 changes: 29 additions & 0 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
});

0 comments on commit b6b76d5

Please sign in to comment.