Commits

Kenneth Jørgensen  committed b2f5333

Added check to Loader about non-model objects

  • Participants
  • Parent commits ce9c468

Comments (0)

Files changed (4)

File coffeelint.coffee

 	"no_throwing_strings":
 		"level": "error"
 	"cyclomatic_complexity":
-		"value": 16
+		"value": 18
 		"level": "error"
 	"no_backticks":
 		"level": "error"
       } else if (!(name instanceof Model) && (model == null)) {
         model = name;
       }
+      if (_.isObject(model) && !(model instanceof Model)) {
+        throw new Error("Non-model object supplied for model");
+      }
       if (name == null) {
         throw new Error("Name is not defined");
       }

File spec/LoaderSpec.coffee

 			expect(models["id:111"]).toBe m1
 			expect(models["id:222"]).toBe m2
 			expect(models["id:333"]).toBeUndefined()
+
+	it "should complain if adding non-models", ->
+		test = -> loader.add "index", {}
+		expect(test).toThrow "Non-model object supplied for model"

File src/Loader.coffee

 		# Single ID.
 		else if not (name instanceof Model) and not model?
 			model = name
+		# Non-model objects.
+		if _.isObject(model) and not (model instanceof Model)
+			throw new Error "Non-model object supplied for model"
 
 		throw new Error "Name is not defined" unless name?
 		throw new Error "Name is not defined" unless model?