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

后端 未结 12 1655
感情败类
感情败类 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:38

    Using Rails 4, I was looking to do this to test the processing of raw xml that was being posted to the controller. I was able to do it by just providing the string to the post:

    raw_xml = File.read("my_raw.xml")
    post :message, raw_xml, format: :xml
    

    I believe if the parameter provided is a string, it just gets passed along to the controller as the body.

提交回复
热议问题