Don't cache static scope method results #575

This commit is contained in:
Fabien Franzen 2015-07-03 10:17:13 +02:00
parent 88229fb5cf
commit 5290559a42
2 changed files with 23 additions and 1 deletions

View File

@ -52,7 +52,7 @@ ScopeDefinition.prototype.related = function(receiver, scopeParams, condOrRefres
var actualCond = {}; var actualCond = {};
var actualRefresh = false; var actualRefresh = false;
var saveOnCache = true; var saveOnCache = receiver instanceof DefaultModelBaseClass;
if (typeof condOrRefresh === 'function' && if (typeof condOrRefresh === 'function' &&
options === undefined && cb === undefined) { options === undefined && cb === undefined) {
// related(receiver, scopeParams, cb) // related(receiver, scopeParams, cb)

View File

@ -75,6 +75,28 @@ describe('scope', function () {
}); });
}); });
}); });
it('should not cache any results', function (done) {
Station.scope('active', {where: {isActive: true}});
Station.active.create(function (err, s) {
if (err) return done(err);
s.isActive.should.be.true;
Station.active(function(err, ss) {
if (err) return done(err);
ss.should.have.lengthOf(1);
ss[0].id.should.eql(s.id);
s.updateAttribute('isActive', false, function(err, s) {
if (err) return done(err);
s.isActive.should.be.false;
Station.active(function(err, ss) {
if (err) return done(err);
ss.should.have.lengthOf(0);
done();
});
});
});
});
});
}); });