Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 20th, 2012  |  syntax: Rails  |  size: 0.56 KB  |  views: 97  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #And here is my test:
  2.  
  3.     it "passes the token" do
  4.       get :new, nil,
  5.         :authorization => ActionController::HttpAuthentication::Token.encode_credentials("test_access1")
  6.  
  7.       assigns(:token).should be "test_access1"
  8.     end
  9.  
  10. #Here's my before filter:
  11.  
  12.     def restrict_access
  13.       authenticate_or_request_with_http_token do |token, options|
  14.         api_key = ApiKey.find_by_access_token(token)
  15.         @user = api_key.user unless api_key.nil?
  16.         @token = token #set just for the sake of testing
  17.         !api_key.nil?
  18.       end
  19.     end