Permalink
Browse files

Merge pull request #157 from Deraen/master

Fix middleware ordering for nested wrap-routes
  • Loading branch information...
2 parents b4fd659 + 0920456 commit 3bdbc2f0c151ebb54b2f77780b417475e8277549 @weavejester committed on GitHub Jan 31, 2017
Showing with 16 additions and 2 deletions.
  1. +1 −1 src/compojure/core.clj
  2. +15 −1 test/compojure/core_test.clj
@@ -342,7 +342,7 @@
(let [middleware (pre-init middleware)
prep-request (fn [request]
(let [mw (:route-middleware request identity)]
- (assoc request :route-middleware (comp middleware mw))))]
+ (assoc request :route-middleware (comp mw middleware))))]
(fn
([request]
(handler (prep-request request)))
@@ -286,7 +286,21 @@
middleware (fn [h] (fn [r] (reset! matched (:compojure/route r)) (h r)))
handler (wrap-routes route middleware)
response (handler (mock/request :get "/foo"))]
- (is (= @matched [:get "/foo"])))))
+ (is (= @matched [:get "/foo"]))))
+
+ (testing "nested route-middlewares are applied in order"
+ (let [mw (fn [handler value]
+ (fn [req]
+ (let [resp (handler (update req :stack str value))]
+ (update resp :body str value))))
+ handler (wrap-routes
+ (routes
+ (wrap-routes (GET "/foo" req (:stack req)) mw "a")
+ (wrap-routes (GET "/bar" req (:stack req)) mw "b"))
+ mw
+ "1")]
+ (is (= "1aa1" (:body (handler (mock/request :get "/foo")))))
+ (is (= "1bb1" (:body (handler (mock/request :get "/bar"))))))))
(deftest route-information-test
(let [route (GET "/foo/:id" req req)

0 comments on commit 3bdbc2f

Please sign in to comment.