Skip to content

Commit

Permalink
Add test for options body and workaround for #76
Browse files Browse the repository at this point in the history
You can actually return custom headers for an error or options handler
but it requires some wrestling with as-response and ring-response.
  • Loading branch information
ordnungswidrig committed Nov 13, 2015
1 parent 6f73bcd commit 948b02f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/test_response.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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")))

0 comments on commit 948b02f

Please sign in to comment.