Permalink
Browse files

add in noir.request namespace

Signed-off-by: Chris Granger <ibdknox@gmail.com>
  • Loading branch information...
1 parent 9749e3c commit 89459ee68687b22fb5f65982d0372dc39c5956b9 @ibdknox ibdknox committed Sep 9, 2011
Showing with 43 additions and 0 deletions.
  1. +14 −0 src/noir/request.clj
  2. +2 −0 src/noir/server/handler.clj
  3. +15 −0 test/noir/test/core.clj
  4. +12 −0 test/noir/test/validation.clj
View
14 src/noir/request.clj
@@ -0,0 +1,14 @@
+(ns noir.request
+ "Functions for accessing the original request object from within noir handlers")
+
+(declare ^{:dynamic true} *request*)
+
+(defn ring-request
+ "Returns back the current ring request map"
+ []
+ *request*)
+
+(defn wrap-request-map [handler]
+ (fn [req]
+ (binding [*request* req]
+ (handler req))))
View
2 src/noir/server/handler.clj
@@ -7,6 +7,7 @@
[noir.content.defaults :as defaults]
[noir.cookies :as cookie]
[noir.exception :as exception]
+ [noir.request :as request]
[noir.statuses :as statuses]
[noir.options :as options]
[noir.session :as session]
@@ -40,6 +41,7 @@
;; result of a modification are evaluated on the first reload.
((pack-routes) request))
(pack-routes))
+ (request/wrap-request-map)
(wrap-custom-middleware))))
(defn add-custom-middleware
View
15 test/noir/test/core.clj
@@ -7,6 +7,7 @@
[noir.server :as server]
[noir.util.middleware :as middleware]
[noir.session :as session]
+ [noir.request :as request]
[noir.options :as options]
[noir.response :as resp]
[noir.cookies :as cookies]
@@ -61,6 +62,20 @@
(defpage "/test" {:keys [nme]}
(str "Hello " nme))
+(defpage "/request" {}
+ (let [req (request/ring-request)]
+ (is req)
+ (is (map? req))
+ (is (:uri req))))
+
+(deftest request-middleware
+ (send-request "/request"))
+
+(deftest route-test
+ (-> (send-request "/test" {"nme" "chris"})
+ (has-status 200)
+ (has-body "Hello chris")))
+
(deftest route-test
(-> (send-request "/test" {"nme" "chris"})
(has-status 200)
View
12 test/noir/test/validation.clj
@@ -0,0 +1,12 @@
+(ns noir.test.validation
+ (:use [noir.util.test])
+ (:use [clojure.test])
+ (:require [noir.validation :as vali]))
+
+(deftest error-counting
+ (with-noir
+ (is (not (vali/errors?)))
+ (vali/set-error :a "oh no")
+ (is (vali/errors?))
+ (is (vali/errors? :a))
+ (is (not (vali/errors? :b)))))

0 comments on commit 89459ee

Please sign in to comment.