Specifying Content Type in rspec

前端 未结 7 1745
终归单人心
终归单人心 2021-01-01 12:57

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
         


        
7条回答
  •  失恋的感觉
    2021-01-01 13:53

    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
    

提交回复
热议问题