Permalink
Browse files

throws an error when a constructor is called with more arguments than…

… specified by isBuiltWith, fixes issue #19
  • Loading branch information...
1 parent 24dd147 commit 04869ee90bd6f9f3b82054e9652dd3bbe524d8a0 @semmypurewal committed Oct 27, 2012
Showing with 30 additions and 3 deletions.
  1. +1 −1 build/jermaine-min.js
  2. +5 −1 build/jermaine.js
  3. +19 −0 spec/core/model.js
  4. +5 −1 src/core/model.js
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -939,7 +939,11 @@ window.jermaine.util.namespace("window.jermaine", function (ns) {
}
err += " to be specified";
throw new Error(err);
- } else {
+ } if (arguments.length > requiredConstructorArgs.length + optionalConstructorArgs.length) {
+ throw new Error("Too many arguments to constructor. Expected " + requiredConstructorArgs.length + " required arguments and " +
+ optionalConstructorArgs.length + " optional arguments");
+ }
+ else {
for (i = 0; i < arguments.length; ++i) {
attribute = i < requiredConstructorArgs.length?
requiredConstructorArgs[i]:
View
@@ -1317,6 +1317,23 @@ describe("Model", function () {
}).not.toThrow(new Error("Constructor requires firstName, lastName to be specified"));
});
+ it("should throw an error if the constructor is called with more arguments than isBuiltWith specifies", function () {
+
+ var Person,
+ p;
+ Person = new Model(function () {
+ this.hasA("name").which.isA("string");
+ this.hasMany("friends").eachOfWhich.validateWith(function (friend) {
+ return friend instanceof Person;
+ });
+ });
+
+ expect(function () {
+ p = new Person("Semmy");
+ }).toThrow("Too many arguments to constructor. Expected 0 required arguments and 0 optional arguments");
+
+ });
+
it("should set the attributes associated with the attributes to the appropriate values", function () {
var Card,
Thing,
@@ -1533,6 +1550,8 @@ describe("Model", function () {
}).not.toThrow();
});
+
+
it("should work with this example", function () {
var Card,
Deck,
View
@@ -291,7 +291,11 @@ window.jermaine.util.namespace("window.jermaine", function (ns) {
}
err += " to be specified";
throw new Error(err);
- } else {
+ } if (arguments.length > requiredConstructorArgs.length + optionalConstructorArgs.length) {
+ throw new Error("Too many arguments to constructor. Expected " + requiredConstructorArgs.length + " required arguments and " +
+ optionalConstructorArgs.length + " optional arguments");
+ }
+ else {
for (i = 0; i < arguments.length; ++i) {
attribute = i < requiredConstructorArgs.length?
requiredConstructorArgs[i]:

0 comments on commit 04869ee

Please sign in to comment.