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

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

    The post method expects a hash of name-value pairs, so you'll need to do something like this:

    post :index, :data => '{"foo":"bar", "bool":true}'
    

    Then, in your controller, get the data to be parsed like this:

    post_data = params[:data]
    

提交回复
热议问题