Skip to content

Commit

Permalink
Merge pull request #30 from cgore/java8-multipart
Browse files Browse the repository at this point in the history
Checking for Java version to determine correct content-type.
  • Loading branch information
glenjamin committed Apr 2, 2016
2 parents 5aa0f0d + f08ac2a commit 9d9e02f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions test/peridot/test/multipart.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
[ring.util.response :as response]
[clojure.java.io :as io]))

(def expected-content-type
(let [[a b] (map #(Integer. %)
(clojure.string/split (System/getProperty "java.specification.version") #"\."))]
(if (and (<= 1 a)
(<= 8 b))
"text/plain" ; Java 1.8 and above
"application/octet-stream"))) ; Java 1.7 and below

(deftest file-as-param-is-multipart
(is (multipart/multipart? {"file" (io/file (io/resource "file.txt"))}))
(is (not (multipart/multipart? {"file" "value"}))))
Expand All @@ -28,8 +36,7 @@
(get-in res [:multipart-params "file"])]
(is (= size 13))
(is (= filename "file.txt"))
;; TODO should this be text content type?
(is (= content-type "application/octet-stream"))
(is (= content-type expected-content-type))
(is (= (slurp tempfile) (slurp file))))))

(deftest uploading-a-file-with-keyword-keys
Expand All @@ -43,8 +50,7 @@
(get-in res [:multipart-params "file"])]
(is (= size 13))
(is (= filename "file.txt"))
;; TODO should this be text content type?
(is (= content-type "application/octet-stream"))
(is (= content-type expected-content-type))
(is (= (slurp tempfile) (slurp file))))))

(deftest uploading-a-file-with-params
Expand All @@ -59,8 +65,7 @@
(get-in res [:multipart-params "file"])]
(is (= size 13))
(is (= filename "file.txt"))
;; TODO should this be text content type?
(is (= content-type "application/octet-stream"))
(is (= content-type expected-content-type))
(is (= (slurp tempfile) (slurp file))))
(is (= (get-in res [:multipart-params "something"])
""))))

0 comments on commit 9d9e02f

Please sign in to comment.