Permalink
Please sign in to comment.
Browse files
Update r.m.multipart-params: new wrap-multipart-params name, updated …
…project.clj deps, add tests, remove last of reflection.
- Loading branch information...
Showing
with
40 additions
and 3 deletions.
5
ring-core/project.clj
5
ring-core/src/ring/middleware/multipart_params.clj
33
ring-core/test/ring/middleware/multipart_params_test.clj
| @@ -0,0 +1,33 @@ | ||
| +(ns ring.middleware.multipart-params-test | ||
| + (:use clojure.test | ||
| + ring.middleware.multipart-params | ||
| + [clojure.contrib.def :only (defvar-)]) | ||
| + (:require [clojure.contrib.duck-streams :as du]) | ||
| + (:import (java.io File ByteArrayInputStream))) | ||
| + | ||
| +(defn- str-input-stream [#^String s] | ||
| + (ByteArrayInputStream. (.getBytes s))) | ||
| + | ||
| +(defvar- upload-content-type | ||
| + "multipart/form-data; boundary=----WebKitFormBoundaryAyGUY6aMxOI6UF5s") | ||
| + | ||
| +(defvar- upload-content-length 188) | ||
| + | ||
| +(defvar- upload-body (str-input-stream | ||
| + "------WebKitFormBoundaryAyGUY6aMxOI6UF5s\r\nContent-Disposition: form-data; name=\"upload\"; filename=\"test.txt\"\r\nContent-Type: text/plain\r\n\r\nfoo\r\n\r\n------WebKitFormBoundaryAyGUY6aMxOI6UF5s--")) | ||
| + | ||
| +(defvar- wrapped-echo (wrap-multipart-params identity)) | ||
| + | ||
| +(deftest test-wrap-multipart-params | ||
| + (let [req {:content-type upload-content-type | ||
| + :content-length upload-content-length | ||
| + :body upload-body | ||
| + :params {"foo" "bar"}} | ||
| + resp (wrapped-echo req)] | ||
| + (is (= "bar" (get-in resp [:params "foo"]))) | ||
| + (let [upload (get-in resp [:params "upload"])] | ||
| + (is (= "test.txt" (:filename upload))) | ||
| + (is (= 5 (:size upload))) | ||
| + (is (= "text/plain" (:content-type upload))) | ||
| + (is (instance? File (:tempfile upload))) | ||
| + (is (= "foo\r\n" (du/slurp* (:tempfile upload))))))) |
0 comments on commit
7d09995