Skip to content

Commit

Permalink
Fixed file and resource routes
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Dec 29, 2010
1 parent b9ecce5 commit 8c2ee97
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/compojure/route.clj
Expand Up @@ -13,7 +13,7 @@
keys: keys:
:root - the root path where the files are stored. Defaults to 'public'." :root - the root path where the files are stored. Defaults to 'public'."
[path & [options]] [path & [options]]
(GET (add-wildcard path) {{file-path "*"} :params} (GET (add-wildcard path) {{file-path :*} :route-params}
(let [options (merge {:root "public"} options)] (let [options (merge {:root "public"} options)]
(file-response file-path options)))) (file-response file-path options))))


Expand All @@ -22,7 +22,7 @@
keys: keys:
:root - the root prefix to get the resources from. Defaults to '/public'." :root - the root prefix to get the resources from. Defaults to '/public'."
[path & [options]] [path & [options]]
(GET (add-wildcard path) {{resource-path "*"} :params} (GET (add-wildcard path) {{resource-path :*} :route-params}
(let [options (merge {:root "/public"} options)] (let [options (merge {:root "/public"} options)]
(resource-response resource-path options)))) (resource-response resource-path options))))


Expand Down
5 changes: 3 additions & 2 deletions test/compojure/test/route.clj
@@ -1,15 +1,16 @@
(ns compojure.test.route (ns compojure.test.route
(:use clojure.test (:use clojure.test
ring.mock.request
[clojure.contrib.io :only (slurp*)]) [clojure.contrib.io :only (slurp*)])
(:require [compojure.route :as route])) (:require [compojure.route :as route]))


(deftest not-found-route (deftest not-found-route
(let [response ((route/not-found "foo") {})] (let [response ((route/not-found "foo") (request :get "/"))]
(is (= (:status response) 404)) (is (= (:status response) 404))
(is (= (:body response) "foo")))) (is (= (:body response) "foo"))))


(deftest resources-route (deftest resources-route
(let [route (route/resources "/foo" {:root "/resources"}) (let [route (route/resources "/foo" {:root "/resources"})
response (route {:request-method :get, :uri "/foo/test.txt"})] response (route (request :get "/foo/test.txt"))]
(is (= (:status response) 200)) (is (= (:status response) 200))
(is (= (slurp* (:body response)) "foobar\n")))) (is (= (slurp* (:body response)) "foobar\n"))))

0 comments on commit 8c2ee97

Please sign in to comment.