ariejan / baseapp

Kick it!

This URL has Read+Write access

ariejan (author)
Mon Dec 22 05:50:02 -0800 2008
commit  87f38ca6fed635154f5cb5d50c9df09aafb2d9fe
tree    f27e5605fcee5ccb13711ecc07e8c5003471d062
parent  89422374684f30d6be6031ce5c8be0fe24f9a6f7
baseapp / lib / authenticated_test_helper.rb
100644 21 lines (18 sloc) 0.593 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module AuthenticatedTestHelper
  # Sets the current user in the session from the user fixtures.
  def login_as(user)
    @request.session[:user_id] = user ? users(user).id : nil
  end
 
  def authorize_as(user)
    @request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials(users(user).login, 'monkey') : nil
  end
  
  # rspec
  def mock_user
    user = mock_model(User, :id => 1,
      :login => 'user_name',
      :name => 'U. Surname',
      :to_xml => "User-in-XML", :to_json => "User-in-JSON",
      :errors => [])
    user
  end
end