[#35,all][m]: crude error catching for backends based on timeouts (best we can do with JSONP) - fixes #35.

* Show errors in UI
* required some extensive refactoring to use done/fail on promise rather than then
This commit is contained in:
Rufus Pollock
2012-02-10 03:14:52 +00:00
parent d17fa4a169
commit 21173b6acf
4 changed files with 78 additions and 24 deletions

View File

@@ -154,26 +154,32 @@
var stub = sinon.stub($, 'ajax', function(options) {
if (options.url.indexOf('schema.json') != -1) {
return {
then: function(callback) {
done: function(callback) {
callback(webstoreSchema);
return this;
},
fail: function() {
return this;
}
}
} else {
return {
then: function(callback) {
done: function(callback) {
callback(webstoreData);
},
fail: function() {
}
}
}
});
dataset.fetch().then(function(dataset) {
dataset.fetch().done(function(dataset) {
deepEqual(['__id__', 'date', 'geometry', 'amount'], dataset.get('headers'));
equal(3, dataset.docCount)
dataset.query().then(function(docList) {
equal(3, docList.length)
equal("2009-01-01", docList.models[0].get('date'));
});
// dataset.query().done(function(docList) {
// equal(3, docList.length)
// equal("2009-01-01", docList.models[0].get('date'));
// });
});
$.ajax.restore();
});
@@ -255,21 +261,25 @@
var partialUrl = 'jsonpdataproxy.appspot.com';
if (options.url.indexOf(partialUrl) != -1) {
return {
then: function(callback) {
done: function(callback) {
callback(dataProxyData);
return this;
},
fail: function() {
return this;
}
}
}
});
dataset.fetch().then(function(dataset) {
dataset.fetch().done(function(dataset) {
deepEqual(['__id__', 'date', 'price'], dataset.get('headers'));
equal(null, dataset.docCount)
dataset.query().then(function(docList) {
dataset.query().done(function(docList) {
equal(10, docList.length)
equal("1950-01", docList.models[0].get('date'));
// needed only if not stubbing
start();
// needed only if not stubbing
start();
});
});
$.ajax.restore();