Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying Content Type in rspec

Tags:

I'm trying to build an rspec test that sends JSON (or XML) via POST. However, I can't seem to actually get it working:

    json = {.... data ....}.to_json     post '/model1.json',json,{'CONTENT_TYPE'=>'application/json'} 

and this

    json = {.... data ....}.to_json     post '/model1.json',json,{'Content-Type'=>'application/json'} 

any ideas? THANKS!

like image 415
skeevis Avatar asked Oct 27 '10 19:10

skeevis


1 Answers

There's a way to do this described in this thread -- it's a hack, but it seems to work:

@request.env["HTTP_ACCEPT"] = "application/json" json = { ... data ... }.to_json post :create, :some_param => json 
like image 72
zetetic Avatar answered Oct 26 '22 08:10

zetetic