Rails JSON API testing POST request with PARAMS in JSON

前端 未结 2 1776
甜味超标
甜味超标 2021-01-04 15:57

This is a problem that has been bothering me for some time. I am building an API function that should receive data in json and response in json. My controller tests run fine

2条回答
  •  长情又很酷
    2021-01-04 16:49

    I found my answer on a post here(RSpec request test merges hashes in array in POST JSON params), I think what I was doing wrong concerned the arguments to the request.

    so this worked:

    it "should return an error if there is no correct email" do
        params = {:subscription => {:email => "andre"}}
    
        post "/magazine_subscriptions", params.to_json, {'ACCEPT' => "application/json", 'CONTENT_TYPE' => 'application/json'}
    end
    

提交回复
热议问题