From c7aa3788bc683e0cbf495a929681c2903e980b9c Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Sun, 31 Jan 2016 12:33:35 +0200 Subject: [PATCH 1/2] Add breaking test --- test/compojure/api/coercion_test.clj | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/compojure/api/coercion_test.clj b/test/compojure/api/coercion_test.clj index b7e72d2d..64ffbaaa 100644 --- a/test/compojure/api/coercion_test.clj +++ b/test/compojure/api/coercion_test.clj @@ -138,4 +138,12 @@ (app {:request-method :get :uri "/api/ping" :query-params {:x "abba"}}) => (contains {:body ["abba" 0]}) (app {:request-method :get :uri "/api/ping" :query-params {:x "1"}}) => (contains {:body ["1" 0]}) (app {:request-method :get :uri "/api/ping" :query-params {:x "1", :y 2}}) => (contains {:body ["1" 2]}) - (app {:request-method :get :uri "/api/ping" :query-params {:x "1", :y "abba"}}) => throws))) + (app {:request-method :get :uri "/api/ping" :query-params {:x "1", :y "abba"}}) => throws)) + + (fact "" + (let [app (context "/api" [] + :coercion (constantly nil) + (GET "/ping" [] + :query-params [x :- Long] + (ok x)))] + (app {:request-method :get :uri "/api/ping" :query-params {:x "abba"}}) => (contains {:body "abba"}))) ) From 79de23081a99b8ef7ef9081fe6800647b92276fe Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Sun, 31 Jan 2016 12:55:33 +0200 Subject: [PATCH 2/2] Apply route middleware using compojure.core/wrap-routes Fixes #210 --- src/compojure/api/meta.clj | 9 ++++----- test/compojure/api/coercion_test.clj | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/compojure/api/meta.clj b/src/compojure/api/meta.clj index 8efa3e5e..fb7e8351 100644 --- a/src/compojure/api/meta.clj +++ b/src/compojure/api/meta.clj @@ -382,14 +382,13 @@ form `(~body-wrap ~@body) form (if (seq letks) `(letk ~letks ~form) form) form (if (seq lets) `(let ~lets ~form) form) - form (if (seq middleware) - `(let [wrap-mw# (mw/compose-middleware ~middleware)] - ((wrap-mw# (fn [~arg] ~form)) ~arg)) - form) - form (if (seq pre-lets) `(let ~pre-lets ~form) form) form (if routes `(compojure.core/context ~path ~arg-with-request ~form) (compojure.core/compile-route method path arg-with-request (list form))) + form (if (seq middleware) + `(compojure.core/wrap-routes ~form (mw/compose-middleware ~middleware)) + form) + form (if (seq pre-lets) `(let ~pre-lets ~form) form) ;; for routes, create a separate lookup-function to find the inner routes child-form (if routes diff --git a/test/compojure/api/coercion_test.clj b/test/compojure/api/coercion_test.clj index 64ffbaaa..8adc119b 100644 --- a/test/compojure/api/coercion_test.clj +++ b/test/compojure/api/coercion_test.clj @@ -140,7 +140,7 @@ (app {:request-method :get :uri "/api/ping" :query-params {:x "1", :y 2}}) => (contains {:body ["1" 2]}) (app {:request-method :get :uri "/api/ping" :query-params {:x "1", :y "abba"}}) => throws)) - (fact "" + (fact "context coercion is used for subroutes" (let [app (context "/api" [] :coercion (constantly nil) (GET "/ping" []