summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/abra/core_test.clj33
1 files changed, 24 insertions, 9 deletions
diff --git a/test/abra/core_test.clj b/test/abra/core_test.clj
index b829cec..362a3d1 100644
--- a/test/abra/core_test.clj
+++ b/test/abra/core_test.clj
@@ -21,15 +21,6 @@
wrap-reverse-routing)]
(is (= (make-request handler "/succeed") "/user/10"))))
-(-> (routes
- (register-route :user
- (GET "/user/:id" [id] (str "user " id)))
- (GET "/succeed" [] (url-for :user 10))
- (GET "/fail1" [] (url-for :user))
- (GET "/fail2" [] (url-for :user 10 20)))
- wrap-reverse-routing
- (make-request "/succeed"))
-
(deftest test-basic-route
(let [handler (-> (routes
(register-route :user
@@ -166,3 +157,27 @@
(is (= (make-request handler "/succeed"), "/user/10"))
(is (nil? (make-request handler "/fail1")))
(is (nil? (make-request handler "/fail2")))))
+
+(deftest add-middleware-maintains-metadata
+ (let [middleware (fn [handler]
+ (fn [request] ;; new handler, without the metadata
+ (handler request)))
+ handler (-> (routes
+ (register-route :user
+ (GET "/user/:id" [id] (str "user " id)))
+ (GET "/succeed" [] (url-for :user 10))
+ (GET "/fail1" [] (url-for :user))
+ (GET "/fail2" [] (url-for :user 10 20)))
+ (add-middleware middleware)
+ wrap-reverse-routing)]
+ (is (= (make-request handler "/succeed") "/user/10"))
+ (is (nil? (make-request handler "/fail1")))
+ (is (nil? (make-request handler "/fail2")))))
+
+(deftest with-url-fn-makes-correct-dynamic-environment
+ (with-url-fn (fn [thing args]
+ (str "/" (name thing) "/" (clojure.string/join "/" args)))
+ (is (url-for :user 10)
+ "/user/10")
+ (is (url-for :user 10 "edit")
+ "/user/10/edit")))