Permalink
Browse files

fixes a bug with toJSON method in an attr_list

  • Loading branch information...
1 parent 99d8fd0 commit b717a2e8c17aff4c5c147e9383877fea844e2fdc @semmypurewal committed Oct 28, 2012
Showing with 25 additions and 3 deletions.
  1. +20 −0 spec/core/attr_list.js
  2. +5 −3 src/core/attr_list.js
View
20 spec/core/attr_list.js
@@ -240,6 +240,26 @@ describe("AttrList", function () {
});
});
+ describe("toJSON method", function () {
+ it("should return a JSON representation of the elements in the list", function () {
+ var testObj = ["john", "semmy", "mark", "jim"];
+
+ obj.friends().add("john");
+ obj.friends().add("semmy");
+ obj.friends().add("mark");
+ obj.friends().add("jim");
+ expect(obj.friends()).toBeDefined();
+
+ expect(function () {
+ obj.friends().toJSON();
+ }).not.toThrow();
+
+ expect(obj.friends().toJSON()).toEqual(testObj);
+
+
+ });
+ });
+
describe("pop method", function () {
it("should return the object which was popped", function () {
var lastObj = "mark",
View
8 src/core/attr_list.js
@@ -83,9 +83,11 @@ window.jermaine.util.namespace("window.jermaine", function (ns) {
i, j;
//check to make sure the current list is not in JSONreps
- for (i = 0;i < JSONreps.length; ++i) {
- if (JSONreps[i].object === this) {
- result = JSONreps[i].JSONrep;
+ if (JSONreps !== undefined) {
+ for (i = 0;i < JSONreps.length; ++i) {
+ if (JSONreps[i].object === this) {
+ result = JSONreps[i].JSONrep;
+ }
}
}

0 comments on commit b717a2e

Please sign in to comment.