On Dec 28, 2010, at 11:06 PM, Peter Karman wrote:

James Russo wrote on 12/28/10 6:47 PM:

Does anyone there some examples of unit tests for a controller which is based on Catalyst::Controller::REST? There was some discussion on the list a few years ago, and I think the conclusion was to use LWP directly and not Test::WWW::Mechanize::Catalyst. It seems that using the methods do not give you access to passing actual body content and content-type headers? There are getting overridden somewhere along the line. I'm going to continue to research it, but figured I'd ask here before I spend too much time on it.
It seems the following code actually creates a request where the body of the request is the URL encoded key/values, in this case would be "content=hello%20world". Since I need to send JSON or XML data, I needed to specify the content myself, so this wouldn't work.

# create
ok( $res = request(
POST( '/rest/file/testfile', [ content => 'hello world' ] )
"POST new file"

This works as expected allowing me to specify the actual content and content-type of the request.

# create
ok($response = request(
POST('/appointment','content-type' => 'application/json', 'content' => to_json($foo)
"create new appointment"));

Just wanted to put it out there in the archives for the next person.



Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 6 of 8 | next ›
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedDec 29, '10 at 12:47a
activeJan 1, '11 at 4:16p



site design / logo © 2022 Grokbase