Setting Content-Type header for RSpec and Rails-API

后端 未结 6 1710
遇见更好的自我
遇见更好的自我 2021-02-19 10:41

I\'m using the rails-api gem to build a web service and want to test my API with RSpec. Every request I make, regardless of the HTTP method has the CONTENT_TYPE hea

6条回答
  •  半阙折子戏
    2021-02-19 11:08

    This worked for me Rails 4.0.3 and Rspec 2.14.1 if anyone is looking for more recent versions.

    put '/projects/1.json', {name: 'Updated Project 1'}, {
      'HTTP_ACCEPT' => 'application/json',
      'CONTENT_TYPE' => 'application/json'
    }
    

    and

    wrap_parameters Project, format: :json
    

提交回复
热议问题