Merge pull request #576 from fabien/fix/scope-caching

Don't cache static scope method results
This commit is contained in:
Miroslav Bajtoš 2015-07-03 10:49:41 +02:00
commit 014e91ea0c
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 actualRefresh = false;
var saveOnCache = true;
var saveOnCache = receiver instanceof DefaultModelBaseClass;
if (typeof condOrRefresh === 'function' &&
options === undefined && cb === undefined) {
// related(receiver, scopeParams, cb)

View File

@ -76,6 +76,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();
});
});
});
});
});
});
describe('scope - order', function () {