Permalink
Please sign in to comment.
Showing
with
45 additions
and 13 deletions.
- +11 −12 src/ring/middleware/params.clj
- +32 −0 test/ring/middleware/params_test.clj
- +2 −1 test/run.clj
23
src/ring/middleware/params.clj
32
test/ring/middleware/params_test.clj
| @@ -0,0 +1,32 @@ | ||
| +(ns ring.middleware.params-test | ||
| + (:use (clj-unit core) | ||
| + (ring.middleware params)) | ||
| + (:import (java.io ByteArrayInputStream))) | ||
| + | ||
| +(defn- str-input-stream [#^String s] | ||
| + (ByteArrayInputStream. (.getBytes s))) | ||
| + | ||
| +(def wrapped-echo (wrap-params identity)) | ||
| + | ||
| +(deftest "wrap-params: query-params only" | ||
| + (let [req {:query-string "foo=bar&biz=bat%25"} | ||
| + resp (wrapped-echo req)] | ||
| + (assert= {"foo" "bar" "biz" "bat%"} (:query-params resp)) | ||
| + (assert-nil (:form-params resp)) | ||
| + (assert= {"foo" "bar" "biz" "bat%"} (:params resp)))) | ||
| + | ||
| +(deftest "wrap-params: query-params and form-params" | ||
| + (let [req {:query-string "foo=bar" | ||
| + :content-type "application/x-www-form-urlencoded" | ||
| + :body (str-input-stream "biz=bat%25")} | ||
| + resp (wrapped-echo req)] | ||
| + (assert= {"foo" "bar"} (:query-params resp)) | ||
| + (assert= {"biz" "bat%"} (:form-params resp)) | ||
| + (assert= {"foo" "bar" "biz" "bat%"} (:params resp)))) | ||
| + | ||
| +(deftest "wrap-params: not form encoded" | ||
| + (let [req {:content-type "application/json" | ||
| + :body (str-input-stream "{foo: \"bar\"}")} | ||
| + resp (wrapped-echo req)] | ||
| + (assert-nil (:form-params resp)) | ||
| + (assert-nil (:params resp)))) |
3
test/run.clj
0 comments on commit
f666802