Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix for `jQuery.ajax` receiving a non-string `data` option.

  • Loading branch information...
commit 681b353d11c91cd682fb6ed96cac6c0cfd8aeb06 1 parent 5eb661f
Damian Janowski djanowski authored
3  CHANGELOG.md
Source Rendered
@@ -13,6 +13,9 @@ to `npm install base64` (Assaf Arkin).
13 13
14 14 Tested with Node 0.3.7 (Assaf Arkin).
15 15
  16 +Fix for `jQuery.ajax` receiving a non-string `data` option (Damian
  17 +Janowski).
  18 +
16 19 283 Tests
17 20 4.6 sec to complete
18 21
23 spec/js-libs-compat.coffee
@@ -15,6 +15,10 @@ brains.get "/jquery", (req, res)-> res.send """
15 15 </select>
16 16
17 17 <span id="option"></span>
  18 +
  19 + <a href="#post">Post</a>
  20 +
  21 + <div id="response"></div>
18 22 </body>
19 23
20 24 <script>
@@ -24,11 +28,24 @@ brains.get "/jquery", (req, res)-> res.send """
24 28 $("#option").text(this.value);
25 29 });
26 30
  31 + $("a[href='#post']").click(function() {
  32 + $.post("/echo", {"foo": "bar"}, function(response) {
  33 + $("#response").text(response);
  34 + });
  35 +
  36 + return false;
  37 + });
27 38 });
28 39 </script>
29 40 </html>
30 41 """
31 42
  43 +brains.post "/echo", (req, res)->
  44 + lines = for key, value of req.body
  45 + key + "=" + value
  46 +
  47 + res.send lines.join("\n")
  48 +
32 49 vows.describe("Compatibility with JavaScript libraries").addBatch(
33 50 "jQuery":
34 51 zombie.wants "http://localhost:3003/jquery"
@@ -38,5 +55,11 @@ vows.describe("Compatibility with JavaScript libraries").addBatch(
38 55 @callback null, browser
39 56 "should fire the change event": (browser)-> assert.equal browser.text("#option"), "1"
40 57
  58 + "jQuery.post":
  59 + topic: (browser)->
  60 + browser.clickLink "Post", @callback
  61 + "should perform an AJAX POST request": (browser)->
  62 + assert.match browser.text("#response"), /foo=bar/
  63 +
41 64
42 65 ).export(module)
7 src/zombie/resources.coffee
@@ -260,14 +260,19 @@ class Resources extends Array
260 260 callback error
261 261 request.end body, "utf8"
262 262
  263 + typeOf = (object)->
  264 + return Object.prototype.toString.call(object)
  265 +
263 266 # We use this to convert data array/hash into application/x-www-form-urlencoded
264 267 stringifyPrimitive = (v) =>
265   - switch Object.prototype.toString.call(v)
  268 + switch typeOf(v)
266 269 when '[object Boolean]' then v ? 'true' : 'false'
267 270 when '[object Number]' then isFinite(v) ? v : ''
268 271 when '[object String]' then v
269 272 else ''
  273 +
270 274 stringify = (object) =>
  275 + return object if typeOf(object) == '[object String]'
271 276 object.map((k) ->
272 277 if Array.isArray(k[1])
273 278 k[1].map((v) ->

0 comments on commit 681b353

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