diff options
author | Carlo Zancanaro <carlo@clearboxsystems.com.au> | 2013-09-02 00:56:29 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@clearboxsystems.com.au> | 2013-09-02 00:56:29 +1000 |
commit | 523e00ccda6559c57cce87e488ecfcb722d1fc19 (patch) | |
tree | 71496206a04d596077edd5375d184cd36c408b11 /test | |
parent | ef4627e39f9746fe27238c862294df94ab4e164b (diff) |
Handle the case of the top-level route being a var
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")))))) |