Merge pull request #955 from alFReD-NSH/checkpoint-leak

Fix Change.getCheckpointModel() giving new models each call
This commit is contained in:
Ritchie Martori 2015-01-05 09:40:29 -08:00
commit 270dfc2603
2 changed files with 7 additions and 1 deletions

View File

@ -419,7 +419,7 @@ module.exports = function(Change) {
Change.getCheckpointModel = function() { Change.getCheckpointModel = function() {
var checkpointModel = this.Checkpoint; var checkpointModel = this.Checkpoint;
if (checkpointModel) return checkpointModel; if (checkpointModel) return checkpointModel;
this.checkpoint = checkpointModel = loopback.Checkpoint.extend('checkpoint'); this.Checkpoint = checkpointModel = loopback.Checkpoint.extend('checkpoint');
assert(this.dataSource, 'Cannot getCheckpointModel(): ' + this.modelName assert(this.dataSource, 'Cannot getCheckpointModel(): ' + this.modelName
+ ' is not attached to a dataSource'); + ' is not attached to a dataSource');
checkpointModel.attachTo(this.dataSource); checkpointModel.attachTo(this.dataSource);

View File

@ -28,6 +28,12 @@ describe('Change', function() {
}); });
}); });
describe('Change.getCheckpointModel()', function() {
it('Shouldnt create two models if called twice', function() {
assert.equal(Change.getCheckpointModel(), Change.getCheckpointModel());
});
});
describe('change.id', function() { describe('change.id', function() {
it('should be a hash of the modelName and modelId', function() { it('should be a hash of the modelName and modelId', function() {
var change = new Change({ var change = new Change({