How to post JSON data in rails 3 functional test

前端 未结 7 1820
礼貌的吻别
礼貌的吻别 2021-02-04 06:55

I plan to use JSON data in both request and response in my project and having some problems in testing.

After searching for a while, I find the following code which uses

7条回答
  •  鱼传尺愫
    2021-02-04 07:42

    Assuming you have a controller named api, a method named new, and you're in the test for the api controller:

    @request.env["RAW_POST_DATA"] = '{ "foo" : "bar" }'
    post :new
    

    did the trick for me.

提交回复
热议问题