Permalink
Browse files

Added tests and minor correctness updates. stop-response propagates h…

…eaders.
  • Loading branch information...
1 parent 7dd6f73 commit 6e7ccce772a6de3b323d1344000414f0b97b4942 @KirinDave KirinDave committed May 30, 2011
Showing with 30 additions and 2 deletions.
  1. +2 −2 src/clothesline/protocol/response_helpers.clj
  2. +28 −0 test/clothesline/test/response_helpers.clj
@@ -79,11 +79,11 @@
([^int code] (fn [{:keys [handler request graphdata]}]
{:status code
:headers (merge {} (:headers graphdata))
- :body (bh/produce-body (:body graphdata) request graphdata)}))
+ :body @(bh/produce-body (:body graphdata) request graphdata)}))
([^int code headers] (fn [{:keys [handle request graphdata]}]
{:status code
:headers headers
- :body (bh/produce-body (:body graphdata) request graphdata)}))
+ :body @(bh/produce-body (:body graphdata) request graphdata)}))
; The other two handlers produce a function which produces a result, but this
; version of the method doesn't need that indirection. It only does so for uniformity.
([^int code headers body]
@@ -0,0 +1,28 @@
+(ns clothesline.test.response_helpers
+ (:use [clojure.test]
+ [clothesline.protocol.response-helpers]))
+
+
+
+(deftest stop-response-tests
+ (testing "stop-response"
+ (let [ecode 500
+ ebody "Whee"
+ eheads {:earth "air" :water "fire"}
+ sgraphdata {:graphdata {:body "NoFun" :headers {:darkness "light"}}}]
+ (is (let [resp ((stop-response ecode eheads ebody) sgraphdata)]
+ (and (= (:body resp) ebody)
+ (= (-> resp :headers :earth) "air")
+ (= (:status ecode))))
+ "should not propagate values in the long form.")
+ (is (let [resp ((stop-response ecode eheads) sgraphdata)]
+ (and (= (:body resp) "NoFun")
+ (= (-> resp :headers :earth) "air")
+ (= (:status ecode))))
+ "should propagate the values in 2-arity form.")
+ (is (let [resp ((stop-response ecode) sgraphdata)]
+ (and (= (:body resp) "NoFun")
+ (= (-> resp :headers :darkness) "light")
+ (= (:status ecode))))
+ "should propagate the body AND headers in 1-arity form."))))
+

0 comments on commit 6e7ccce

Please sign in to comment.