Rspec Rails 3.1 Integration test. How to send post request headers for mobile, http basic authentication and JSON?

前端 未结 1 1264
误落风尘
误落风尘 2021-01-04 06:09

I have an RSPEC integration test for a Rails 3.1 app that needs to test an api for a mobile client by issuing a POST request with JSON params and a mobile header that needs

相关标签:
1条回答
  • 2021-01-04 06:41

    I figured out what I needed to do

    post("scores", {:score => {:mobile_user_id => @mobile_user.id, :points => 50, :time_taken => 7275}}.to_json,
           {"HTTP_USER_AGENT" => "Mobile", 'HTTP_AUTHORIZATION' => get_basic_auth, 'HTTP_CONTENT_TYPE' => "application/json"}
    

    Obviously the "mobile" user agent is not needed to test normal json requests.

    Hope that helps someone

    0 讨论(0)
提交回复
热议问题