Sign in through GitHub

RailsCasts Pro episodes are now free!

Learn more or hide this

Jérémy's Profile

GitHub User: jerefrer

Comments by Jérémy


Here is a nice answer if your are doing controller or acceptance tests.

If you're like me and went with Rack::Test::Methods (see this post section 'Testing your API', some examples here as well), here's the solution (which was a pain to figure out ...) :

get '/api/v1/users.json', nil, 'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Token.encode_credentials('THE-AWESOME-TOKEN')

And here is a little helper to keep things DRY :

def perform(method, url, params = {})
  token = ActionController::HttpAuthentication::Token.encode_credentials(Settings.application_api.token)
  send method, url, params, 'HTTP_AUTHORIZATION' => token