From 00f04b2df6449e43ef44eb4842169bd3dfce490b Mon Sep 17 00:00:00 2001 From: Alvin Savoy Date: Mon, 21 Oct 2013 17:05:21 +1100 Subject: [PATCH 1/5] Added a failing test for JMVC 3.2 style arguments in `Model.List.push()`. --- model/list/list_test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/model/list/list_test.js b/model/list/list_test.js index c66fba07..0a4ec72c 100644 --- a/model/list/list_test.js +++ b/model/list/list_test.js @@ -42,6 +42,16 @@ test("create", function(){ equals(this.people.get("a2")[0].id,"a2" , "get works") }) +test("push another list", function(){ + var listOfPeople = new Person.List(); + listOfPeople.push( + new Person({ name: "Barry" }), + new Person({ name: "Colin" }) + ); + equals(this.people.length, 20, 'started with 20 people'); + this.people.push(listOfPeople); + equals(this.people.length, 22, 'pushed 2 more people'); +}) test("splice", function(){ ok(this.people.get("a1").length,"something where a1 is") From 0e802f26d153cb906fb5208d7880a64434d4583c Mon Sep 17 00:00:00 2001 From: Alvin Savoy Date: Mon, 21 Oct 2013 17:09:08 +1100 Subject: [PATCH 2/5] Make the `can` namespace available to this module. --- model/list/list.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/list/list.js b/model/list/list.js index 14600930..d171e44d 100644 --- a/model/list/list.js +++ b/model/list/list.js @@ -1,4 +1,4 @@ -steal('can/model/list','jquerypp/model').then(function() { +steal('can/util', 'can/model/list','jquerypp/model', function(can) { // List.get used to take a model or list of models var getList = $.Model.List.prototype.get; $.Model.List.prototype.get = function(arg) { From cb712110749cad73f8359f7df58c981e31aa211d Mon Sep 17 00:00:00 2001 From: Alvin Savoy Date: Mon, 21 Oct 2013 17:10:29 +1100 Subject: [PATCH 3/5] Fixed the failing test by fixing the dead code block. --- model/list/list.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/model/list/list.js b/model/list/list.js index d171e44d..e8bcf936 100644 --- a/model/list/list.js +++ b/model/list/list.js @@ -18,8 +18,9 @@ steal('can/util', 'can/model/list','jquerypp/model', function(can) { var push = $.Model.List.prototype.push; $.Model.List.prototype.push = function(arg) { if(arg instanceof $.Model.List) { - arg = can.makeArray(arg); + return push.apply(this,can.makeArray(arg)); + } else { + return push.apply(this,arguments); } - return push.apply(this,arguments); }; }); From 9899fa534bce810275e222e393aef94c75526c75 Mon Sep 17 00:00:00 2001 From: Alvin Savoy Date: Mon, 21 Oct 2013 17:29:09 +1100 Subject: [PATCH 4/5] Added a failing test for JMVC 3.2 style arguments in `Model.List.get()`. --- model/list/list_test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/model/list/list_test.js b/model/list/list_test.js index 0a4ec72c..2ee82ace 100644 --- a/model/list/list_test.js +++ b/model/list/list_test.js @@ -42,6 +42,20 @@ test("create", function(){ equals(this.people.get("a2")[0].id,"a2" , "get works") }) +test("get", function(){ + var listOfPeople = new Person.List([ + new Person({ id: 1000, name: "Barry" }), + new Person({ id: 1001, name: "Colin" }) + ]); + var instanceMatch = listOfPeople.get(listOfPeople.attr('0')); + equals(instanceMatch[0].id, 1000, 'get works with model instance'); + equals(instanceMatch.length, 1, 'result is correct length'); + + var listMatch = listOfPeople.get(new Person.List([listOfPeople.attr('0')])); + equals(listMatch[0].id, 1000, 'get works with model list instance'); + equals(listMatch.length, 1, 'result is correct length'); +}) + test("push another list", function(){ var listOfPeople = new Person.List(); listOfPeople.push( From 2499a0364fc25067b379dc9ffd9f798504cf857d Mon Sep 17 00:00:00 2001 From: Alvin Savoy Date: Mon, 21 Oct 2013 17:29:26 +1100 Subject: [PATCH 5/5] Fix failing test. --- model/list/list.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/model/list/list.js b/model/list/list.js index e8bcf936..b278ab27 100644 --- a/model/list/list.js +++ b/model/list/list.js @@ -9,10 +9,13 @@ steal('can/util', 'can/model/list','jquerypp/model', function(can) { ids.push(this.attr('id')); }); arg = ids; + return getList.apply(this,arg); } else if(arg.attr && arg.constructor && (id = arg.attr(arg.constructor.id))) { arg = id; + return getList.apply(this,[arg]); + } else { + return getList.apply(this,arguments); } - return getList.apply(this,arguments); }; // restore the ability to push a list!arg var push = $.Model.List.prototype.push;