On Sunday, May 11, 2014 3:18:56 AM UTC-5, Ivan Schuetz wrote:
>
> I tried
>
> (let [response (app
> (content-type (request :post "/login" {:username
> "jane" :password "test"})
> "application/json"))] )
>
Take a look at the source. Params passed to ring-mock.request/request for
non-GET, non-HEAD requests will always be passed through to 'body[1], and
if those params are a map, they'll always be urlencoded, and the content
type of the request will be set to "application/x-www-form-urlencoded"[2].
Your call to content-type is changing the declared content-type of the
request, but the body is still urlencoded. If you instead pass in a json
string, it will be converted to a byte-array and wrapped in a
ByteArrayInputStream without further encoding[3]. So you should be able to
do something like the following (untested).
(-> (request :post "/login"
(clojure.data.json/write-str {:username "jane" :password
"test"}))
(content-type "application/json"))
[1]:
https://github.com/weavejester/ring-mock/blob/master/src/ring/mock/request.clj#L92-L104
[2]:
https://github.com/weavejester/ring-mock/blob/master/src/ring/mock/request.clj#L70-L73
[3]:
https://github.com/weavejester/ring-mock/blob/master/src/ring/mock/request.clj#L62-L68
Doesn't work...
>
In the future, it would be helpful to say more about how it doesn't work.
For example, you could show us the return value of (content-type (request
:post "/login" {:username "jane" :password "test"}) "application/json")
and, if you can see what's wrong with it, tell us what's wrong.
The Stack Overflow post you linked to is about peridot, a different library
for testing Ring apps.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.