diff options
author | Carlo Zancanaro <carlo@zancanaro.id.au> | 2014-02-15 00:31:00 +1100 |
---|---|---|
committer | Carlo Zancanaro <carlo@zancanaro.id.au> | 2014-02-15 00:31:00 +1100 |
commit | 23c2ba96a34654b8bfdcdb314e88a4a53fd29e4d (patch) | |
tree | f0d8c2683835056ec7a12f536040a7eef2a314cd /test | |
parent | 71c60cd6e16047385adfef3272dc17d74b5bfbb9 (diff) |
Remove some cruft and add some tests for `with-url-fn` and `add-middleware`
Diffstat (limited to 'test')
-rw-r--r-- | test/abra/core_test.clj | 33 |
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"))) |