aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVojta Jina2012-02-23 22:50:02 -0800
committerVojta Jina2012-02-23 22:50:02 -0800
commit3171f215910255938c179d8243480fbaeebc77cf (patch)
tree06f1ecf3ba20a32a6ab67e429a7083dfc037e5f0
parentd6e3e1baabc3acc930e4fda387b62cbd03e64577 (diff)
downloadangular.js-3171f215910255938c179d8243480fbaeebc77cf.tar.bz2
fix($httpBackend): Set current url, if not defined or empty string
Reason to fix this was the fact that with undefined url, it ended up with weird exception (Cannot call method 'replace' of undefined), which was more confusing than helpful. jQuery.ajax() does request to current url, if url is not specified, so I decided for this solution.
-rw-r--r--src/service/httpBackend.js1
-rw-r--r--test/service/httpBackendSpec.js11
2 files changed, 12 insertions, 0 deletions
diff --git a/src/service/httpBackend.js b/src/service/httpBackend.js
index 291d24bb..201d1a87 100644
--- a/src/service/httpBackend.js
+++ b/src/service/httpBackend.js
@@ -34,6 +34,7 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, body, locati
// TODO(vojta): fix the signature
return function(method, url, post, callback, headers, timeout) {
$browser.$$incOutstandingRequestCount();
+ url = url || $browser.url();
if (lowercase(method) == 'jsonp') {
var callbackId = '_' + (callbacks.counter++).toString(36);
diff --git a/test/service/httpBackendSpec.js b/test/service/httpBackendSpec.js
index 55d1a48a..820099e8 100644
--- a/test/service/httpBackendSpec.js
+++ b/test/service/httpBackendSpec.js
@@ -168,6 +168,17 @@ describe('$httpBackend', function() {
});
+ it('should set url to current location if not specified or empty string', function() {
+ $backend('JSONP', undefined, null, callback);
+ expect($browser.$$scripts[0].url).toBe($browser.url());
+ $browser.$$scripts.shift();
+
+ $backend('JSONP', '', null, callback);
+ expect($browser.$$scripts[0].url).toBe($browser.url());
+ $browser.$$scripts.shift();
+ });
+
+
// TODO(vojta): test whether it fires "async-start"
// TODO(vojta): test whether it fires "async-end" on both success and error
});