Skip to content
Browse files

- add serialize

- add serializeArray
- more tests
- new valentine dependency
- reinstall node modules
- bump package
  • Loading branch information...
1 parent da5e2a8 commit bf4b05044225d6cddc82aa2785651509528b3ece @ded committed May 9, 2011
Showing with 277 additions and 79 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 .gitmodules
  3. +5 −1 Makefile
  4. +1 −1 Makefile.js
  5. +11 −11 README.md
  6. +1 −1 build/connect
  7. +1 −1 build/mime
  8. +1 −1 build/sink
  9. +1 −1 build/smoosh
  10. +1 −0 build/valentine
  11. +6 −4 make/tests.js
  12. +6 −3 package.json
  13. +81 −23 reqwest.js
  14. +6 −1 reqwest.min.js
  15. +5 −2 src/ender.js
  16. +81 −23 src/reqwest.js
  17. +1 −1 tests/fixtures/fixtures_jsonp.js
  18. +1 −1 tests/fixtures/fixtures_jsonp3.js
  19. +23 −0 tests/tests.html
  20. +41 −4 tests/tests.js
View
1 .gitignore
@@ -0,0 +1 @@
+node_modules
View
3 .gitmodules
@@ -13,3 +13,6 @@
[submodule "build/connect"]
path = build/connect
url = git://github.com/senchalabs/connect.git
+[submodule "build/valentine"]
+ path = build/valentine
+ url = git://github.com/ded/valentine.git
View
6 Makefile
@@ -1,4 +1,8 @@
boosh:
node Makefile.js
test:
- node make/tests.js
+ node make/tests.js
+install:
+ npm install connect
+ npm install mime
+ npm install dispatch
View
2 Makefile.js
@@ -15,7 +15,7 @@ require('smoosh').config({
"evil": true,
"regexp": false,
"undef": false,
- "sub": false,
+ "sub": true,
"white": true,
"indent": 2,
"whitespace": true,
View
22 README.md
@@ -5,17 +5,18 @@ All over again.
The happs
---------
- git clone git://github.com/ded/Reqwest.git
- cd !$
- git submodule update --init
- make
+ $ git clone git://github.com/ded/reqwest.git
+ $ cd reqwest
+ $ git submodule update --init
+ $ make
+ $ make install
-The codes
+API
---------
``` js
reqwest('path/to/html', function (resp) {
- Q('#content').html(resp);
+ qwery('#content').html(resp);
});
```
@@ -25,7 +26,7 @@ reqwest({
type: 'json',
method: 'post',
success: function (resp) {
- Q('#content').html(resp.content);
+ qwery('#content').html(resp.content);
},
failure: function (err) { }
});
@@ -36,7 +37,7 @@ reqwest({
url: 'path/to/data.jsonp?callback=?',
type: 'jsonp',
success: function (resp) {
- Q('#content').html(resp.content);
+ qwery('#content').html(resp.content);
}
});
```
@@ -47,16 +48,15 @@ reqwest({
type: 'jsonp',
jsonpCallback: 'foo',
success: function (resp) {
- Q('#content').html(resp.content);
+ qwery('#content').html(resp.content);
}
});
```
The Tests
-----
make test
- open http://localhost:3000
-
+ open http://localhost:1234
Browser support
---------------
2 build/connect
@@ -1 +1 @@
-Subproject commit 1aa4957eae55e897e882d49de163bbb124410e3d
+Subproject commit 76816734b80f4b5d765d53a1c1f535e00757b863
2 build/mime
@@ -1 +1 @@
-Subproject commit da62624813ef2790834a683fa487a74d2f5ea7b4
+Subproject commit 8f2c606244f4ae6784cc4a6bdd7b29578cc5f701
2 build/sink
@@ -1 +1 @@
-Subproject commit a5286d84c1398dddc154500c6c24f7b4bc0610b3
+Subproject commit 5b82553c81a3561b6525e72468caeeb3557687d4
2 build/smoosh
@@ -1 +1 @@
-Subproject commit 1591d9d20edf8aca590e3d4b24ae5eaee29b5076
+Subproject commit a96872eb6ef4332a23b5c742e6b054fd9c804ac0
1 build/valentine
@@ -0,0 +1 @@
+Subproject commit 3f0f427951ca405d243f82b376e7644ca5731c0c
View
10 make/tests.js
@@ -1,17 +1,19 @@
var http = require('http'),
exec = require('child_process').exec,
fs = require('fs'),
- Connect = require('../build/connect/'),
- dispatch = require('../build/dispatch/'),
- mime = require('../build/mime/');
+ Connect = require('connect'),
+ dispatch = require('dispatch'),
+ mime = require('mime');
+
+
var routes = {
'/': function (req, res) {
res.write(fs.readFileSync('./tests/tests.html', 'utf8'));
res.end();
},
- '(([a-zA-Z0-9_\\-\\/]+)\\.(css|js|json|html)$)': function (req, res, m, whole, file, ext) {
+ '(([a-zA-Z0-9_\\-\\/]+)\\.(css|js|json|html)$)': function (req, res, m, file, ext) {
res.writeHead(200, {'Content-Type': mime.lookup(ext)});
var asset = fs.readFileSync('./' + file + '.' + ext);
res.write(asset);
View
9 package.json
@@ -1,13 +1,16 @@
{
"name": "reqwest",
"description": "A robust lightweight wrapper for asynchronous http requests",
- "version": "0.0.9",
+ "version": "0.1.0",
"homepage": "https://github.com/ded/reqwest",
- "authors": ["Dustin Diaz", "Jacob Thornton"],
+ "author": "Dustin Diaz <@ded>",
"repository": {
"type": "git",
"url": "https://github.com/ded/reqwest.git"
},
"main": "./reqwest.js",
- "ender": "./src/ender.js"
+ "ender": "./src/ender.js",
+ "dependencies": {
+ "valentine": ">= 1.1.0"
+ }
}
View
104 reqwest.js
@@ -4,24 +4,27 @@
* https://github.com/ded/reqwest
* license MIT
*/
-!function (context) {
+/*!
+ * Reqwest! A x-browser general purpose XHR connection manager
+ * copyright Dustin Diaz 2011
+ * https://github.com/ded/reqwest
+ * license MIT
+ */
+!function (window) {
var twoHundo = /^20\d$/,
+ doc = document,
+ byTag = 'getElementsByTagName',
+ topScript = doc[byTag]('script')[0],
+ head = topScript.parentNode,
xhr = ('XMLHttpRequest' in window) ?
function () {
return new XMLHttpRequest();
} :
function () {
return new ActiveXObject('Microsoft.XMLHTTP');
};
-
- var uniqid = (function () {
- var id = 0;
- return {
- get: function () {
- return id++;
- }
- };
- }());
+
+ var uniqid = 0;
function readyState(o, success, error) {
return function () {
@@ -45,47 +48,47 @@
}
}
}
-
+
function getCallbackName(o) {
var callbackVar = o.jsonpCallback || "callback";
if (o.url.substr(-(callbackVar.length + 2)) == (callbackVar + "=?")) {
// Generate a guaranteed unique callback name
- var callbackName = "Request" + uniqid.get();
-
+ var callbackName = "reqwest_" + uniqid++;
+
// Replace the ? in the URL with the generated name
o.url = o.url.substr(0, o.url.length - 1) + callbackName;
return callbackName;
} else {
// Find the supplied callback name
- var regex = new RegExp(callbackVar + "=([A-Za-z0-9_]+)");
+ var regex = new RegExp(callbackVar + "=([\\w]+)");
return o.url.match(regex)[1];
}
}
function getRequest(o, fn, err) {
if (o.type == 'jsonp') {
- var script = document.createElement('script');
- var head = document.getElementsByTagName('head')[0];
-
+ var script = doc.createElement('script');
+
// Add the global callback
var callbackName = getCallbackName(o);
window[callbackName] = function (data) {
// Call the success callback
o.success && o.success(data);
};
-
+
// Setup our script element
script.type = "text/javascript";
script.src = o.url;
+ script.async = true;
script.onload = function () {
// Script has been loaded, and thus the user callback has
// been called, so lets clean up now.
head.removeChild(script);
delete window[callbackName];
};
-
+
// Add the script to the DOM head
- head.appendChild(script);
+ head.insertBefore(script, topScript);
} else {
var http = xhr();
http.open(o.method || 'GET', typeof o == 'string' ? o : o.url, true);
@@ -183,11 +186,66 @@
return new Reqwest(o, fn);
}
- var old = context.reqwest;
+ function enc(v) {
+ return encodeURIComponent(v);
+ }
+
+ function serial(el) {
+ var n = el.name;
+ // don't serialize elements that are disabled or without a name
+ if (el.disabled || !n) {
+ return '';
+ }
+ n = enc(n);
+ switch (el.tagName.toLowerCase()) {
+ case 'input':
+ switch (el.type) {
+ // silly wabbit
+ case 'reset':
+ case 'button':
+ case 'image':
+ case 'file':
+ return '';
+ case 'checkbox':
+ case 'radio':
+ return el.checked ? n + '=' + (el.value ? enc(el.value) : true) + '&' : '';
+ default: // text hidden password submit
+ return n + '=' + (el.value ? enc(el.value) : true) + '&';
+ }
+ break;
+ case 'textarea':
+ return n + '=' + enc(el.value) + '&';
+ case 'select':
+ // @todo refactor beyond basic single selected value case
+ return n + '=' + enc(el.options[el.selectedIndex].value) + '&';
+ }
+ return '';
+ }
+
+ reqwest.serialize = function (form) {
+ var inputs = form[byTag]('input'),
+ selects = form[byTag]('select'),
+ texts = form[byTag]('textarea');
+ return (v(inputs).chain().toArray().map(serial).value().join('') +
+ v(selects).chain().toArray().map(serial).value().join('') +
+ v(texts).chain().toArray().map(serial).value().join('')).replace(/&$/, '');
+ };
+
+ reqwest.serializeArray = function (f) {
+ for (var pairs = this.serialize(f).split('&'), i = 0, l = pairs.length, r = [], o; i < l; i++) {
+ pairs[i] && (o = pairs[i].split('=')) && r.push({name: o[0], value: o[1]});
+ }
+ return r;
+ };
+
+ var old = window.reqwest;
reqwest.noConflict = function () {
- context.reqwest = old;
+ window.reqwest = old;
return this;
};
- context.reqwest = reqwest;
+
+ // defined as extern for Closure Compilation
+ // do not change to (dot) '.' syntax
+ window['reqwest'] = reqwest;
}(this);
View
7 reqwest.min.js
@@ -3,5 +3,10 @@
* copyright Dustin Diaz 2011
* https://github.com/ded/reqwest
* license MIT
+ *//*!
+ * Reqwest! A x-browser general purpose XHR connection manager
+ * copyright Dustin Diaz 2011
+ * https://github.com/ded/reqwest
+ * license MIT
*/
-!function(context){function reqwest(a,b){return new Reqwest(a,b)}function init(o,fn){function error(a){o.error&&o.error(a),complete(a)}function success(resp){o.timeout&&clearTimeout(self.timeout)&&(self.timeout=null);var r=resp.responseText;switch(type){case"json":resp=eval("("+r+")");break;case"js":resp=eval(r);break;case"html":resp=r}fn(resp),o.success&&o.success(resp),complete(resp)}function complete(a){o.complete&&o.complete(a)}this.url=typeof o=="string"?o:o.url,this.timeout=null;var type=o.type||setType(this.url),self=this;fn=fn||function(){},o.timeout&&(this.timeout=setTimeout(function(){self.abort(),error()},o.timeout)),this.request=getRequest(o,success,error)}function setType(a){if(/\.json$/.test(a))return"json";if(/\.jsonp$/.test(a))return"jsonp";if(/\.js$/.test(a))return"js";if(/\.html?$/.test(a))return"html";if(/\.xml$/.test(a))return"xml";return"js"}function Reqwest(a,b){this.o=a,this.fn=b,init.apply(this,arguments)}function getRequest(a,b,c){if(a.type!="jsonp"){var g=xhr();g.open(a.method||"GET",typeof a=="string"?a:a.url,!0),setHeaders(g,a),g.onreadystatechange=readyState(g,b,c),a.before&&a.before(g),g.send(a.data||null);return g}var d=document.createElement("script"),e=document.getElementsByTagName("head")[0],f=getCallbackName(a);window[f]=function(b){a.success&&a.success(b)},d.type="text/javascript",d.src=a.url,d.onload=function(){e.removeChild(d),delete window[f]},e.appendChild(d)}function getCallbackName(a){var b=a.jsonpCallback||"callback";if(a.url.substr(-(b.length+2))==b+"=?"){var c="Request"+uniqid.get();a.url=a.url.substr(0,a.url.length-1)+c;return c}var d=new RegExp(b+"=([A-Za-z0-9_]+)");return a.url.match(d)[1]}function setHeaders(a,b){var c=b.headers||{};c.Accept="text/javascript, text/html, application/xml, text/xml, */*";if(b.data){c["Content-type"]="application/x-www-form-urlencoded";for(var d in c)c.hasOwnProperty(d)&&a.setRequestHeader(d,c[d],!1)}}function readyState(a,b,c){return function(){a&&a.readyState==4&&(twoHundo.test(a.status)?b(a):c(a))}}var twoHundo=/^20\d$/,xhr="XMLHttpRequest"in window?function(){return new XMLHttpRequest}:function(){return new ActiveXObject("Microsoft.XMLHTTP")},uniqid=function(){var a=0;return{get:function(){return a++}}}();Reqwest.prototype={abort:function(){this.request.abort()},retry:function(){init.call(this,this.o,this.fn)}};var old=context.reqwest;reqwest.noConflict=function(){context.reqwest=old;return this},context.reqwest=reqwest}(this)
+!function(window){function serial(a){var b=a.name;if(a.disabled||!b)return"";b=enc(b);switch(a.tagName.toLowerCase()){case"input":switch(a.type){case"reset":case"button":case"image":case"file":return"";case"checkbox":case"radio":return a.checked?b+"="+(a.value?enc(a.value):!0)+"&":"";default:return b+"="+(a.value?enc(a.value):!0)+"&"}break;case"textarea":return b+"="+enc(a.value)+"&";case"select":return b+"="+enc(a.options[a.selectedIndex].value)+"&"}return""}function enc(a){return encodeURIComponent(a)}function reqwest(a,b){return new Reqwest(a,b)}function init(o,fn){function error(a){o.error&&o.error(a),complete(a)}function success(resp){o.timeout&&clearTimeout(self.timeout)&&(self.timeout=null);var r=resp.responseText;switch(type){case"json":resp=eval("("+r+")");break;case"js":resp=eval(r);break;case"html":resp=r}fn(resp),o.success&&o.success(resp),complete(resp)}function complete(a){o.complete&&o.complete(a)}this.url=typeof o=="string"?o:o.url,this.timeout=null;var type=o.type||setType(this.url),self=this;fn=fn||function(){},o.timeout&&(this.timeout=setTimeout(function(){self.abort(),error()},o.timeout)),this.request=getRequest(o,success,error)}function setType(a){if(/\.json$/.test(a))return"json";if(/\.jsonp$/.test(a))return"jsonp";if(/\.js$/.test(a))return"js";if(/\.html?$/.test(a))return"html";if(/\.xml$/.test(a))return"xml";return"js"}function Reqwest(a,b){this.o=a,this.fn=b,init.apply(this,arguments)}function getRequest(a,b,c){if(a.type!="jsonp"){var f=xhr();f.open(a.method||"GET",typeof a=="string"?a:a.url,!0),setHeaders(f,a),f.onreadystatechange=readyState(f,b,c),a.before&&a.before(f),f.send(a.data||null);return f}var d=doc.createElement("script"),e=getCallbackName(a);window[e]=function(b){a.success&&a.success(b)},d.type="text/javascript",d.src=a.url,d.async=!0,d.onload=function(){head.removeChild(d),delete window[e]},head.insertBefore(d,topScript)}function getCallbackName(a){var b=a.jsonpCallback||"callback";if(a.url.substr(-(b.length+2))==b+"=?"){var c="reqwest_"+uniqid++;a.url=a.url.substr(0,a.url.length-1)+c;return c}var d=new RegExp(b+"=([\\w]+)");return a.url.match(d)[1]}function setHeaders(a,b){var c=b.headers||{};c.Accept="text/javascript, text/html, application/xml, text/xml, */*";if(b.data){c["Content-type"]="application/x-www-form-urlencoded";for(var d in c)c.hasOwnProperty(d)&&a.setRequestHeader(d,c[d],!1)}}function readyState(a,b,c){return function(){a&&a.readyState==4&&(twoHundo.test(a.status)?b(a):c(a))}}var twoHundo=/^20\d$/,doc=document,byTag="getElementsByTagName",topScript=doc[byTag]("script")[0],head=topScript.parentNode,xhr="XMLHttpRequest"in window?function(){return new XMLHttpRequest}:function(){return new ActiveXObject("Microsoft.XMLHTTP")},uniqid=0;Reqwest.prototype={abort:function(){this.request.abort()},retry:function(){init.call(this,this.o,this.fn)}},reqwest.serialize=function(a){var b=a[byTag]("input"),c=a[byTag]("select"),d=a[byTag]("textarea");return(v(b).chain().toArray().map(serial).value().join("")+v(c).chain().toArray().map(serial).value().join("")+v(d).chain().toArray().map(serial).value().join("")).replace(/&$/,"")},reqwest.serializeArray=function(a){for(var b=this.serialize(a).split("&"),c=0,d=b.length,e=[],f;c<d;c++)b[c]&&(f=b[c].split("="))&&e.push({name:f[0],value:f[1]});return e};var old=window.reqwest;reqwest.noConflict=function(){window.reqwest=old;return this},window.reqwest=reqwest}(this)
View
7 src/ender.js
@@ -1,3 +1,6 @@
-$.ender({
- ajax: reqwest.noConflict()
+ender.ender({
+ ajax: reqwest,
+ serialize: function () {
+ return reqwest.serialize(this[0]);
+ }
});
View
104 src/reqwest.js
@@ -1,21 +1,24 @@
-!function (context) {
+/*!
+ * Reqwest! A x-browser general purpose XHR connection manager
+ * copyright Dustin Diaz 2011
+ * https://github.com/ded/reqwest
+ * license MIT
+ */
+!function (window) {
var twoHundo = /^20\d$/,
+ doc = document,
+ byTag = 'getElementsByTagName',
+ topScript = doc[byTag]('script')[0],
+ head = topScript.parentNode,
xhr = ('XMLHttpRequest' in window) ?
function () {
return new XMLHttpRequest();
} :
function () {
return new ActiveXObject('Microsoft.XMLHTTP');
};
-
- var uniqid = (function () {
- var id = 0;
- return {
- get: function () {
- return id++;
- }
- };
- }());
+
+ var uniqid = 0;
function readyState(o, success, error) {
return function () {
@@ -39,47 +42,47 @@
}
}
}
-
+
function getCallbackName(o) {
var callbackVar = o.jsonpCallback || "callback";
if (o.url.substr(-(callbackVar.length + 2)) == (callbackVar + "=?")) {
// Generate a guaranteed unique callback name
- var callbackName = "Request" + uniqid.get();
-
+ var callbackName = "reqwest_" + uniqid++;
+
// Replace the ? in the URL with the generated name
o.url = o.url.substr(0, o.url.length - 1) + callbackName;
return callbackName;
} else {
// Find the supplied callback name
- var regex = new RegExp(callbackVar + "=([A-Za-z0-9_]+)");
+ var regex = new RegExp(callbackVar + "=([\\w]+)");
return o.url.match(regex)[1];
}
}
function getRequest(o, fn, err) {
if (o.type == 'jsonp') {
- var script = document.createElement('script');
- var head = document.getElementsByTagName('head')[0];
-
+ var script = doc.createElement('script');
+
// Add the global callback
var callbackName = getCallbackName(o);
window[callbackName] = function (data) {
// Call the success callback
o.success && o.success(data);
};
-
+
// Setup our script element
script.type = "text/javascript";
script.src = o.url;
+ script.async = true;
script.onload = function () {
// Script has been loaded, and thus the user callback has
// been called, so lets clean up now.
head.removeChild(script);
delete window[callbackName];
};
-
+
// Add the script to the DOM head
- head.appendChild(script);
+ head.insertBefore(script, topScript);
} else {
var http = xhr();
http.open(o.method || 'GET', typeof o == 'string' ? o : o.url, true);
@@ -177,11 +180,66 @@
return new Reqwest(o, fn);
}
- var old = context.reqwest;
+ function enc(v) {
+ return encodeURIComponent(v);
+ }
+
+ function serial(el) {
+ var n = el.name;
+ // don't serialize elements that are disabled or without a name
+ if (el.disabled || !n) {
+ return '';
+ }
+ n = enc(n);
+ switch (el.tagName.toLowerCase()) {
+ case 'input':
+ switch (el.type) {
+ // silly wabbit
+ case 'reset':
+ case 'button':
+ case 'image':
+ case 'file':
+ return '';
+ case 'checkbox':
+ case 'radio':
+ return el.checked ? n + '=' + (el.value ? enc(el.value) : true) + '&' : '';
+ default: // text hidden password submit
+ return n + '=' + (el.value ? enc(el.value) : true) + '&';
+ }
+ break;
+ case 'textarea':
+ return n + '=' + enc(el.value) + '&';
+ case 'select':
+ // @todo refactor beyond basic single selected value case
+ return n + '=' + enc(el.options[el.selectedIndex].value) + '&';
+ }
+ return '';
+ }
+
+ reqwest.serialize = function (form) {
+ var inputs = form[byTag]('input'),
+ selects = form[byTag]('select'),
+ texts = form[byTag]('textarea');
+ return (v(inputs).chain().toArray().map(serial).value().join('') +
+ v(selects).chain().toArray().map(serial).value().join('') +
+ v(texts).chain().toArray().map(serial).value().join('')).replace(/&$/, '');
+ };
+
+ reqwest.serializeArray = function (f) {
+ for (var pairs = this.serialize(f).split('&'), i = 0, l = pairs.length, r = [], o; i < l; i++) {
+ pairs[i] && (o = pairs[i].split('=')) && r.push({name: o[0], value: o[1]});
+ }
+ return r;
+ };
+
+ var old = window.reqwest;
reqwest.noConflict = function () {
- context.reqwest = old;
+ window.reqwest = old;
return this;
};
- context.reqwest = reqwest;
+
+ // defined as extern for Closure Compilation
+ // do not change to (dot) '.' syntax
+ window['reqwest'] = reqwest;
}(this);
View
2 tests/fixtures/fixtures_jsonp.js
@@ -1 +1 @@
-Request0({ "boosh": "boosh" });
+reqwest_0({ "boosh": "boosh" });
View
2 tests/fixtures/fixtures_jsonp3.js
@@ -1 +1 @@
-Request1({ "boosh": "boosh" });
+reqwest_1({ "boosh": "boosh" });
View
23 tests/tests.html
@@ -4,11 +4,34 @@
<title>Reqwest tests</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="/build/sink/src/sink.css" type="text/css">
+ <script src="/build/valentine/valentine.js"></script>
<script src="/build/sink/src/sink.js"></script>
<script src="src/reqwest.js"></script>
+ <style type="text/css">
+ #fixtures {
+ position: absolute;
+ top: -9999em;
+ }
+ </style>
</head>
<body>
<h1>Reqwest Tests</h1>
+ <div id="fixtures">
+ <form action="/foo" method="post">
+ <input type="submit" value="Continue">
+ <input type="text" name="foo" value="bar">
+ <input type="hidden" name="bar" value="baz">
+ <input type="checkbox" name="wha" checked value="1">
+ <input type="checkbox" name="wha" value="2">
+ <input type="checkbox" name="wha" checked value="3">
+ <select name="choices">
+ <option>one</option>
+ <option selected>two</option>
+ <option>tres</option>
+ </select>
+ <textarea name="opinions">world peace is not real</textarea>
+ </form>
+ </div>
<ol id="tests"></ol>
<script src="/tests/tests.js"></script>
</body>
View
45 tests/tests.js
@@ -1,4 +1,4 @@
-sink('Reqwest', function(test, ok, before, after) {
+sink('Mime types', function (test, ok) {
test('JSON', 1, function() {
reqwest({
url: '/tests/fixtures/fixtures.json',
@@ -8,7 +8,7 @@ sink('Reqwest', function(test, ok, before, after) {
}
});
});
-
+
// For some reason, using the .jsonp file extension didn't work
// in the testing suite. Using .js instead for now.
test('JSONP', 3, function() {
@@ -19,7 +19,7 @@ sink('Reqwest', function(test, ok, before, after) {
ok(resp.boosh == "boosh", "evaluated response as JSONP");
}
});
-
+
reqwest({
url: '/tests/fixtures/fixtures_jsonp2.js?foo=bar',
type: 'jsonp',
@@ -28,7 +28,7 @@ sink('Reqwest', function(test, ok, before, after) {
ok(resp.boosh == "boosh", "evaluated response as JSONP with custom callback");
}
});
-
+
reqwest({
url: '/tests/fixtures/fixtures_jsonp3.js?foo=?',
type: 'jsonp',
@@ -59,6 +59,10 @@ sink('Reqwest', function(test, ok, before, after) {
});
});
+});
+
+sink('Callbacks', function (test, ok) {
+
test('no callbacks', 1, function () {
var pass = true;
try {
@@ -79,6 +83,10 @@ sink('Reqwest', function(test, ok, before, after) {
});
});
+});
+
+sink('Connection Object', function (test, ok) {
+
test('setRequestHeaders', 1, function () {
reqwest({
url: '/tests/fixtures/fixtures.html',
@@ -107,5 +115,34 @@ sink('Reqwest', function(test, ok, before, after) {
});
});
+ sink('Serializing', function (test, ok) {
+
+ test('serialize', 1, function () {
+ var expected = 'foo=bar&bar=baz&wha=1&wha=3&choices=two&opinions=world%20peace%20is%20not%20real';
+ ok(reqwest.serialize(document.forms[0]) == expected, 'serialized form');
+ });
+
+ test('serializeArray', 6, function () {
+ var expected = [
+ { name: 'foo', value: 'bar' },
+ { name: 'bar', value: 'baz' },
+ { name: 'wha', value: 1 },
+ { name: 'wha', value: 3 },
+ { name: 'choices', value: 'two' },
+ { name: 'opinions', value: 'world%20peace%20is%20not%20real' }
+ ];
+
+ var result = reqwest.serializeArray(document.forms[0]);
+
+ for (var i = 0; i < expected.length; i++) {
+ ok(result.some(function (v) {
+ return v.name == expected[i].name && v.value == expected[i].value;
+ }), 'serialized ' + result[i].name);
+ }
+ });
+
+ });
+
});
+
start();

0 comments on commit bf4b050

Please sign in to comment.
Something went wrong with that request. Please try again.