Commits

Kenneth Jørgensen committed a74dbf7

Added test to prevent loader from adding objects to the load queue when it has already completed

  • Participants
  • Parent commits c3493f2

Comments (0)

Files changed (4)

coffeelint.coffee

 	"no_throwing_strings":
 		"level": "error"
 	"cyclomatic_complexity":
-		"value": 19
+		"value": 20
 		"level": "error"
 	"no_backticks":
 		"level": "error"
-/*! Discrete 0.1.0-dev.6 - MIT license */
+/*! Discrete 0.1.0-dev.7 - MIT license */
 (function() {
   var Async, Calamity, Collection, Discrete, HasManyRelation, HasOneRelation, Loader, Map, Model, ModelRepo, Persistor, Relation, RepoPersistor, Set, SortedMap, calamity, exports, object_toString, root, _, _ref, _ref1,
     __hasProp = {}.hasOwnProperty,
   }
 
   Discrete = {
-    version: "0.1.0-dev.6"
+    version: "0.1.0-dev.7"
   };
 
   if (typeof exports !== "undefined") {
           throw new Error("Non-model object supplied for model");
         }
         this._models[name] = model;
-        if (this._queue) {
+        if (this._queue && !this.completed) {
           this._queue.push({
             name: name,
             model: model

spec/LoaderSpec.coffee

 			expect(loader.get "m1").toBe m1
 			expect(loader.get "m2").toBe m2
 
+	it "should not start fetching more models when loading is completed", ->
+		loader.load done
+		loader.add m1: "id:111"
+		waitsFor (-> done.called), "Done never called", 100
+		defer = sinon.spy()
+		runs ->
+			expect(done.callCount).toBe 1
+			loader.add m2: "id:222"
+			expect(done.callCount).toBe 1
+			_.defer defer
+		waitsFor (-> defer.called), "Defer never called", 100
+		runs ->
+			expect(done.callCount).toBe 1
+
 	it "should save known models", ->
 		sinon.spy m1, "save"
 		sinon.spy m2, "save"

src/Loader.coffee

 			# Add to model container.
 			@_models[name] = model
 			# Push to queue.
-			if @_queue
+			if @_queue and not @completed
 				@_queue.push
 					name: name
 					model: model