Permalink
Browse files

context macro can take symbols for paths (fixes #51)

  • Loading branch information...
1 parent 3b203a2 commit aaa3a4bc482be398435b35bea8926a1e7ff76424 @weavejester committed Mar 15, 2012
Showing with 8 additions and 1 deletion.
  1. +3 −1 src/compojure/core.clj
  2. +5 −0 test/compojure/test/core.clj
View
@@ -157,7 +157,9 @@
(vector? route)
`(route-compile
~(str (first route) ":__path-info")
- ~(merge (apply hash-map (rest route)) re-context)))))
+ ~(merge (apply hash-map (rest route)) re-context))
+ (symbol? route)
+ `(route-compile (str ~route ":__path-info") ~re-context))))
(defmacro context
"Give all routes in the form a common path prefix and set of bindings.
@@ -92,6 +92,11 @@
(let [handler (context ["/foo/:id" :id #"\d+"] [id] identity)]
(is (map? (handler (request :get "/foo/10"))))
(is (nil? (handler (request :get "/foo/ab"))))))
+ (testing "symbol matching"
+ (let [path "/foo/:id"
+ handler (context path [id] identity)]
+ (is (map? (handler (request :get "/foo/10"))))
+ (is (nil? (handler (request :get "/bar/10"))))))
(testing "context key"
(let [handler (context "/foo/:id" [id] :context)]
(are [url ctx] (= (handler (request :get url)) ctx)

0 comments on commit aaa3a4b

Please sign in to comment.