|  | 
| 188 | 188 |         "/foo/10/b%20r" "/foo/10" | 
| 189 | 189 |         "/bar/10"       nil))) | 
| 190 | 190 | 
 | 
|  | 191 | +  (testing "compojure/context key" | 
|  | 192 | +    (let [resp               (fn [req bar] {:body [bar (:compojure/context req)] :status 200}) | 
|  | 193 | +          handler            (GET "/foo/:bar" [bar :as req] (resp req bar)) | 
|  | 194 | +          cxt-handler        (context "/foo/:bar" [bar] (GET "/" req (resp req bar))) | 
|  | 195 | +          in-cxt-handler     (context "/foo" [] (GET "/:bar" [bar :as req] (resp req bar))) | 
|  | 196 | +          root-cxt-handler   (context "/" [] (GET "/foo/:bar" [bar :as req] (resp req bar))) | 
|  | 197 | +          request            (mock/request :get "/foo/bar") ] | 
|  | 198 | +      (is (= (-> request handler :body)          ["bar" nil])) | 
|  | 199 | +      (is (= (-> request cxt-handler :body)      ["bar" "/foo/:bar"])) | 
|  | 200 | +      (is (= (-> request in-cxt-handler :body)   ["bar" "/foo"])) | 
|  | 201 | +      (is (= (-> request root-cxt-handler :body) ["bar" nil])))) | 
|  | 202 | + | 
|  | 203 | +  (testing "compojure/context key in nested context" | 
|  | 204 | +    (let [handler (context "/foo" [] | 
|  | 205 | +                    (context "/:bar" [bar] | 
|  | 206 | +                      (GET "/baz" req {:status 200 | 
|  | 207 | +                                       :body   [bar (:compojure/context req)]}))) | 
|  | 208 | +          request (mock/request :get "/foo/bar/baz")] | 
|  | 209 | +      (is (= (-> request handler :body) ["bar" "/foo/:bar"])))) | 
|  | 210 | + | 
| 191 | 211 |   (testing "path-info   key" | 
| 192 | 212 |     (let [handler (context "/foo/:id" [id] :path-info)] | 
| 193 | 213 |       (are [url ctx] (= (handler (mock/request :get url)) ctx) | 
|  | 
| 298 | 318 |           response   (handler (mock/request :get "/foo"))] | 
| 299 | 319 |       (is (= @matched [:get "/foo"])))) | 
| 300 | 320 | 
 | 
|  | 321 | +  (testing "matched route context available in request" | 
|  | 322 | +    (let [route      (context "/foo/:bar" [] (GET "/baz" [] "foo")) | 
|  | 323 | +          matched    (atom nil) | 
|  | 324 | +          middleware (fn [h] (fn [r] (reset! matched (:compojure/context r)) (h r))) | 
|  | 325 | +          handler    (wrap-routes route middleware) | 
|  | 326 | +          response   (handler (mock/request :get "/foo/bar/baz"))] | 
|  | 327 | +      (is (= @matched "/foo/:bar")))) | 
|  | 328 | + | 
| 301 | 329 |   (testing "nested route-middlewares are applied in order" | 
| 302 | 330 |     (let [mw (fn [handler value] | 
| 303 | 331 |                (fn [req] | 
|  | 
0 commit comments