diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/reverse_routing/core_test.clj | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/test/reverse_routing/core_test.clj b/test/reverse_routing/core_test.clj index 8752de9..ef2fa93 100644 --- a/test/reverse_routing/core_test.clj +++ b/test/reverse_routing/core_test.clj @@ -77,18 +77,30 @@ (is (thrown? java.lang.AssertionError (make-request handler "/fail3"))))) -(def ^:dynamic *subroutes* (register-route :user - (GET "/user" [] (str "user")))) (deftest test-with-rebinding-vars - (let [handler (-> (routes - #'*subroutes* - (GET "/succeed" [] (url-for :user)) - (GET "/fail" [] (url-for :user 10))) - wrap-reverse-routing)] - (is (= (make-request handler "/succeed") "/user")) - (is (thrown? java.lang.AssertionError (make-request handler "/fail"))) + (with-local-vars [subroutes (register-route :user + (GET "/user" [] (str "user")))] + (let [handler (-> (routes + subroutes + (GET "/succeed" [] (url-for :user)) + (GET "/fail" [] (url-for :user 10))) + wrap-reverse-routing)] + (is (= (make-request handler "/succeed") "/user")) + (is (thrown? java.lang.AssertionError (make-request handler "/fail"))) - (binding [*subroutes* (register-route :user - (GET "/not-user" [] (str "user")))] + (var-set subroutes (register-route :user + (GET "/not-user" [] (str "user")))) (is (= (make-request handler "/succeed") "/not-user")) (is (thrown? java.lang.AssertionError (make-request handler "/fail")))))) + +(deftest top-level-is-a-var + (with-local-vars [bare-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)))] + (let [handler (wrap-reverse-routing bare-handler)] + (is (= (make-request handler "/succeed") "/user/10")) + (is (thrown? java.lang.AssertionError (make-request handler "/fail1"))) + (is (thrown? java.lang.AssertionError (make-request handler "/fail2")))))) |