How to post JSON data in rails 3 functional test

前端 未结 7 1817
礼貌的吻别
礼貌的吻别 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:31

    As of Rails 5, the way to do this is:

    post new_widget_url, as: :json, params: { foo: "bar" }
    

    This will also set the Content-type header correctly (to application/json).

提交回复
热议问题