Skip to content

Commit ff17833

Browse files
author
Ralph Holzmann
committed
RejectWith fix for static model methods. Thanks @roelmonnens.
1 parent 22cbe28 commit ff17833

File tree

6 files changed

+53
-7
lines changed

6 files changed

+53
-7
lines changed

control/route/route_test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,22 @@ test("routes changed", function () {
3030

3131
window.location.hash = '!foos';
3232
can.trigger(window, 'hashchange');
33+
3334
});
3435

3536
test("route pointers", function(){
3637
expect(1);
3738
var tester = can.Control({
38-
"foo/:bar route" : "meth",
39+
"lol/:wat route" : "meth",
3940
meth : function(){
4041
ok(true, "method pointer called")
4142
}
4243
});
4344
new tester(document.body);
44-
window.location.hash = '!foo/bar';
45+
window.location.hash = '!lol/wat';
4546
can.trigger(window, 'hashchange');
4647

4748
})
4849

4950

50-
})();
51+
})();

model/model.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ steal('can/observe', function() {
1515
arguments[0] = model[func](arguments[0])
1616
d.resolve.apply(d, arguments)
1717
},function(){
18-
d.resolveWith.apply(this,arguments)
18+
d.rejectWith.apply(this,arguments)
1919
})
2020
return d;
2121
},

model/model_test.js

+44
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,50 @@ test("findAll deferred", function(){
4747
})
4848
});
4949

50+
asyncTest("findAll deferred reject", function() {
51+
// This test is automatically paused
52+
53+
function rejectDeferred(df) {
54+
setTimeout(function() { df.reject(); }, 100);
55+
}
56+
function resolveDeferred(df) {
57+
setTimeout(function() { df.resolve(); }, 100);
58+
}
59+
60+
can.Model("Person", {
61+
findAll : function(params, success, error) {
62+
var df = can.Deferred();
63+
if(params.resolve) {
64+
resolveDeferred(df);
65+
} else {
66+
rejectDeferred(df);
67+
}
68+
return df;
69+
}
70+
},{});
71+
var people_reject = Person.findAll({ resolve : false});
72+
var people_resolve = Person.findAll({ resolve : true});
73+
74+
setTimeout(function() {
75+
people_reject.done(function() {
76+
ok(false, "This deferred should be rejected");
77+
});
78+
people_reject.fail(function() {
79+
ok(true, "The deferred is rejected");
80+
});
81+
82+
people_resolve.done(function() {
83+
ok(true, "This deferred is resolved");
84+
});
85+
people_resolve.fail(function() {
86+
ok(false, "The deferred should be resolved");
87+
});
88+
89+
// continue the test
90+
start();
91+
}, 200);
92+
});
93+
5094
test("findOne deferred", function(){
5195
if(window.jQuery){
5296
can.Model("Person",{

test/can_dojo.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ <h2 id="qunit-userAgent"></h2>
1818
<ol id="qunit-tests"></ol>
1919
<div id="qunit-test-area"></div>
2020
</body>
21-
</html>
21+
</html>

test/setup.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ steal('can/util/mvc.js')
55
var oldmodule = window.module,
66
library = 'jQuery';
77
// Set the test timeout to five minutes
8+
QUnit.config.hidepassed = true;
89
QUnit.config.testTimeout = 300000;
910

1011
if (window.STEALDOJO){
@@ -19,4 +20,4 @@ steal('can/util/mvc.js')
1920
window.module = function(name, testEnvironment) {
2021
oldmodule(library + '/' + name, testEnvironment);
2122
}
22-
})
23+
})

test/test.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
iframe {
1515
float: left;
16-
width: 33.333%;
16+
width: 32%;
1717
height: 50%;
1818
border-color: #eee;
1919
border-style: dashed;

0 commit comments

Comments
 (0)