From 23c2ba96a34654b8bfdcdb314e88a4a53fd29e4d Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Sat, 15 Feb 2014 00:31:00 +1100 Subject: Remove some cruft and add some tests for `with-url-fn` and `add-middleware` --- test/abra/core_test.clj | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'test') 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"))) -- cgit v1.2.3