This commit is contained in:
Tommi Reiman 2020-05-09 17:18:17 +03:00
parent 79c430d298
commit b8b442b598
3 changed files with 20 additions and 7 deletions

View file

@ -28,6 +28,10 @@ is called the first time, so that `rfe/push-state` and such can be called
[metosin/malli "0.0.1-20200404.091302-14"] is available but we use "0.0.1-20200305.102752-13" [metosin/malli "0.0.1-20200404.091302-14"] is available but we use "0.0.1-20200305.102752-13"
``` ```
### `reitit-ring`
* `reitit.ring/routes` strips away `nil` routes, fixes [#394](https://github.com/metosin/reitit/issues/394)
## 0.4.2 (2020-01-17) ## 0.4.2 (2020-01-17)
### `reitit` ### `reitit`

View file

@ -108,7 +108,7 @@
(defn routes (defn routes
"Create a ring handler by combining several handlers into one." "Create a ring handler by combining several handlers into one."
[& handlers] [& handlers]
(let [single-arity (apply some-fn handlers)] (let [single-arity (apply some-fn (keep identity handlers))]
(fn (fn
([request] ([request]
(single-arity request)) (single-arity request))

View file

@ -24,6 +24,15 @@
([request respond _] ([request respond _]
(respond (handler request)))) (respond (handler request))))
(deftest routes-test
(testing "nils are removed"
(is (= 123
((ring/routes
(constantly nil)
nil
(constantly 123))
::irrelevant)))))
(deftest ring-router-test (deftest ring-router-test
(testing "all paths should have a handler" (testing "all paths should have a handler"
@ -161,8 +170,8 @@
(deftest default-handler-test (deftest default-handler-test
(let [response {:status 200, :body "ok"} (let [response {:status 200, :body "ok"}
router (ring/router router (ring/router
[["/ping" {:get (constantly response)}] [["/ping" {:get (constantly response)}]
["/pong" (constantly nil)]]) ["/pong" (constantly nil)]])
app (ring/ring-handler router)] app (ring/ring-handler router)]
(testing "match" (testing "match"
@ -188,9 +197,9 @@
(testing "with custom http responses" (testing "with custom http responses"
(let [app (ring/ring-handler router (ring/create-default-handler (let [app (ring/ring-handler router (ring/create-default-handler
{:not-found (constantly {:status -404}) {:not-found (constantly {:status -404})
:method-not-allowed (constantly {:status -405}) :method-not-allowed (constantly {:status -405})
:not-acceptable (constantly {:status -406})}))] :not-acceptable (constantly {:status -406})}))]
(testing "route doesn't match" (testing "route doesn't match"
(is (= -404 (:status (app {:request-method :get, :uri "/"}))))) (is (= -404 (:status (app {:request-method :get, :uri "/"})))))
(testing "method doesn't match" (testing "method doesn't match"
@ -200,7 +209,7 @@
(testing "with some custom http responses" (testing "with some custom http responses"
(let [app (ring/ring-handler router (ring/create-default-handler (let [app (ring/ring-handler router (ring/create-default-handler
{:not-found (constantly {:status -404})}))] {:not-found (constantly {:status -404})}))]
(testing "route doesn't match" (testing "route doesn't match"
(is (= 405 (:status (app {:request-method :post, :uri "/ping"})))))))))) (is (= 405 (:status (app {:request-method :post, :uri "/ping"}))))))))))