From 948b02f6b38b01f8ed08c620a6d7e36e9dbcd7e6 Mon Sep 17 00:00:00 2001 From: Philipp Meier Date: Fri, 13 Nov 2015 13:26:06 +0100 Subject: [PATCH] Add test for options body and workaround for #76 You can actually return custom headers for an error or options handler but it requires some wrestling with as-response and ring-response. --- test/test_response.clj | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/test_response.clj b/test/test_response.clj index d92597f..c8d430f 100644 --- a/test/test_response.clj +++ b/test/test_response.clj @@ -83,3 +83,26 @@ ((resource :handle-ok "ok"))) => (fn [c] (not (contains? (:headers c) "Allow")))) ) + + +(facts "Options can return a body" + (fact "return a simple response" + (-> (request :options "/") + ((resource :allowed-methods [:get :options] + :handle-ok "ok" + :handle-options "options"))) + => (body "options")) + (fact "return a ring response" + (let [resp (-> (request :options "/") + ((resource :allowed-methods [:get :options] + :available-media-types ["text/plain" "text/html"] + :handle-ok "ok" + :handle-options (fn [ctx] + ;; workaround until issue #152 is fixed + (-> "options" + (as-response (assoc-in ctx [:representation :media-type] + "text/plain")) + (assoc-in [:headers "X-Foo"] "bar") + (ring-response))))))] + resp => (body "options") + resp) => (header-value "X-Foo" "bar")))