How to send raw post data in a Rails functional test?

后端 未结 12 1654
感情败类
感情败类 2020-12-13 12:07

I\'m looking to send raw post data (e.g. unparamaterized JSON) to one of my controllers for testing:

class LegacyOrderUpdateControllerTest < ActionControl         


        
12条回答
  •  难免孤独
    2020-12-13 12:47

    For those using Rails5+ integration tests, the (undocumented) way to do this is to pass a string in the params argument, so:

    post '/path', params: raw_body, headers: { 'Content-Type' => 'application/json' }
    

提交回复
热议问题