I\'m using rspec request to test a JSON API that requires an api-key in the header of each request.
I know I can do this:
get \"/v1/users/janedoe.json\"
This is another way to do it if you are doing a post.
@authentication_params = { 'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Token.encode_credentials(Temp::Application.config.api_key) }
expect { post "/api/interactions", @interaction_params, @authentication_params }.to change(Interaction, :count).by(1)
Note interaction_params is just a json object I am passing in.