I have a POST endpoint that requires an api_key query parameter. In my controller, I want to check request.GET (rather than params) for the api_key, because I want users to put their key in the URL.
I want to test it, but it looks like RSpec requests don't allow both POST and query parameters. It seems to only allow me to use one big params hash (as the second argument to post), which means the API key would be passed in via the POST body rather than the query string. As a result, my test will fail, because the controller is checking request.GET.
I tried setting the QUERY_STRING in @request.env , as well as in the third parameter to the post method, e.g., post :create, post_params, "QUERY_STRING" => "api_key=#{api_key}", but both result in an empty request.GET object on the controller's end. It seems that query parameters are ignored in an RSpec context.
Any ideas how I can get query parameters to be passed into a POST request in RSpec?
Thanks!
Aucun commentaire:
Enregistrer un commentaire