From 3fe1e0304aba67f807f9b1cb2d61c15d19f7dc28 Mon Sep 17 00:00:00 2001 From: crwang Date: Wed, 30 Jul 2014 14:11:46 +0800 Subject: [PATCH 1/4] Added in clear methods to model and collection stores --- shared/store/collection_store.js | 9 +++++++++ shared/store/model_store.js | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/shared/store/collection_store.js b/shared/store/collection_store.js index a56d3598..324796b5 100644 --- a/shared/store/collection_store.js +++ b/shared/store/collection_store.js @@ -30,6 +30,15 @@ _.extend(CollectionStore.prototype, Super.prototype, { return cachedCollection; }, + clear: function(collectionName, params) { + if (collectionName && params) { + var key = this._getStoreKey(collectionName, params); + return Super.prototype.clear.call(this, key); + } else { + return Super.prototype.clear.call(this, null); + } + }, + mergeParams: function(collectionName, params, callback) { this.modelUtils.getCollectionConstructor(collectionName, function(Collection) { var mergedParams = _.extend({}, Collection.prototype.defaultParams, params); diff --git a/shared/store/model_store.js b/shared/store/model_store.js index b3a52cf8..9169d7ef 100644 --- a/shared/store/model_store.js +++ b/shared/store/model_store.js @@ -38,6 +38,15 @@ _.extend(ModelStore.prototype, Super.prototype, { } }, + clear: function(modelName, id) { + if (modelName && id) { + var key = this._getModelStoreKey(modelName, id); + return Super.prototype.clear.call(this, key); + } else { + return Super.prototype.clear.call(this, null); + } + }, + find: function(modelName, params) { var prefix = this._formatKey(this._keyPrefix(modelName)), keys = Object.keys(this.cache), From d8d2f2a7084b052fb07dce13c437279c92320340 Mon Sep 17 00:00:00 2001 From: crwang Date: Thu, 21 Aug 2014 10:08:03 +0800 Subject: [PATCH 2/4] Added tests and changed to not clear all collections if collection name is empty --- shared/store/collection_store.js | 2 +- test/shared/store/collection_store.test.js | 93 ++++++++++++++++++++++ test/shared/store/model_store.test.js | 45 +++++++++++ 3 files changed, 139 insertions(+), 1 deletion(-) diff --git a/shared/store/collection_store.js b/shared/store/collection_store.js index 324796b5..4c8ec79e 100644 --- a/shared/store/collection_store.js +++ b/shared/store/collection_store.js @@ -31,7 +31,7 @@ _.extend(CollectionStore.prototype, Super.prototype, { }, clear: function(collectionName, params) { - if (collectionName && params) { + if ((collectionName !== null) && !_.isUndefined(collectionName) && params) { var key = this._getStoreKey(collectionName, params); return Super.prototype.clear.call(this, key); } else { diff --git a/test/shared/store/collection_store.test.js b/test/shared/store/collection_store.test.js index 21199ca9..bbfc8df4 100644 --- a/test/shared/store/collection_store.test.js +++ b/test/shared/store/collection_store.test.js @@ -149,4 +149,97 @@ describe('CollectionStore', function() { should.exist(results); results.should.be.equal(collection); }); + + it("should allow clearing out of the store by params", function() { + + var collection0, collection10, models0, models10, params0, params10, results0, results10; + + models0 = [ + { + foo: 'bar', + id: 1 + }, { + foo: 'bot', + id: 2 + } + ]; + models10 = [ + { + foo: 'bar', + id: 11 + }, { + foo: 'bot', + id: 12 + } + ]; + params0 = { + offset: 0 + }; + collection0 = new BaseCollection(models0, {params: params0}); + this.store.set(collection0, params0); + params10 = {offset: 10}; + collection10 = new BaseCollection(models10, {params: params10}); + this.store.set(collection10, params10); + this.store.clear(collection0.constructor.name, params0); + results0 = this.store.get(collection0.constructor.name, params0); + should.not.exist(results0); + results10 = this.store.get(collection10.constructor.name, params10); + should.exist(results10); + }); + + it("should allow clearing out of the store", function() { + + var collection0, collection10, models0, models10, params0, params10, results0, results10; + + models0 = [ + { + foo: 'bar', + id: 1 + }, { + foo: 'bot', + id: 2 + } + ]; + models10 = [ + { + foo: 'bar', + id: 11 + }, { + foo: 'bot', + id: 12 + } + ]; + params0 = { + offset: 0 + }; + params10 = {offset: 10}; + collection0 = new BaseCollection(models0, {params: params0}); + collection10 = new BaseCollection(models10, {params: params10}); + + this.store.set(collection0, params0); + this.store.set(collection10, params10); + results0 = this.store.get(collection0.constructor.name, params0); + results10 = this.store.get(collection10.constructor.name, params10); + should.exist(results0); + should.exist(results10); + this.store.clear(collection0.constructor.name); + results0 = this.store.get(collection0.constructor.name, params0); + results10 = this.store.get(collection10.constructor.name, params10); + should.not.exist(results0); + should.not.exist(results10); + + this.store.set(collection0, params0); + this.store.set(collection10, params10); + results0 = this.store.get(collection0.constructor.name, params0); + results10 = this.store.get(collection10.constructor.name, params10); + should.exist(results0); + should.exist(results10); + this.store.clear(); + results0 = this.store.get(collection0.constructor.name, params0); + results10 = this.store.get(collection10.constructor.name, params10); + should.not.exist(results0); + should.not.exist(results10); + + }); + }); diff --git a/test/shared/store/model_store.test.js b/test/shared/store/model_store.test.js index 4b1cd7e2..22614cd1 100644 --- a/test/shared/store/model_store.test.js +++ b/test/shared/store/model_store.test.js @@ -76,6 +76,51 @@ describe('ModelStore', function() { resultModel.should.be.equal(model); }); + it("should allow clearing out of the store by id", function() { + var model, modelAttrs, resultModel; + + modelAttrs = { + foo: 'foo', + id: 1 + }; + + model = new MyModel(modelAttrs, {app: this.app}); + this.store.set(model); + resultModel = this.store.get('my_model', 1, true); + should.exist(resultModel); + this.store.clear(modelAttrs.id); + resultModel = this.store.get('my_model', 1, true); + should.not.exist(resultModel); + }); + + it("should allow clearing out the store", function() { + var model, modelAttrs, resultModel; + + modelAttrs = { + foo: 'foo', + id: 1 + }; + modelAttrs2 = { + foo: 'bar', + id: 2 + }; + + model = new MyModel(modelAttrs, {app: this.app}); + this.store.set(model); + model = new MyModel(modelAttrs2, {app: this.app}); + this.store.set(model); + + resultModel = this.store.get('my_model', 1, true); + should.exist(resultModel); + resultModel = this.store.get('my_model', 2, true); + should.exist(resultModel); + this.store.clear(); + resultModel = this.store.get('my_model', 1, true); + should.not.exist(resultModel); + resultModel = this.store.get('my_model', 2, true); + should.not.exist(resultModel); + }); + describe('find', function(){ function MySecondModel() { MySecondModel.super_.apply(this, arguments); From d1930fb737fdd01a3aa50a537131f4e966ab597e Mon Sep 17 00:00:00 2001 From: crwang Date: Thu, 27 Nov 2014 11:38:49 +0800 Subject: [PATCH 3/4] Added in context to the tests --- test/shared/store/collection_store.test.js | 158 ++++++++---------- test/shared/store/model_store.test.js | 176 ++++++++++----------- 2 files changed, 148 insertions(+), 186 deletions(-) diff --git a/test/shared/store/collection_store.test.js b/test/shared/store/collection_store.test.js index bbfc8df4..8f7ada57 100644 --- a/test/shared/store/collection_store.test.js +++ b/test/shared/store/collection_store.test.js @@ -150,96 +150,72 @@ describe('CollectionStore', function() { results.should.be.equal(collection); }); - it("should allow clearing out of the store by params", function() { - - var collection0, collection10, models0, models10, params0, params10, results0, results10; - - models0 = [ - { - foo: 'bar', - id: 1 - }, { - foo: 'bot', - id: 2 - } - ]; - models10 = [ - { - foo: 'bar', - id: 11 - }, { - foo: 'bot', - id: 12 - } - ]; - params0 = { - offset: 0 - }; - collection0 = new BaseCollection(models0, {params: params0}); - this.store.set(collection0, params0); - params10 = {offset: 10}; - collection10 = new BaseCollection(models10, {params: params10}); - this.store.set(collection10, params10); - this.store.clear(collection0.constructor.name, params0); - results0 = this.store.get(collection0.constructor.name, params0); - should.not.exist(results0); - results10 = this.store.get(collection10.constructor.name, params10); - should.exist(results10); - }); - - it("should allow clearing out of the store", function() { - - var collection0, collection10, models0, models10, params0, params10, results0, results10; - - models0 = [ - { - foo: 'bar', - id: 1 - }, { - foo: 'bot', - id: 2 - } - ]; - models10 = [ - { - foo: 'bar', - id: 11 - }, { - foo: 'bot', - id: 12 - } - ]; - params0 = { - offset: 0 - }; - params10 = {offset: 10}; - collection0 = new BaseCollection(models0, {params: params0}); - collection10 = new BaseCollection(models10, {params: params10}); - - this.store.set(collection0, params0); - this.store.set(collection10, params10); - results0 = this.store.get(collection0.constructor.name, params0); - results10 = this.store.get(collection10.constructor.name, params10); - should.exist(results0); - should.exist(results10); - this.store.clear(collection0.constructor.name); - results0 = this.store.get(collection0.constructor.name, params0); - results10 = this.store.get(collection10.constructor.name, params10); - should.not.exist(results0); - should.not.exist(results10); - - this.store.set(collection0, params0); - this.store.set(collection10, params10); - results0 = this.store.get(collection0.constructor.name, params0); - results10 = this.store.get(collection10.constructor.name, params10); - should.exist(results0); - should.exist(results10); - this.store.clear(); - results0 = this.store.get(collection0.constructor.name, params0); - results10 = this.store.get(collection10.constructor.name, params10); - should.not.exist(results0); - should.not.exist(results10); - - }); + context("there is data to be cleared", function() { + var collection, collection2, models, models2, params, params2, resultsCollection; + + beforeEach(function() { + models = [ + { + foo: 'bar', + id: 1 + }, { + foo: 'bot', + id: 2 + } + ]; + models2 = [ + { + foo: 'bar', + id: 11 + }, { + foo: 'bot', + id: 12 + } + ]; + params = { + offset: 0 + }; + params2 = {offset: 10}; + collection = new BaseCollection(models, {params: params}); + collection2 = new BaseCollection(models2, {params: params2}); + }); + it("should allow clearing out of the store by params", function() { + this.store.set(collection, params); + this.store.set(collection2, params2); + this.store.clear(collection.constructor.name, params); + resultsCollection = this.store.get(collection.constructor.name, params); + should.not.exist(resultsCollection); + resultsCollection = this.store.get(collection2.constructor.name, params2); + should.exist(resultsCollection); + }); + + it("should allow clearing out of the store", function() { + this.store.set(collection, params); + this.store.set(collection2, params2); + resultsCollection = this.store.get(collection.constructor.name, params); + should.exist(resultsCollection); + resultsCollection = this.store.get(collection2.constructor.name, params2); + should.exist(resultsCollection); + + this.store.clear(collection.constructor.name); + resultsCollection = this.store.get(collection.constructor.name, params); + should.not.exist(resultsCollection); + resultsCollection = this.store.get(collection2.constructor.name, params2); + should.not.exist(resultsCollection); + + this.store.set(collection, params); + this.store.set(collection2, params2); + resultsCollection = this.store.get(collection.constructor.name, params); + should.exist(resultsCollection); + resultsCollection = this.store.get(collection2.constructor.name, params2); + should.exist(resultsCollection); + + this.store.clear(); + resultsCollection = this.store.get(collection.constructor.name, params); + should.not.exist(resultsCollection); + resultsCollection = this.store.get(collection2.constructor.name, params2); + should.not.exist(resultsCollection); + }); + }); }); diff --git a/test/shared/store/model_store.test.js b/test/shared/store/model_store.test.js index 22614cd1..f1ef8ad9 100644 --- a/test/shared/store/model_store.test.js +++ b/test/shared/store/model_store.test.js @@ -18,6 +18,7 @@ function App() {} addClassMapping.add(modelUtils.modelName(MyModel), MyModel); describe('ModelStore', function() { + var model, result; beforeEach(function() { this.app = new App({modelUtils: modelUtils}); this.store = new ModelStore({ @@ -26,21 +27,8 @@ describe('ModelStore', function() { }); }); - it("should get and set the values for a model", function() { - var model, modelAttrs, result; - - modelAttrs = { - foo: 'bar', - id: 1 - }; - model = new MyModel(modelAttrs); - this.store.set(model); - result = this.store.get('my_model', 1); - result.should.eql(modelAttrs); - }); - it("should support custom idAttribute", function() { - var model, modelAttrs, result; + var modelAttrs; modelAttrs = { foo: 'bar', @@ -60,97 +48,95 @@ describe('ModelStore', function() { result.should.eql(modelAttrs); }); - it("should support returning a model instance", function() { - var model, modelAttrs, resultModel; + context("there is a model with id", function () { + var defaultModelAttrs; - modelAttrs = { - foo: 'bar', - id: 1 - }; - model = new MyModel(modelAttrs, {app: this.app}); - this.store.set(model); - resultModel = this.store.get('my_model', 1, true); - resultModel.should.be.an.instanceOf(BaseModel); - resultModel.toJSON().should.eql(modelAttrs); - resultModel.app.should.eql(this.app); - resultModel.should.be.equal(model); - }); - - it("should allow clearing out of the store by id", function() { - var model, modelAttrs, resultModel; - - modelAttrs = { - foo: 'foo', - id: 1 - }; - - model = new MyModel(modelAttrs, {app: this.app}); - this.store.set(model); - resultModel = this.store.get('my_model', 1, true); - should.exist(resultModel); - this.store.clear(modelAttrs.id); - resultModel = this.store.get('my_model', 1, true); - should.not.exist(resultModel); - }); + beforeEach(function() { + defaultModelAttrs = { + foo: 'bar', + id: 1 + }; - it("should allow clearing out the store", function() { - var model, modelAttrs, resultModel; + model = new MyModel(defaultModelAttrs, { app: this.app }); + }); - modelAttrs = { - foo: 'foo', - id: 1 - }; - modelAttrs2 = { - foo: 'bar', - id: 2 - }; - - model = new MyModel(modelAttrs, {app: this.app}); - this.store.set(model); - model = new MyModel(modelAttrs2, {app: this.app}); - this.store.set(model); + it("should get and set the values for a model", function() { + var resultModel; - resultModel = this.store.get('my_model', 1, true); - should.exist(resultModel); - resultModel = this.store.get('my_model', 2, true); - should.exist(resultModel); - this.store.clear(); - resultModel = this.store.get('my_model', 1, true); - should.not.exist(resultModel); - resultModel = this.store.get('my_model', 2, true); - should.not.exist(resultModel); - }); - - describe('find', function(){ - function MySecondModel() { - MySecondModel.super_.apply(this, arguments); - } - util.inherits(MySecondModel, BaseModel); + this.store.set(model); + resultModel = this.store.get('my_model', defaultModelAttrs.id); + resultModel.should.eql(defaultModelAttrs); + }); - addClassMapping.add(modelUtils.modelName(MySecondModel), MySecondModel); + it("should support returning a model instance", function() { + var resultModel; - it('should find a model on custom attributes', function(){ - var model, modelAttrs, result; - modelAttrs = { - foo: 'bar', - id: 1 - }; - model = new MyModel(modelAttrs); this.store.set(model); - result = this.store.find('my_model', {foo: 'bar'}); - result.should.eql(modelAttrs); + resultModel = this.store.get('my_model', defaultModelAttrs.id, true); + resultModel.should.be.an.instanceOf(BaseModel); + resultModel.toJSON().should.eql(defaultModelAttrs); + resultModel.app.should.eql(this.app); + resultModel.should.be.equal(model); }); - it('should skip different models, even when they match the query', function(){ - var model, modelAttrs, result; - modelAttrs = { - foo: 'bar', - id: 1 - }; - model = new MySecondModel(modelAttrs); + it("should be able to be cleared from the store by id", function() { + var resultModel; + this.store.set(model); - result = this.store.find('my_model', {foo: 'bar'}); - should.equal(result, undefined); + resultModel = this.store.get('my_model', defaultModelAttrs.id, true); + should.exist(resultModel); + this.store.clear(defaultModelAttrs.id); + resultModel = this.store.get('my_model', defaultModelAttrs.id, true); + should.not.exist(resultModel); + }); + + describe('find', function(){ + function MySecondModel() { + MySecondModel.super_.apply(this, arguments); + } + util.inherits(MySecondModel, BaseModel); + + addClassMapping.add(modelUtils.modelName(MySecondModel), MySecondModel); + + it('should find a model on custom attributes', function(){ + this.store.set(model); + resultModel = this.store.find('my_model', {foo: 'bar'}); + resultModel.should.eql(defaultModelAttrs); + }); + + it('should skip different models, even when they match the query', function(){ + model = new MySecondModel(defaultModelAttrs); + this.store.set(model); + resultModel = this.store.find('my_model', {foo: 'bar'}); + should.equal(resultModel, undefined); + }); + }); + context("more than one model", function () { + var defaultModelAttrs2, model2; + + beforeEach(function() { + defaultModelAttrs2 = { + foo: 'bar2', + id: 2 + }; + model2 = new MyModel(defaultModelAttrs2, { app: this.app }); + }); + + it("all should be able to be cleared from the store", function() { + + this.store.set(model); + this.store.set(model2); + + resultModel = this.store.get('my_model', defaultModelAttrs.id, true); + should.exist(resultModel); + resultModel = this.store.get('my_model', defaultModelAttrs2.id, true); + should.exist(resultModel); + this.store.clear(); + resultModel = this.store.get('my_model', defaultModelAttrs.id, true); + should.not.exist(resultModel); + resultModel = this.store.get('my_model', defaultModelAttrs2.id, true); + should.not.exist(resultModel); + }); }); }); }); From ca42ebd483cc79973a94e0501b2db6677bb0e6d7 Mon Sep 17 00:00:00 2001 From: crwang Date: Tue, 9 Dec 2014 14:49:19 +0800 Subject: [PATCH 4/4] Added in ability to clear all instances of a model or a collection out of the cache --- shared/store/collection_store.js | 22 +++++++++++- shared/store/model_store.js | 17 +++++++++- test/shared/store/collection_store.test.js | 33 ++++++++++++++---- test/shared/store/model_store.test.js | 39 ++++++++++++++++++++-- 4 files changed, 100 insertions(+), 11 deletions(-) diff --git a/shared/store/collection_store.js b/shared/store/collection_store.js index 4c8ec79e..2c2c7dad 100644 --- a/shared/store/collection_store.js +++ b/shared/store/collection_store.js @@ -31,9 +31,17 @@ _.extend(CollectionStore.prototype, Super.prototype, { }, clear: function(collectionName, params) { - if ((collectionName !== null) && !_.isUndefined(collectionName) && params) { + if (!_.isUndefined(collectionName) && params) { var key = this._getStoreKey(collectionName, params); return Super.prototype.clear.call(this, key); + } else if (!_.isUndefined(collectionName) && !params) { + var cachedItems = this._getCachedItemsByCollection(collectionName), + self = this, + storeKey; + _.each(cachedItems, function (item) { + storeKey = self._getStoreKey(collectionName, item.value.params); + Super.prototype.clear.call(self, storeKey); + }); } else { return Super.prototype.clear.call(this, null); } @@ -46,6 +54,14 @@ _.extend(CollectionStore.prototype, Super.prototype, { }); }, + _getCachedItemsByCollection:function(collectionName) { + var prefix = this._formatKey(this.modelUtils.underscorize(collectionName)); + + return _.filter(this.cache, function(val, key) { + return startsWith(key, prefix); + }); + }, + _getStoreKeyForCollection: function(collection, params) { var collectionName = this.modelUtils.modelName(collection.constructor); @@ -66,3 +82,7 @@ function sortParams(params) { }); return sorted; } + +function startsWith(string, prefix) { + return string.slice(0, prefix.length) == prefix; +} \ No newline at end of file diff --git a/shared/store/model_store.js b/shared/store/model_store.js index 31b26cdf..0760614e 100644 --- a/shared/store/model_store.js +++ b/shared/store/model_store.js @@ -35,7 +35,15 @@ _.extend(ModelStore.prototype, Super.prototype, { clear: function(modelName, id) { if (modelName && id) { var key = this._getModelStoreKey(modelName, id); - return Super.prototype.clear.call(this, key); + return Super.prototype.clear.call(this, key); + } else if (modelName && !id) { + var cachedItems = this._getCachedItemsByModel(modelName), + self = this, + modelStoreKey; + _.each(cachedItems, function (item) { + modelStoreKey = self._getModelStoreKey(modelName, item.value.id); + Super.prototype.clear.call(self, modelStoreKey); + }); } else { return Super.prototype.clear.call(this, null); } @@ -61,6 +69,13 @@ _.extend(ModelStore.prototype, Super.prototype, { } }, + _getCachedItemsByModel:function(modelName) { + var prefix = this._formatKey(this._keyPrefix(modelName)); + return _.filter(this.cache, function(val, key) { + return startsWith(key, prefix); + }); + }, + _formatKey: function(key) { return Super.prototype._formatKey.call(this, "_ms:" + key); }, diff --git a/test/shared/store/collection_store.test.js b/test/shared/store/collection_store.test.js index 8f7ada57..6ed5085c 100644 --- a/test/shared/store/collection_store.test.js +++ b/test/shared/store/collection_store.test.js @@ -151,7 +151,8 @@ describe('CollectionStore', function() { }); context("there is data to be cleared", function() { - var collection, collection2, models, models2, params, params2, resultsCollection; + var collection, collection2, anotherCollection, models, models2, modelsAnother, + params, params2, resultsCollection; beforeEach(function() { models = [ @@ -171,6 +172,15 @@ describe('CollectionStore', function() { foo: 'bot', id: 12 } + ]; + modelsAnother = [ + { + foo: 'bee', + id: 111 + }, { + foo: 'hum', + id: 112 + } ]; params = { offset: 0 @@ -178,6 +188,13 @@ describe('CollectionStore', function() { params2 = {offset: 10}; collection = new BaseCollection(models, {params: params}); collection2 = new BaseCollection(models2, {params: params2}); + + function AnotherCollection() { + AnotherCollection.super_.apply(this, arguments); + } + util.inherits(AnotherCollection, BaseCollection); + + anotherCollection = new AnotherCollection(modelsAnother, {params: params }); }); it("should allow clearing out of the store by params", function() { @@ -190,9 +207,11 @@ describe('CollectionStore', function() { should.exist(resultsCollection); }); - it("should allow clearing out of the store", function() { + it("should allow clearing a collection out of the store", function() { this.store.set(collection, params); this.store.set(collection2, params2); + this.store.set(anotherCollection, params); + resultsCollection = this.store.get(collection.constructor.name, params); should.exist(resultsCollection); resultsCollection = this.store.get(collection2.constructor.name, params2); @@ -203,19 +222,21 @@ describe('CollectionStore', function() { should.not.exist(resultsCollection); resultsCollection = this.store.get(collection2.constructor.name, params2); should.not.exist(resultsCollection); + this.store.cache.should.not.be.empty; + }); + + it("should allow clearing out the store", function() { this.store.set(collection, params); this.store.set(collection2, params2); - resultsCollection = this.store.get(collection.constructor.name, params); - should.exist(resultsCollection); - resultsCollection = this.store.get(collection2.constructor.name, params2); - should.exist(resultsCollection); + this.store.set(anotherCollection, params); this.store.clear(); resultsCollection = this.store.get(collection.constructor.name, params); should.not.exist(resultsCollection); resultsCollection = this.store.get(collection2.constructor.name, params2); should.not.exist(resultsCollection); + this.store.cache.should.be.empty; }); }); }); diff --git a/test/shared/store/model_store.test.js b/test/shared/store/model_store.test.js index 3aff249b..8f21a816 100644 --- a/test/shared/store/model_store.test.js +++ b/test/shared/store/model_store.test.js @@ -14,6 +14,11 @@ function MyModel() { } util.inherits(MyModel, BaseModel); +function MyModel2() { + MyModel2.super_.apply(this, arguments); +} +util.inherits(MyModel2, BaseModel); + function App() {} addClassMapping.add(modelUtils.modelName(MyModel), MyModel); @@ -105,7 +110,7 @@ describe('ModelStore', function() { this.store.set(model); resultModel = this.store.get('my_model', defaultModelAttrs.id, true); should.exist(resultModel); - this.store.clear(defaultModelAttrs.id); + this.store.clear('my_model', defaultModelAttrs.id); resultModel = this.store.get('my_model', defaultModelAttrs.id, true); should.not.exist(resultModel); }); @@ -130,7 +135,7 @@ describe('ModelStore', function() { resultModel = this.store.find('my_model', {foo: 'bar'}); should.equal(resultModel, undefined); }); - }); + }); context("more than one model", function () { var defaultModelAttrs2, model2; @@ -156,7 +161,35 @@ describe('ModelStore', function() { should.not.exist(resultModel); resultModel = this.store.get('my_model', defaultModelAttrs2.id, true); should.not.exist(resultModel); - }); + }); + }); + context("more than one type of model", function () { + var defaultModelAttrs2, model2; + + beforeEach(function() { + defaultModelAttrs2 = { + foo: 'bar2', + id: 2 + }; + model2 = new MyModel2(defaultModelAttrs2, { app: this.app }); + }); + + it("should be able to be clear one full model from the store", function() { + + this.store.set(model); + this.store.set(model2); + + resultModel = this.store.get('my_model', defaultModelAttrs.id, true); + should.exist(resultModel); + resultModel = this.store.get('my_model2', defaultModelAttrs2.id, true); + should.exist(resultModel); + + this.store.clear('my_model'); + resultModel = this.store.get('my_model', defaultModelAttrs.id, true); + should.not.exist(resultModel); + resultModel = this.store.get('my_model2', defaultModelAttrs2.id, true); + should.exist(resultModel); + }); }); }); });