respond with nil if async ring route doesn't match

* relates to #45
This commit is contained in:
Tommi Reiman 2017-11-11 22:12:06 +02:00
parent 4ea0dc2600
commit 63848838d5
2 changed files with 27 additions and 1 deletions

View file

@ -39,7 +39,8 @@
(handler
(cond-> (impl/fast-assoc request ::match match)
(seq params) (impl/fast-assoc :path-params params))
respond raise))))))
respond raise)))
(respond nil))))
{::router router}))
(defn get-router [handler]

View file

@ -135,3 +135,28 @@
(app {:uri "/api/admin/ping"
:request-method :get
::roles #{:admin}})))))))
(deftest async-ring-test
(let [promise #(let [value (atom ::nil)]
(fn
([] @value)
([x] (reset! value x))))
response {:status 200, :body "ok"}
handler (fn [_ respond raise]
(respond response))
app (ring/ring-handler
(ring/router
["/ping" handler]))]
(testing "match"
(let [respond (promise)
raise (promise)]
(app {:request-method :get, :uri "/ping"} respond raise)
(is (= response (respond)))
(is (= ::nil (raise)))))
(testing "no match"
(let [respond (promise)
raise (promise)]
(app {:request-method :get, :uri "/pong"} respond raise)
(is (= nil (respond)))
(is (= ::nil (raise)))))))