Skip to content

Commit

Permalink
RejectWith fix for static model methods. Thanks @roelmonnens.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralph Holzmann committed May 18, 2012
1 parent 22cbe28 commit ff17833
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
7 changes: 4 additions & 3 deletions control/route/route_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@ test("routes changed", function () {

window.location.hash = '!foos';
can.trigger(window, 'hashchange');

});

test("route pointers", function(){
expect(1);
var tester = can.Control({
"foo/:bar route" : "meth",
"lol/:wat route" : "meth",
meth : function(){
ok(true, "method pointer called")
}
});
new tester(document.body);
window.location.hash = '!foo/bar';
window.location.hash = '!lol/wat';
can.trigger(window, 'hashchange');

})


})();
})();
2 changes: 1 addition & 1 deletion model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ steal('can/observe', function() {
arguments[0] = model[func](arguments[0])
d.resolve.apply(d, arguments)
},function(){
d.resolveWith.apply(this,arguments)
d.rejectWith.apply(this,arguments)
})
return d;
},
Expand Down
44 changes: 44 additions & 0 deletions model/model_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,50 @@ test("findAll deferred", function(){
})
});

asyncTest("findAll deferred reject", function() {
// This test is automatically paused

function rejectDeferred(df) {
setTimeout(function() { df.reject(); }, 100);
}
function resolveDeferred(df) {
setTimeout(function() { df.resolve(); }, 100);
}

can.Model("Person", {
findAll : function(params, success, error) {
var df = can.Deferred();
if(params.resolve) {
resolveDeferred(df);
} else {
rejectDeferred(df);
}
return df;
}
},{});
var people_reject = Person.findAll({ resolve : false});
var people_resolve = Person.findAll({ resolve : true});

setTimeout(function() {
people_reject.done(function() {
ok(false, "This deferred should be rejected");
});
people_reject.fail(function() {
ok(true, "The deferred is rejected");
});

people_resolve.done(function() {
ok(true, "This deferred is resolved");
});
people_resolve.fail(function() {
ok(false, "The deferred should be resolved");
});

// continue the test
start();
}, 200);
});

test("findOne deferred", function(){
if(window.jQuery){
can.Model("Person",{
Expand Down
2 changes: 1 addition & 1 deletion test/can_dojo.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ <h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-test-area"></div>
</body>
</html>
</html>
3 changes: 2 additions & 1 deletion test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ steal('can/util/mvc.js')
var oldmodule = window.module,
library = 'jQuery';
// Set the test timeout to five minutes
QUnit.config.hidepassed = true;
QUnit.config.testTimeout = 300000;

if (window.STEALDOJO){
Expand All @@ -19,4 +20,4 @@ steal('can/util/mvc.js')
window.module = function(name, testEnvironment) {
oldmodule(library + '/' + name, testEnvironment);
}
})
})
2 changes: 1 addition & 1 deletion test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
iframe {
float: left;
width: 33.333%;
width: 32%;
height: 50%;
border-color: #eee;
border-style: dashed;
Expand Down

0 comments on commit ff17833

Please sign in to comment.