mardi 3 avril 2018

Mock internal auth check in Rails requests tests

I've added an auth layer in my server and now all my tests fail with unauthorized status. Since I don't want to rewrite all my tests to hook an authenticated user before testing I wanna build a mock that returns true for all my calls.

I've identified the check in this part of the code:

before_action :authenticate_request
...
private

def authenticate_request
  @current_user = AuthorizeApiRequest.call(request.headers).result
  render json: { error: 'Not Authorized' }, status: 401 unless @current_user
end

How can I mock this check in my request tests?

Aucun commentaire:

Enregistrer un commentaire