Thanks, that works! I'm new to Clojure and studying Ring's source to find this would probably require more time than I have available… this should be documented in the api shouldn't it?
About providing details, my question was more of the kind "what do I have to do" than "why isn't it working"... didn't see any sense in providing them when it's evidently an incorrect usage of the api, which should be visible with the code... But thanks again, next time I'll try to reserve extra time to study the source :) Am Sonntag, 11. Mai 2014 16:16:14 UTC+2 schrieb John Hume: > > 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.