Merge pull request #1343 from strongloop/fix/app-getApp

Fix regression in Model.getApp()
This commit is contained in:
Miroslav Bajtoš 2015-04-28 18:08:27 +02:00
commit ff5f507560
2 changed files with 34 additions and 3 deletions

View File

@ -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);
});
};

View File

@ -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
});
});
});